ashok 3 months ago
commit 0d349a4ab9

@ -488,7 +488,53 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
}
};
exports.getQuotationsByInstallationAndTeamMember = async (request, reply) => {
// 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",
// },
// });
// }
// };
exports.getQuotationsByInstallationAndTeamMember = async (request, reply) => {
try {
const { installationId, teamMemberId } = request.params;
@ -501,11 +547,11 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
});
}
// 🔹 Fetch quotations where installationId matches and teamMemberId is assigned
// 🔹 Find quotations matching installationId and assignedTeamMembers
const quotations = await Order.find({
installationId,
assignedTeamMembers: teamMemberId,
});
}).lean(); // use lean() for performance, since we'll enrich manually
if (!quotations || quotations.length === 0) {
return reply.status(404).send({
@ -516,23 +562,36 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
});
}
// 🔹 Enrich each quotation with customer details
const enrichedQuotations = await Promise.all(
quotations.map(async (quotation) => {
const customer = await User.findOne({ customerId: quotation.customerId }).lean();
return {
...quotation,
customer: customer || null, // attach under 'customer'
};
})
);
return reply.send({
simplydata: {
error: false,
message: "Quotations fetched successfully",
quotations,
quotations: enrichedQuotations,
},
});
} catch (err) {
console.error("Error fetching quotations:", err);
reply.status(500).send({
return reply.status(500).send({
simplydata: {
error: true,
message: "Internal server error",
},
});
}
};
};
exports.getDepartmentByFirstName = async (req, reply) => {
try {

Loading…
Cancel
Save