save the master slave data

master^2
Bhaskar 6 months ago
parent 5ba5720fef
commit 961fcd2fbf

@ -3,7 +3,7 @@ const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken'); const jwt = require('jsonwebtoken');
const customJwtAuth = require("../customAuthJwt"); const customJwtAuth = require("../customAuthJwt");
const { Deparments } = require("../models/Department"); 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 { Counter } = require("../models/User");
const { IotData, Tank } = require("../models/tanks"); const { IotData, Tank } = require("../models/tanks");
const fastify = require("fastify")({ const fastify = require("fastify")({
@ -673,3 +673,46 @@ exports.getAllocatedSensorsByTank = async (req, reply) => {
return reply.status(500).send({ error: "Internal server error" }); 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 });
}
};

@ -652,8 +652,28 @@ const salesSchema = new mongoose.Schema({
updatedBy: ObjectId, updatedBy: ObjectId,
}, { versionKey: false }); }, { 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 Iotprice = mongoose.model('Iotprice', iotpriceSchema);
const Insensors = mongoose.model('Insensors', insensorsSchema); const Insensors = mongoose.model('Insensors', insensorsSchema);
const MasterSlaveData = mongoose.model('MasterSlaveData', masterSlaveDataSchema);
const Order = mongoose.model('Order', orderSchema); const Order = mongoose.model('Order', orderSchema);
const EstimationOrder = mongoose.model('EstimationOrder', estimationorderSchema); 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};

@ -279,6 +279,37 @@ module.exports = function (fastify, opts, next) {
handler: installationController.getAllocatedSensorsByTank, 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(); next();

Loading…
Cancel
Save