|
|
|
@ -1236,12 +1236,14 @@ exports.deleteSensorById = async (req, reply) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.updateSensorQC = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { _id } = req.params;
|
|
|
|
|
let updateData = req.body;
|
|
|
|
|
|
|
|
|
|
const allowedFields = ["qccheck", "qcby", "comment","status"];
|
|
|
|
|
const allowedFields = ["qccheck", "qcby", "comment", "status"];
|
|
|
|
|
|
|
|
|
|
// Filter only allowed fields
|
|
|
|
|
const filteredUpdateData = Object.keys(updateData)
|
|
|
|
@ -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);
|
|
|
|
|