get all quations based on installation and team member

master^2
Bhaskar 7 months ago
parent 3d33e2e465
commit dd7aa1e24e

@ -251,7 +251,7 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
quotation = new Order({
installationId,
quatationId: quotationId,
assignedTeamMembers: [],
assignedTeamMembers: [], // Ensure assignedTeamMembers array is initialized
status: "Pending", // Default status when created
});
}
@ -268,9 +268,13 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
// 🔹 Update order status when a team member is assigned
quotation.status = "Assigned"; // Update status
// 🔹 Save the updated quotation
// 🔹 Save the updated quotation in the Order schema
await quotation.save();
// 🔹 Update Installation schema with quotationId
installation.quatationId = quotationId;
await installation.save();
return reply.send({
simplydata: {
error: false,
@ -436,4 +440,94 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
});
}
};
exports.getQuotationsByInstallationId = async (request, reply) => {
try {
const { installationId } = request.params;
if (!installationId) {
return reply.status(400).send({
simplydata: {
error: true,
message: "Installation ID is required",
},
});
}
// 🔹 Fetch quotations based on installationId
const quotations = await Order.find({ installationId });
if (!quotations || quotations.length === 0) {
return reply.status(404).send({
simplydata: {
error: true,
message: "No quotations found for this installation ID",
},
});
}
return reply.send({
simplydata: {
error: false,
message: "Quotations fetched successfully",
quotations,
},
});
} catch (err) {
console.error("Error fetching quotations:", err);
reply.status(500).send({
simplydata: {
error: true,
message: "Internal server error",
},
});
}
};
exports.getQuotationsByInstallationAndTeamMember = async (request, reply) => {
try {
const { installationId, teamMemberId } = request.params;
if (!installationId || !teamMemberId) {
return reply.status(400).send({
simplydata: {
error: true,
message: "Both installationId and teamMemberId are required",
},
});
}
// 🔹 Fetch quotations where installationId matches and teamMemberId is assigned
const quotations = await Order.find({
installationId,
assignedTeamMembers: teamMemberId,
});
if (!quotations || quotations.length === 0) {
return reply.status(404).send({
simplydata: {
error: true,
message: "No quotations found for this installation and team member",
},
});
}
return reply.send({
simplydata: {
error: false,
message: "Quotations fetched successfully",
quotations,
},
});
} catch (err) {
console.error("Error fetching quotations:", err);
reply.status(500).send({
simplydata: {
error: true,
message: "Internal server error",
},
});
}
};

@ -46,6 +46,48 @@ module.exports = function (fastify, opts, next) {
handler: installationController.getTeamMembers
});
fastify.get("/api/getQuations/:installationId", {
schema: {
description: "Get all quatations under a specific installation",
tags: ["Installation"],
summary: "Get all quatations under a specific installation",
params: {
type: "object",
properties: {
installationId: {
type: "string",
description: "Installation ID to fetch team members from"
}
},
required: ["installationId"]
},
},
handler: installationController.getQuotationsByInstallationId
});
fastify.get("/api/getQuations/:installationId/:teamMemberId", {
schema: {
description: "Get all quatations under a specific installation and team member",
tags: ["Installation"],
summary: "Get all quatations under a specific installation and team member",
params: {
type: "object",
properties: {
installationId: {
type: "string",
description: "Installation ID to fetch team members from"
},
teamMemberId: {
type: "string",
description: "teamMember ID to fetch team members from"
}
},
// required: ["installationId"]
},
},
handler: installationController.getQuotationsByInstallationAndTeamMember
});
fastify.post("/api/assignTeammember/:installationId", {
schema: {
description: "Assign a team member to an installation's quotation",

Loading…
Cancel
Save