MultiUsersSalesSystem / services /driverService.js
Mahmoud7456's picture
Upload 72 files
0330133 verified
Raw History Blame Contribute Delete
743 Bytes
export const DriverService = {
setAvailable: async (Driver, id) =>
Driver.findByIdAndUpdate(id, {
status: "available",
currentOrders: 0,
currentOrderIds: [],
}),
setBusy: async (Driver, id) =>
Driver.findByIdAndUpdate(id, { status: "busy" }),
assignOrders: async (Driver, id, invoiceIds) => {
return Driver.findByIdAndUpdate(
id,
{
$addToSet: { currentOrderIds: { $each: invoiceIds } }, //correct field, no duplicates
status: "busy",
},
{ new: true }
).then((driver) => {
if (driver) {
driver.currentOrders = driver.currentOrderIds.length; // keep count in sync
return driver.save();
}
});
},
};