sending quote for sensors

master
Varun 1 year ago
parent cd70393d48
commit c340e70a74

@ -10,7 +10,7 @@ const fastify = require("fastify")({
return uuidv4();
},
});
const { Install, ProfilePictureInstall, generateinstallationId,Store,WaterLeverSensor,MotorSwitchSenso,Insensors} = require("../models/store");
const { Install, ProfilePictureInstall, SensorQuotation,generateinstallationId,Store,WaterLeverSensor,MotorSwitchSenso,Insensors} = require("../models/store");
const { User,Counter, generateBookingId,resetCounter,generateCustomerId,ProfilePicture} = require('../models/User')
@ -1070,4 +1070,45 @@ exports.getusersofParticularInstaller = async (req, reply) => {
} catch (err) {
throw boom.boomify(err);
}
};
};
exports.createquotationforSensor = async (req, reply) => {
try {
// Extract parameters and body data from the request
const { installationId } = req.params;
const { customerId, masters, slaves, motor_switches, electricals } = req.body;
// Create a new SensorQuotation document
const newQuotation = new SensorQuotation({
customerIdId: customerId,
installationId: installationId, // Assuming installationId is being used as InstallerId
masters,
slaves,
motor_switches,
electricals, // This will store the array of electrical items
});
// Save the document to the database
const savedQuotation = await newQuotation.save();
// Send a success response with the saved document
reply.code(201).send({
success: true,
message: 'Quotation for sensors created successfully.',
data: savedQuotation,
});
} catch (error) {
// Handle errors and send error response
console.error('Error creating quotation:', error);
reply.code(500).send({
success: false,
message: 'Failed to create quotation for sensors.',
error: error.message,
});
}
};

@ -251,6 +251,25 @@ const insensorsSchema = new mongoose.Schema({
});
const sensorquotationSchema = new mongoose.Schema({
customerIdId: { type: String },
installationId: { type: String, default: null },
masters: { type: String },
slaves: { type: String },
motor_switches: { type: String },
quote_status: { type: String, default: null },
quoted_amount: { type: String, default: null },
comments: { type: String, default: null },
// Define electricals as an array of strings or objects
electricals: [
{
type: String, // or Object, based on your requirements
default: null
}
]
});
@ -260,7 +279,9 @@ const insensorsSchema = new mongoose.Schema({
const ProfilePictureStore = mongoose.model('ProfilePictureStore', profilePictureStoreSchema);
const ProfilePictureInstall = mongoose.model('ProfilePictureInstall', profilePictureInstallSchema);
const MotorSwitchSensor = mongoose.model('MotorSwitchSensor', motorSwitchSensorInSchema);
const SensorQuotation = mongoose.model('SensorQuotationSchema', sensorquotationSchema);
const Install = mongoose.model("Install", installationschema);
module.exports = { Install, ProfilePictureInstall, generateinstallationId,Store,ProfilePictureStore,WaterLeverSensor,MotorSwitchSensor,Insensors};
module.exports = { Install, ProfilePictureInstall, SensorQuotation,generateinstallationId,Store,ProfilePictureStore,WaterLeverSensor,MotorSwitchSensor,Insensors,};

@ -764,7 +764,44 @@ fastify.get("/api/getbatchnumbers/:storeId", {
handler: storeController.getbatchnumbers,
});
fastify.post("/api/createquotationforSensor/:installationId", {
schema: {
description: "This is for sending quotation for sensors",
tags: ["Install"],
summary: "This is for sending quotation for sensors",
params: {
required: ["installationId"],
type: "object",
properties: {
installationId: {
type: "string",
description: "installationId",
},
},
},
body: {
type: "object",
properties: {
customerId: { type: "string" },
masters: { type: "string" },
slaves: { type: "string" },
motor_switches: { type: "string" },
electricals: {
type: "array",
description: "List of electrical items",
items: {
type: "string" // or use "object" if each electrical item is more complex
}
},
},
},
},
handler: storeController.createquotationforSensor,
})
next();

Loading…
Cancel
Save