ashok 1 year ago
commit bde5d1be5e

@ -1079,14 +1079,22 @@ exports.createquotationforSensor = async (req, reply) => {
const { installationId } = req.params; const { installationId } = req.params;
const { customerId, masters, slaves, motor_switches, electricals } = req.body; const { customerId, masters, slaves, motor_switches, electricals } = req.body;
// Validate electricals field to ensure it's an array of objects
if (!Array.isArray(electricals) || electricals.some(e => typeof e !== 'object')) {
return reply.code(400).send({
success: false,
message: 'Invalid data format for electricals. It should be an array of objects with "name" and "type".'
});
}
// Create a new SensorQuotation document // Create a new SensorQuotation document
const newQuotation = new SensorQuotation({ const newQuotation = new SensorQuotation({
customerIdId: customerId, customerId: customerId,
installationId: installationId, // Assuming installationId is being used as InstallerId installationId: installationId, // Using installationId for the field
masters, masters,
slaves, slaves,
motor_switches, motor_switches,
electricals, // This will store the array of electrical items electricals, // This will store the array of electrical items (objects)
}); });
// Save the document to the database // Save the document to the database

@ -252,7 +252,7 @@ const insensorsSchema = new mongoose.Schema({
const sensorquotationSchema = new mongoose.Schema({ const sensorquotationSchema = new mongoose.Schema({
customerIdId: { type: String }, customerId: { type: String },
installationId: { type: String, default: null }, installationId: { type: String, default: null },
masters: { type: String }, masters: { type: String },
slaves: { type: String }, slaves: { type: String },
@ -265,8 +265,9 @@ const sensorquotationSchema = new mongoose.Schema({
// Define electricals as an array of strings or objects // Define electricals as an array of strings or objects
electricals: [ electricals: [
{ {
type: String, // or Object, based on your requirements name: { type: String },
default: null type: { type: String },
} }
] ]
}); });

@ -793,8 +793,13 @@ fastify.post("/api/createquotationforSensor/:installationId", {
type: "array", type: "array",
description: "List of electrical items", description: "List of electrical items",
items: { items: {
type: "string" // or use "object" if each electrical item is more complex type: "object",
} properties: {
name: { type: "string", description: "Name of the electrical item" },
type: { type: "string", description: "Type of the electrical item" },
},
required: ["name", "type"],
},
}, },
}, },

Loading…
Cancel
Save