ashok 9 months ago
commit e2f6e843e0

@ -1620,7 +1620,7 @@ exports.createquotationforSensor = async (req, reply) => {
const i_id = await generatequatationId();
const quatationId = `AWQU${i_id}`;
const { surveyId } = req.params;
const { customerId, masters, slaves, sensors, motor_switches, electricals } = req.body;
const { customerId, masters, slaves, sensors, motor_switches, electricals,master_connections } = req.body;
// Format electricals field
const formattedElectricals = electricals.map((item) => ({
@ -1629,6 +1629,16 @@ exports.createquotationforSensor = async (req, reply) => {
switch: item.switch || "",
text: item.text || "",
}));
const formattedMasterDetails = master_connections.map((item) => ({
master_name: item.master_name || "",
slaves: item.slaves || "",
tanks: Array.isArray(item.tanks)
? item.tanks.map(tank => ({
tankName: tank.tankName || "",
tankLocation: tank.tankLocation || ""
}))
: []
}));
// Fetch pricing data from Iotprice database
const getPrice = async (name, type) => {
@ -1662,7 +1672,7 @@ exports.createquotationforSensor = async (req, reply) => {
const newQuotation = new SensorQuotation({
quatationId,
customerId,
master_connections: formattedMasterDetails,
surveyId,
quote_status: "sentfromsurvey",
masters,
@ -1697,7 +1707,7 @@ 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;
const { masters, slaves, sensors, motor_switches, electricals, master_connections } = req.body;
// Format electricals field
const formattedElectricals = electricals.map((item) => ({
@ -1707,6 +1717,20 @@ exports.editQuotationForSensor = async (req, reply) => {
text: item.text || "",
}));
// Format master_connections field
const formattedMasterDetails = master_connections.map((item) => ({
master_name: item.master_name || "",
slaves: item.slaves || "",
tanks: Array.isArray(item.tanks)
? item.tanks.map(tank => ({
tankName: tank.tankName || "",
tankLocation: tank.tankLocation || ""
}))
: []
}));
console.log("Formatted Master Connections:", formattedMasterDetails); // Debugging
// Find and update the quotation
const updatedQuotation = await SensorQuotation.findOneAndUpdate(
{ quatationId },
@ -1716,6 +1740,7 @@ exports.editQuotationForSensor = async (req, reply) => {
sensors,
motor_switches,
electricals: formattedElectricals,
master_connections: formattedMasterDetails, // <- Ensure it's included
updated_at: dayjs().tz("Asia/Kolkata").format('DD-MMM-YYYY - HH:mm'),
},
{ new: true } // Return the updated document

@ -419,6 +419,22 @@ const sensorquotationSchema = new mongoose.Schema({
comments: { type: String, default: null },
datetime: { type: String, default: null },
updated_at: { type: String, default: null },
master_connections: [
{
master_name: { type: String, default: null },
slaves: { type: String, default: null },
tanks: [
{
tankName: { type: String, default: null },
tankLocation: { type: String, default: null },
},
],
},
],
electricals: [
{
type: { type: String, default: null },
@ -466,6 +482,7 @@ const orderSchema = new mongoose.Schema({
datetime: { type: String, default: null },
updated_at: { type: String, default: null },
assignedTeamMembers: [{ type: String }],
electricals: [
{
type: { type: String, default: null },

@ -1419,6 +1419,29 @@ fastify.post("/api/createquotationforSensor/:surveyId", {
slaves: { type: "string" },
sensors: { type: "string" },
motor_switches: { type: "string" },
master_connections: {
type: "array",
maxItems: 2500,
items: {
type: "object",
properties: {
master_name: { type: "string", default: null },
slaves: { type: "string", default: null },
tanks: {
type: "array",
items: {
type: "object",
properties: {
tankName: { type: "string", default: null },
tankLocation: { type: "string", default: null },
},
},
default: [],
},
},
},
},
electricals: {
type: "array",
maxItems: 2500,
@ -1554,23 +1577,22 @@ fastify.get("/api/orders/:customerId", {
fastify.post("/api/editQuotationForSensor/:quatationId", {
schema: {
description: "This is for edit quotation for sensors",
description: "This is for editing quotation for sensors",
tags: ["Install"],
summary: "This is for edit quotation for sensors",
summary: "Edit an existing sensor quotation",
params: {
required: ["quatationId"],
type: "object",
properties: {
quatationId: {
type: "string",
description: "quatationId",
description: "Quotation ID",
},
},
},
body: {
type: "object",
properties: {
masters: { type: "string" },
slaves: { type: "string" },
sensors: { type: "string" },
@ -1588,12 +1610,35 @@ fastify.post("/api/editQuotationForSensor/:quatationId", {
},
},
},
master_connections: { // Added master_connections to schema
type: "array",
maxItems: 2500,
items: {
type: "object",
properties: {
master_name: { type: "string", default: null },
slaves: { type: "string", default: null },
tanks: {
type: "array",
items: {
type: "object",
properties: {
tankName: { type: "string", default: null },
tankLocation: { type: "string", default: null },
},
},
default: [],
},
},
},
},
},
},
},
handler: storeController.editQuotationForSensor,
});
fastify.post("/api/getquotationofinstalleranduser/:surveyId", {
schema: {
tags: ["Install"],

Loading…
Cancel
Save