diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index 3f45fdb9..5c8fc203 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -3,7 +3,7 @@ const bcrypt = require('bcrypt'); const jwt = require('jsonwebtoken'); const customJwtAuth = require("../customAuthJwt"); const { Deparments } = require("../models/Department"); -const { Install, SensorStock, SensorQuotation, Order, Insensors } = require("../models/store"); +const { Install, SensorStock, SensorQuotation, Order, Insensors, MasterSlaveData } = require("../models/store"); const { Counter } = require("../models/User"); const { IotData, Tank } = require("../models/tanks"); const fastify = require("fastify")({ @@ -673,3 +673,46 @@ exports.getAllocatedSensorsByTank = async (req, reply) => { return reply.status(500).send({ error: "Internal server error" }); } }; + +exports.createMasterSlaveData = async (req, reply) => { + try { + const { installationId } = req.params; + const { + type, + hardwareId, + batchno, + masterId, + tankName, + tankLocation, + materialRecived, + electicityWork, + plumbingWork, + loraCheck + } = req.body; + + if (!installationId || !hardwareId || !masterId) { + return reply.status(400).send({ message: "installationId, hardwareId, and masterId are required." }); + } + + const newData = new MasterSlaveData({ + installationId, + type, + hardwareId, + batchno, + masterId, + tankName, + tankLocation, + materialRecived, + electicityWork, + plumbingWork, + loraCheck + }); + + // Save to database + await newData.save(); + + reply.status(201).send({ message: "Master-Slave data created successfully", data: newData }); + } catch (err) { + reply.status(500).send({ message: err.message }); + } +}; diff --git a/src/models/store.js b/src/models/store.js index bb91d1ff..7a077735 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -652,8 +652,28 @@ const salesSchema = new mongoose.Schema({ updatedBy: ObjectId, }, { versionKey: false }); + +const masterSlaveDataSchema = new mongoose.Schema({ + installationId: {type: String}, + type: { type: String}, + hardwareId: { type: String }, + batchno: { type: String, default: null }, + masterId: { type: String }, + tankName: { type: String }, + tankLocation: { type: String }, + materialRecived: { type: String }, + electicityWork: { type: String }, + plumbingWork: { type: String }, + loraCheck: { type: String }, + +}, { + timestamps: true, +}); + const Iotprice = mongoose.model('Iotprice', iotpriceSchema); const Insensors = mongoose.model('Insensors', insensorsSchema); + const MasterSlaveData = mongoose.model('MasterSlaveData', masterSlaveDataSchema); + const Order = mongoose.model('Order', orderSchema); const EstimationOrder = mongoose.model('EstimationOrder', estimationorderSchema); @@ -675,4 +695,4 @@ const Iotprice = mongoose.model('Iotprice', iotpriceSchema); - module.exports = {SensorStock,Order,EstimationOrder,Iotprice,Sales, Install,Survey, ProfilePictureInstall, SensorQuotation,generateinstallationId,Store,ProfilePictureStore,WaterLeverSensor,MotorSwitchSensor,Insensors,generatequatationId, HardwareCart, ServiceCart}; + module.exports = {MasterSlaveData,SensorStock,Order,EstimationOrder,Iotprice,Sales, Install,Survey, ProfilePictureInstall, SensorQuotation,generateinstallationId,Store,ProfilePictureStore,WaterLeverSensor,MotorSwitchSensor,Insensors,generatequatationId, HardwareCart, ServiceCart}; diff --git a/src/routes/installationRoute.js b/src/routes/installationRoute.js index f9aa6058..c2ca1113 100644 --- a/src/routes/installationRoute.js +++ b/src/routes/installationRoute.js @@ -279,6 +279,37 @@ module.exports = function (fastify, opts, next) { handler: installationController.getAllocatedSensorsByTank, }); + fastify.post("/api/createMasterSlaveData/:installationId", { + schema: { + description: "Create a new Master-Slave data entry under an installation", + tags: ["Installation"], + summary: "Save Master-Slave Data", + params: { + type: "object", + required: ["installationId"], + properties: { + installationId: { type: "string", description: "Installation ID to associate the master-slave data with" } + } + }, + body: { + type: "object", + required: ["hardwareId", "masterId"], + properties: { + type: { type: "string", description: "Type of the device (master/slave)" }, + hardwareId: { type: "string", description: "Hardware ID of the device" }, + batchno: { type: "string", description: "Batch number (optional)" }, + masterId: { type: "string", description: "Master ID associated with the device" }, + tankName: { type: "string", description: "Name of the tank" }, + tankLocation: { type: "string", description: "Location of the tank" }, + materialRecived: { type: "string", description: "Material received status" }, + electicityWork: { type: "string", description: "Electricity work status" }, + plumbingWork: { type: "string", description: "Plumbing work status" }, + loraCheck: { type: "string", description: "LoRa check status" } + } + } + }, + handler: installationController.createMasterSlaveData + }); next();