edit quotation

master
Varun 9 months ago
parent 5487d6b40c
commit 9a510b0bff

@ -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({})

@ -292,6 +292,7 @@ const sensorquotationSchema = new mongoose.Schema({
quoted_amount: { type: String, default: null },
comments: { type: String, default: null },
datetime: { type: String, default: null },
updated_at: { type: String, default: null },
electricals: [
{
type: { type: String, default: null },

@ -1178,6 +1178,49 @@ fastify.post("/api/createquotationforSensor/:installationId", {
});
fastify.post("/api/editQuotationForSensor/:quatationId", {
schema: {
description: "This is for edit quotation for sensors",
tags: ["Install"],
summary: "This is for edit quotation for sensors",
params: {
required: ["quatationId"],
type: "object",
properties: {
quatationId: {
type: "string",
description: "quatationId",
},
},
},
body: {
type: "object",
properties: {
masters: { type: "string" },
slaves: { type: "string" },
sensors: { type: "string" },
motor_switches: { type: "string" },
electricals: {
type: "array",
maxItems: 2500,
items: {
type: "object",
properties: {
type: { type: "string", default: null },
wire: { type: "string", default: null },
switch: { type: "string", default: null },
text: { type: "string", default: null },
},
},
},
},
},
},
handler: storeController.editQuotationForSensor,
});
fastify.post("/api/getquotationofinstalleranduser/:installationId", {
schema: {
tags: ["Install"],

Loading…
Cancel
Save