Bhaskar 8 months ago
commit 985e3c75df

@ -1236,12 +1236,14 @@ exports.deleteSensorById = async (req, reply) => {
}; };
exports.updateSensorQC = async (req, reply) => { exports.updateSensorQC = async (req, reply) => {
try { try {
const { _id } = req.params; const { _id } = req.params;
let updateData = req.body; let updateData = req.body;
const allowedFields = ["qccheck", "qcby", "comment","status"]; const allowedFields = ["qccheck", "qcby", "comment", "status"];
// Filter only allowed fields // Filter only allowed fields
const filteredUpdateData = Object.keys(updateData) const filteredUpdateData = Object.keys(updateData)
@ -1251,6 +1253,12 @@ exports.updateSensorQC = async (req, reply) => {
return obj; 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 // Update qccheckdate with the current date in "DD-MMM-YYYY - HH:MM" format
filteredUpdateData.qccheckdate = moment().format("DD-MMM-YYYY - HH:mm"); filteredUpdateData.qccheckdate = moment().format("DD-MMM-YYYY - HH:mm");
@ -1272,6 +1280,7 @@ exports.updateSensorQC = async (req, reply) => {
}; };
exports.getSensorsByStatus = async (req, reply) => { exports.getSensorsByStatus = async (req, reply) => {
try { try {
const { storeId } = req.params; const { storeId } = req.params;
@ -2069,6 +2078,7 @@ exports.acceptQuotation = async (req, reply) => {
}; };
exports.getOrdersByStoreId = async (req, reply) => { exports.getOrdersByStoreId = async (req, reply) => {
try { try {
const { storeId } = req.params; const { storeId } = req.params;
@ -2080,10 +2090,29 @@ exports.getOrdersByStoreId = async (req, reply) => {
// Fetch orders with the matching storeId // Fetch orders with the matching storeId
const orders = await Order.find({ 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({ return reply.send({
status_code: 200, status_code: 200,
message: "Orders fetched successfully", message: "Orders fetched successfully",
data: orders, data: ordersWithCustomerDetails,
}); });
} catch (err) { } catch (err) {
console.error("Error fetching orders:", err); console.error("Error fetching orders:", err);

Loading…
Cancel
Save