|
|
|
@ -10,7 +10,7 @@ const fastify = require("fastify")({
|
|
|
|
|
return uuidv4();
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
const { Install, ProfilePictureInstall, generateinstallationId,Store,WaterLeverSensor} = require("../models/store");
|
|
|
|
|
const { Install, ProfilePictureInstall, generateinstallationId,Store,WaterLeverSensor,MotorSwitchSensor} = require("../models/store");
|
|
|
|
|
const { User,Counter, generateBookingId,resetCounter,generateCustomerId,ProfilePicture} = require('../models/User')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -513,7 +513,7 @@ exports.addStore = async (request, reply) => {
|
|
|
|
|
const { hardwareId,hardwareId_company, type, indate } = req.body;
|
|
|
|
|
var mater_seq_id = await generatewaterlevelsensorId();
|
|
|
|
|
const date = moment().format('MM-DD');
|
|
|
|
|
const prefix = 'AS' + date + 'MALOV1-';
|
|
|
|
|
const prefix = 'AS' + date + 'MALOV1';
|
|
|
|
|
var masterId = `${prefix}${mater_seq_id}`;
|
|
|
|
|
const newSensor = new WaterLeverSensor({
|
|
|
|
|
storeId,
|
|
|
|
@ -597,6 +597,23 @@ exports.addStore = async (request, reply) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getHardwaremotorswitch = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
await MotorSwitchSensor.find({storeId: req.params.storeId})
|
|
|
|
|
.exec()
|
|
|
|
|
.then((docs) => {
|
|
|
|
|
reply.send({ status_code: 200, data: docs, count: docs.length });
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.log(err);
|
|
|
|
|
reply.send({ error: err });
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getHardwareqc = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
await WaterLeverSensor.find({storeId: req.params.storeId,hardwareId:req.body.hardwareId})
|
|
|
|
@ -635,7 +652,7 @@ exports.addStore = async (request, reply) => {
|
|
|
|
|
}
|
|
|
|
|
var slave_seq_id = await generatewaterlevelslavesensorId();
|
|
|
|
|
const date = moment().format('MM-DD');
|
|
|
|
|
const prefix = 'AS' + date + 'SLAOV1-';
|
|
|
|
|
const prefix = 'AS' + date + 'SLAOV1';
|
|
|
|
|
var slaveId = `${prefix}${slave_seq_id}`;
|
|
|
|
|
// Create new slave
|
|
|
|
|
const newSlave = {
|
|
|
|
@ -668,6 +685,7 @@ exports.qccheckwaterlevelSensorSlave = async (request, reply) => {
|
|
|
|
|
const updatedSensor = await WaterLeverSensor.findOneAndUpdate(
|
|
|
|
|
{
|
|
|
|
|
storeId: storeId,
|
|
|
|
|
hardwareId:request.body.hardwareId,
|
|
|
|
|
"slaves.tankhardware.tankhardwareId": request.body.tankhardwareId
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
@ -763,3 +781,73 @@ exports.getHardwareqcslave = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.createmotorswitchSensor = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const storeId = req.params.storeId
|
|
|
|
|
const { motorId, type, indate } = req.body;
|
|
|
|
|
var mater_seq_id = await generatewaterlevelsensorId();
|
|
|
|
|
const date = moment().format('MM-DD');
|
|
|
|
|
const prefix = 'AS' + date + 'PSV1';
|
|
|
|
|
var masterId = `${prefix}${mater_seq_id}`;
|
|
|
|
|
const newSensor = new MotorSwitchSensor({
|
|
|
|
|
storeId,
|
|
|
|
|
motorId,
|
|
|
|
|
masterId,
|
|
|
|
|
type,
|
|
|
|
|
indate
|
|
|
|
|
});
|
|
|
|
|
const savedSensor = await newSensor.save();
|
|
|
|
|
reply.code(200).send(savedSensor);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
reply.code(500).send(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.qccheckmotorswitch = async (request, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { motorId } = request.params;
|
|
|
|
|
const updateData = request.body;
|
|
|
|
|
|
|
|
|
|
// Find the document by hardwareId and update it with the fields received in the body
|
|
|
|
|
const updatedSensor = await MotorSwitchSensor.findOneAndUpdate(
|
|
|
|
|
{ motorId: motorId },
|
|
|
|
|
{ $set: updateData },
|
|
|
|
|
{ new: true } // Return the updated document
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!updatedSensor) {
|
|
|
|
|
return reply.status(404).send({ error: 'Sensor not found' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return reply.status(200).send(updatedSensor);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
return reply.status(500).send({ error: 'An error occurred while updating the sensor' });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.installmotorswitch = async (request, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { storeId } = request.params;
|
|
|
|
|
const updateData = request.body;
|
|
|
|
|
|
|
|
|
|
// Find the document by hardwareId and update it with the fields received in the body
|
|
|
|
|
const updatedSensor = await MotorSwitchSensor.findOneAndUpdate(
|
|
|
|
|
{ storeId:storeId,motorId: request.body.motorId, },
|
|
|
|
|
{ $set: updateData },
|
|
|
|
|
{ new: true } // Return the updated document
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!updatedSensor) {
|
|
|
|
|
return reply.status(404).send({ error: 'Sensor not found' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return reply.status(200).send(updatedSensor);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
return reply.status(500).send({ error: 'An error occurred while updating the sensor' });
|
|
|
|
|
}
|
|
|
|
|
};
|