Bhaskar 8 months ago
commit 985e3c75df

@ -1236,6 +1236,8 @@ exports.deleteSensorById = async (req, reply) => {
};
exports.updateSensorQC = async (req, reply) => {
try {
const { _id } = req.params;
@ -1251,6 +1253,12 @@ exports.updateSensorQC = async (req, reply) => {
return obj;
}, {});
// Ensure qccheck is handled properly
if (filteredUpdateData.qccheck) {
const qccheckLower = filteredUpdateData.qccheck.toLowerCase();
filteredUpdateData.status = qccheckLower === "ok" ? "available" : "qcfailed";
}
// Update qccheckdate with the current date in "DD-MMM-YYYY - HH:MM" format
filteredUpdateData.qccheckdate = moment().format("DD-MMM-YYYY - HH:mm");
@ -1272,6 +1280,7 @@ exports.updateSensorQC = async (req, reply) => {
};
exports.getSensorsByStatus = async (req, reply) => {
try {
const { storeId } = req.params;
@ -2069,6 +2078,7 @@ exports.acceptQuotation = async (req, reply) => {
};
exports.getOrdersByStoreId = async (req, reply) => {
try {
const { storeId } = req.params;
@ -2080,10 +2090,29 @@ exports.getOrdersByStoreId = async (req, reply) => {
// Fetch orders with the matching storeId
const orders = await Order.find({ storeId });
if (!orders.length) {
return reply.send({
status_code: 200,
message: "No orders found for this store",
data: [],
});
}
// Fetch customer details for each order
const ordersWithCustomerDetails = await Promise.all(
orders.map(async (order) => {
const customer = await User.findOne({ customerId: order.customerId }).lean();
return {
...order.toObject(),
customer: customer || null, // Include customer details or null if not found
};
})
);
return reply.send({
status_code: 200,
message: "Orders fetched successfully",
data: orders,
data: ordersWithCustomerDetails,
});
} catch (err) {
console.error("Error fetching orders:", err);

Loading…
Cancel
Save