|
|
|
@ -215,7 +215,7 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find installation by installationId
|
|
|
|
|
// 🔹 Find installation by installationId
|
|
|
|
|
const installation = await Install.findOne({ installationId });
|
|
|
|
|
|
|
|
|
|
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 || [];
|
|
|
|
|
|
|
|
|
|
// Check if the provided teamMemberId exists in the installation's team
|
|
|
|
|
const assignedTeamMember = teamMembers.find(member => member.teamMemberId === teamMemberId);
|
|
|
|
|
// 🔹 Check if the provided teamMemberId exists in the installation's team
|
|
|
|
|
const assignedTeamMember = teamMembers.find(
|
|
|
|
|
(member) => member.teamMemberId === teamMemberId
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!assignedTeamMember) {
|
|
|
|
|
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 });
|
|
|
|
|
|
|
|
|
|
if (!quotation) {
|
|
|
|
|
quotation = new Order({
|
|
|
|
|
installationId,
|
|
|
|
|
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) {
|
|
|
|
|
quotation.assignedTeamMembers = [];
|
|
|
|
|
}
|
|
|
|
@ -262,7 +265,10 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
@ -283,6 +289,7 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.getAllInstallers = async (request, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { departmentName } = request.params; // Get installationId from request params
|
|
|
|
|