ashok 9 months ago
commit e9eadb4bb2

@ -2021,7 +2021,7 @@ exports.getOrdersByCustomer = async (req, reply) => {
exports.acceptQuotation = async (req, reply) => {
try {
const { quotationId } = req.params;
let { action } = req.body;
let { action, storeId } = req.body;
action = action.toLowerCase(); // Convert action to lowercase
@ -2041,9 +2041,10 @@ exports.acceptQuotation = async (req, reply) => {
message: "Quotation rejected successfully",
});
} else if (action === "accept") {
// Convert quotation to an order object
// Convert quotation to an order object and include storeId
const newOrder = new Order({
...quotation.toObject(), // Copy all fields
...quotation.toObject(), // Copy all fields from quotation
storeId: storeId, // Ensure storeId is included
status: "pending", // Set status to "pending"
});
@ -2066,3 +2067,27 @@ exports.acceptQuotation = async (req, reply) => {
return reply.status(500).send({ error: "Internal server error" });
}
};
exports.getOrdersByStoreId = async (req, reply) => {
try {
const { storeId } = req.params;
if (!storeId) {
return reply.status(400).send({ error: "storeId is required" });
}
// Fetch orders with the matching storeId
const orders = await Order.find({ storeId });
return reply.send({
status_code: 200,
message: "Orders fetched successfully",
data: orders,
});
} catch (err) {
console.error("Error fetching orders:", err);
return reply.status(500).send({ error: "Internal server error" });
}
};

@ -1314,6 +1314,7 @@ fastify.post("/api/createquotationforSensor/:surveyId", {
type: "object",
properties: {
customerId: { type: "string" },
masters: { type: "string" },
slaves: { type: "string" },
sensors: { type: "string" },
@ -1671,6 +1672,7 @@ fastify.post("/api/acceptquotation/:quotationId", {
type: "object",
properties: {
action: { type: "string" },
storeId: { type: "string" },
},
required: ["action"],
},
@ -1683,5 +1685,29 @@ fastify.post("/api/acceptquotation/:quotationId", {
// preHandler: fastify.auth([fastify.authenticate]), // Uncomment if authentication is needed
handler: storeController.acceptQuotation,
});
fastify.get("/api/ordersofstore/:storeId", {
schema: {
tags: ["Install"],
description: "Fetches orders based on storeId",
summary: "Get orders by storeId",
params: {
type: "object",
properties: {
storeId: { type: "string" },
},
required: ["storeId"],
},
security: [
{
basicAuth: [],
},
],
},
handler: storeController.getOrdersByStoreId,
});
next();
};

Loading…
Cancel
Save