-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patheditVehicle.ts
54 lines (51 loc) · 1.57 KB
/
editVehicle.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { User } from "@/components/dataTables/UserList";
import { apiRoutes } from "@/data/apiRoutes";
import { jwtToken } from "@/data/cookieNames";
import { admin, landfillManager, stsManager, unassigned } from "@/data/roles";
import { getCookie } from "@/lib/cookieFunctions";
import axios from "axios";
import { STS } from "@/components/modals/stsControl/EditSTSInfoModal";
import { message } from "antd";
type Vehicle = {
id: string;
vehicleNumber: string;
vehicleType: string;
capacity: string;
loadedFuelCostPerKm: string;
unloadedFuelCostPerKm: string;
landFillId: string;
landFillName: string;
stsId: string;
};
export default async function editVehicle(vehicleData: Vehicle) {
if (vehicleData) {
try {
const payload = {
vehicleNumber: vehicleData.vehicleNumber,
vehicleType: vehicleData.vehicleType,
capacity: vehicleData.capacity,
loadedFuelCostPerKm: vehicleData.loadedFuelCostPerKm,
unloadedFuelCostPerKm: vehicleData.unloadedFuelCostPerKm,
landFillId: vehicleData.landFillId,
stsId: vehicleData.stsId,
};
const res2 = await axios.put(
apiRoutes.vehicle.edit + vehicleData.id,
payload,
{
headers: {
Authorization: `Bearer ${await getCookie(jwtToken)}`,
},
}
);
return "vehicle updated successfully";
} catch (error: any) {
message.error(
error.message?.toString() ||
"error updating vehicle. You may not have the required permissions."
);
return null;
}
}
return null;
}