motor switch add,qc and installation

master
varun 1 year ago
parent a3f038d027
commit 30ac59d903

@ -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' });
}
};

@ -88,9 +88,6 @@ async function deleteOldRecords() {
exports.addTanks = async (req, reply) => {
try {
const InstallerId = req.params.InstallerId;
const { customerId,hardwareId, tankhardwareId,tankName,tankLocation } = req.body;

@ -211,6 +211,27 @@ const waterLeverSensorInSchema = new mongoose.Schema({
});
const motorSwitchSensorInSchema = new mongoose.Schema({
storeId:{ type: String },
motorId: { type: String },
masterId: { type: String, default: null },
type: { type: String },
indate: { type: String },
qccheck: { type: String, default: null },
qccheckdate: { type: String, default: null },
qcby: { type: String, default: null },
comment: { type: String, default: "0" },
outforrepairdate: { type: String, default: "0" },
sendto: { type: String, default: null },
repairfeedback:{ type: String, default: "0" },
dateofinstallation: { type: String, default: null },
installedby: { type: String, default: "0" },
customerId:{ type: String,default:"0" },
comments:{ type: String,default:"0" },
});
@ -218,8 +239,8 @@ const waterLeverSensorInSchema = new mongoose.Schema({
const WaterLeverSensor = mongoose.model('WaterLeverSensor', waterLeverSensorInSchema);
const ProfilePictureStore = mongoose.model('ProfilePictureStore', profilePictureStoreSchema);
const ProfilePictureInstall = mongoose.model('ProfilePictureInstall', profilePictureInstallSchema);
const MotorSwitchSensor = mongoose.model('MotorSwitchSensor', motorSwitchSensorInSchema);
const Install = mongoose.model("Install", installationschema);
module.exports = { Install, ProfilePictureInstall, generateinstallationId,Store,ProfilePictureStore,WaterLeverSensor};
module.exports = { Install, ProfilePictureInstall, generateinstallationId,Store,ProfilePictureStore,WaterLeverSensor,MotorSwitchSensor};

@ -236,6 +236,7 @@ fastify.post("/api/qccheckwaterlevelslaveSensor/:storeId", {
body: {
type: "object",
properties: {
hardwareId: { type: "string" },
tankhardwareId: { type: "string" },
qccheck: { type: "string" },
qccheckdate: { type: "string" },
@ -256,7 +257,7 @@ fastify.get("/api/getHardware/:storeId", {
schema: {
tags: ["Store-Data"],
description: "This is to Get Hardware Data",
summary: "This is to Get Hardware Tank Data",
summary: "This is to Get Hardware Data",
params: {
required: ["storeId"],
type: "object",
@ -401,5 +402,125 @@ fastify.put("/api/getHardwareqcslave/:storeId", {
});
fastify.post("/api/createmotorswitchSensor/:storeId", {
schema: {
description: "This is for creating motor switch",
tags: ["Store-Data"],
summary: "This is for creating motor switch",
params: {
required: ["storeId"],
type: "object",
properties: {
storeId: {
type: "string",
description: "storeId",
},
},
},
body: {
type: "object",
properties: {
motorId: { type: "string" },
type: { type: "string" },
indate: { type: "string" },
},
},
},
handler: storeController.createmotorswitchSensor,
})
fastify.post("/api/qccheckpumpswitch/:motorId", {
schema: {
description: "This is for checking motor switch",
tags: ["Store-Data"],
summary: "This is for checking motor switch",
params: {
required: ["motorId"],
type: "object",
properties: {
motorId: {
type: "string",
description: "motorId",
},
},
},
body: {
type: "object",
properties: {
qccheck: { type: "string" },
qccheckdate: { type: "string" },
qcby: { type: "string" },
comment: { type: "string" },
outforrepairdate: { type: "string" },
sendto: { type: "string" },
repairfeedback: { type: "string" },
},
},
},
handler: storeController.qccheckmotorswitch,
})
fastify.get("/api/getHardwaremotorswitch/:storeId", {
schema: {
tags: ["Store-Data"],
description: "This is to Get Motor Switches",
summary: "This is to Get Motor Switches",
params: {
required: ["storeId"],
type: "object",
properties: {
storeId: {
type: "string",
description: "storeId",
},
},
},
security: [
{
basicAuth: [],
},
],
},
// preHandler: fastify.auth([fastify.authenticate]),
handler: storeController.getHardwaremotorswitch,
});
fastify.post("/api/installmotorswitch/:storeId", {
schema: {
description: "This is for installing Motor Switch",
tags: ["Store-Data"],
summary: "This is for installing Motor Switch",
params: {
required: ["storeId"],
type: "object",
properties: {
storeId: {
type: "string",
description: "storeId",
},
},
},
body: {
type: "object",
properties: {
motorId: { type: "string" },
dateofinstallation: { type: "string" },
customerId: { type: "string" },
installedby: { type: "string" }
},
},
},
handler: storeController.installmotorswitch,
})
next();
};

Loading…
Cancel
Save