changes in get based on status of in sensors

master^2
Varun 7 months ago
parent 7b53eae263
commit 3ff82be367

@ -1305,7 +1305,7 @@ exports.getSensorsByStatus = async (req, reply) => {
try {
const { storeId } = req.params;
const statuses = ["pending", "available", "rejected"];
const statuses = ["pending", "available", "rejected","blocked"];
let result = {};
for (const status of statuses) {
@ -1957,8 +1957,12 @@ exports.updateInstallationId = async (req, reply) => {
// Update the order with the new installationId
const updatedOrder = await Order.findByIdAndUpdate(
_id,
{ installationId, updated_at: new Date().toISOString() }, // Also update the timestamp
{ new: true } // Return the updated document
{
installationId,
status: "installer_assigned", // Updating the status
updated_at: new Date().toISOString(), // Updating timestamp
},
{ new: true }
);
if (!updatedOrder) {
@ -1977,6 +1981,31 @@ exports.updateInstallationId = async (req, reply) => {
};
exports.getPendingOrders = async (req, reply) => {
try {
const pendingOrders = await Order.find({ status: "pending" });
if (!pendingOrders.length) {
return reply.send({
status_code: 200,
message: "No pending orders found",
data: [],
});
}
return reply.send({
status_code: 200,
message: "Pending orders fetched successfully",
data: pendingOrders,
});
} catch (err) {
console.error("Error fetching pending orders:", err);
return reply.status(500).send({ error: "Internal server error" });
}
};
exports.handleEstimation = async (req, reply) => {
try {
const { customerId, items, estimatedTotal, action } = req.body;

@ -1676,6 +1676,26 @@ fastify.put("/api/updateInstallationId/:_id", {
});
fastify.get("/api/getPendingOrders", {
schema: {
tags: ["Install"],
description: "Fetch all orders with status 'pending'",
summary: "Get all pending orders",
response: {
200: {
type: "object",
properties: {
status_code: { type: "number" },
message: { type: "string" },
data: { type: "array", items: { type: "object" } },
},
},
},
},
handler: storeController.getPendingOrders,
});
fastify.post("/api/cart/hardwareItem", {
schema: {
description: "To add items to the Hardwarecart",

Loading…
Cancel
Save