ashok 1 year ago
commit bde5d1be5e

@ -1079,14 +1079,22 @@ exports.createquotationforSensor = async (req, reply) => {
const { installationId } = req.params;
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
const newQuotation = new SensorQuotation({
customerIdId: customerId,
installationId: installationId, // Assuming installationId is being used as InstallerId
customerId: customerId,
installationId: installationId, // Using installationId for the field
masters,
slaves,
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

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

@ -793,8 +793,13 @@ fastify.post("/api/createquotationforSensor/:installationId", {
type: "array",
description: "List of electrical 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