|
|
|
@ -1338,6 +1338,57 @@ exports.createquotationforSensor = async (req, reply) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.editQuotationForSensor = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { quatationId } = req.params; // Get the ID of the quotation to edit
|
|
|
|
|
const { masters, slaves, sensors, motor_switches, electricals } = req.body;
|
|
|
|
|
|
|
|
|
|
// Format electricals field
|
|
|
|
|
const formattedElectricals = electricals.map((item) => ({
|
|
|
|
|
type: item.type || "",
|
|
|
|
|
wire: item.wire || "",
|
|
|
|
|
switch: item.switch || "",
|
|
|
|
|
text: item.text || "",
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// Find and update the quotation
|
|
|
|
|
const updatedQuotation = await SensorQuotation.findOneAndUpdate(
|
|
|
|
|
{ quatationId },
|
|
|
|
|
{
|
|
|
|
|
masters,
|
|
|
|
|
slaves,
|
|
|
|
|
sensors,
|
|
|
|
|
motor_switches,
|
|
|
|
|
electricals: formattedElectricals,
|
|
|
|
|
updated_at: dayjs().tz("Asia/Kolkata").format('DD-MMM-YYYY - HH:mm'),
|
|
|
|
|
},
|
|
|
|
|
{ new: true } // Return the updated document
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!updatedQuotation) {
|
|
|
|
|
return reply.code(404).send({
|
|
|
|
|
success: false,
|
|
|
|
|
message: 'Quotation not found.',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reply.code(200).send({
|
|
|
|
|
success: true,
|
|
|
|
|
message: 'Quotation updated successfully.',
|
|
|
|
|
data: updatedQuotation,
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error updating quotation:', error);
|
|
|
|
|
reply.code(500).send({
|
|
|
|
|
success: false,
|
|
|
|
|
message: 'Failed to update quotation.',
|
|
|
|
|
error: error.message,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getallquotationdata = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
await SensorQuotation.find({})
|
|
|
|
|