status maintain in order schema

master^2
Bhaskar 8 months ago
parent 55310b1407
commit 3d33e2e465

@ -215,7 +215,7 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
}); });
} }
// Find installation by installationId // 🔹 Find installation by installationId
const installation = await Install.findOne({ installationId }); const installation = await Install.findOne({ installationId });
if (!installation) { if (!installation) {
@ -227,11 +227,13 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
}); });
} }
// Extract team members list // 🔹 Extract team members list
const teamMembers = installation.team_member?.team_member || []; const teamMembers = installation.team_member?.team_member || [];
// Check if the provided teamMemberId exists in the installation's team // 🔹 Check if the provided teamMemberId exists in the installation's team
const assignedTeamMember = teamMembers.find(member => member.teamMemberId === teamMemberId); const assignedTeamMember = teamMembers.find(
(member) => member.teamMemberId === teamMemberId
);
if (!assignedTeamMember) { if (!assignedTeamMember) {
return reply.status(404).send({ return reply.status(404).send({
@ -242,18 +244,19 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
}); });
} }
// Find or create the quotation for the given installationId // 🔹 Find or create the quotation for the given installationId
let quotation = await Order.findOne({ installationId, quatationId: quotationId }); let quotation = await Order.findOne({ installationId, quatationId: quotationId });
if (!quotation) { if (!quotation) {
quotation = new Order({ quotation = new Order({
installationId, installationId,
quatationId: quotationId, quatationId: quotationId,
// assignedTeamMembers: [], assignedTeamMembers: [],
status: "Pending", // Default status when created
}); });
} }
// Assign the team member to the quotation // 🔹 Assign the team member to the quotation
if (!quotation.assignedTeamMembers) { if (!quotation.assignedTeamMembers) {
quotation.assignedTeamMembers = []; quotation.assignedTeamMembers = [];
} }
@ -262,7 +265,10 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
quotation.assignedTeamMembers.push(teamMemberId); quotation.assignedTeamMembers.push(teamMemberId);
} }
// Save the updated quotation // 🔹 Update order status when a team member is assigned
quotation.status = "Assigned"; // Update status
// 🔹 Save the updated quotation
await quotation.save(); await quotation.save();
return reply.send({ return reply.send({
@ -283,6 +289,7 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
}); });
} }
}; };
exports.getAllInstallers = async (request, reply) => { exports.getAllInstallers = async (request, reply) => {
try { try {
const { departmentName } = request.params; // Get installationId from request params const { departmentName } = request.params; // Get installationId from request params

Loading…
Cancel
Save