create and get bores for installer

master
varun 1 year ago
parent 8bee134e88
commit d783185e69

@ -452,6 +452,23 @@ exports.getBores = async (req, reply) => {
};
exports.getBoresbyInstaller = async (req, reply) => {
try {
await Bore.find({InstallerId: req.query.InstallerId})
.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.deleteBoresInfo = async (req, reply) => {
try {

@ -134,11 +134,12 @@ exports.addTanks = async (req, reply) => {
exports.updateTanksInfo = async (req, reply) => {
try {
var customerId = req.params.customerId;
var tankName = req.query.tankName;
const InstallerId = req.params.InstallerId;
const customerId = req.body.customerId;
const tankName = req.query.tankName;
const tank = req.body;
const { ...updateData } = tank;
const update = await Tank.findOneAndUpdate({ tankName: tankName,customerId:customerId, }, updateData, { new: true });
const update = await Tank.findOneAndUpdate({ InstallerId:InstallerId,tankName: tankName,customerId:customerId }, updateData, { new: true });
console.log(update.username)
//return update;
@ -155,10 +156,11 @@ exports.updateTanksInfo = async (req, reply) => {
//delete selected tank
exports.deleteTanksInfo = async (req, reply) => {
try {
const customerId = req.params.customerId;
const InstallerId = req.params.InstallerId;
const customerId = req.body.customerId;
const tankName = req.query.tankName;
const tankLocation = req.body.tankLocation.toLowerCase();
const tank = await Tank.findOneAndDelete({ tankName: tankName,customerId:customerId,tankLocation:tankLocation });
const tank = await Tank.findOneAndDelete({ InstallerId:InstallerId,tankName: tankName,customerId:customerId,tankLocation:tankLocation });
reply.send({ status_code: 200, data: tank});
// return tank;
@ -170,13 +172,15 @@ exports.deleteTanksInfo = async (req, reply) => {
exports.getConnectionsInfoOfParticularTank = async (req, reply) => {
try {
const customerId = req.params.customerId;
const InstallerId = req.params.InstallerId;
const customerId = req.body.customerId;
const tankName = req.body.tankName;
const tankLocation = req.body.tankLocation.toLowerCase();
console.log(customerId, tankName, tankLocation);
// Find the specific tank
const mainTank = await Tank.findOne({
InstallerId:InstallerId,
tankName: tankName,
customerId: customerId,
tankLocation: tankLocation
@ -212,7 +216,21 @@ exports.getTank = async (req, reply) => {
}
};
exports.getTanksofParticularInstaller = async (req, reply) => {
try {
await Tank.find({InstallerId: req.query.InstallerId})
.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.getTanklevels = async (req, reply) => {
// try {
// const customerId = req.params.customerId;
@ -1170,7 +1188,7 @@ exports.motorAction = async (req, reply) => {
supplier_type: req.body.from_type,
receiver_type: req.body.to_type,
startTime: req.body.startTime,
receiverwaterlevel:parseInt(receiver_tank_info7.waterlevel, 10)
receiverInitialwaterlevel:parseInt(receiver_tank_info7.waterlevel, 10)
});
await newMotorData.save();
// If threshold type is percentage, calculate percentage threshold

@ -384,6 +384,24 @@ module.exports = function (fastify, opts, next) {
handler: tankersController.getBores,
});
fastify.get("/api/getBoresbyInstaller", {
schema: {
tags: ["Tank"],
description: "This is for Get Bore Data of Installer",
summary: "This is for to Get Bore Data of installer",
querystring: {
InstallerId: {type: 'string'}
},
security: [
{
basicAuth: [],
},
],
},
preHandler: fastify.auth([fastify.authenticate]),
handler: tankersController.getBoresbyInstaller,
});
fastify.route({
method: "PUT",
url: "/api/deleteBore/:customerId",

@ -53,17 +53,17 @@ module.exports = function (fastify, opts, next) {
fastify.route({
method: "PUT",
url: "/api/updateTanks/:customerId",
url: "/api/updateTanks/:InstallerId",
schema: {
tags: ["Tank"],
summary: "This is for update tank",
params: {
required: ["customerId"],
required: ["InstallerId"],
type: "object",
properties: {
customerId: {
InstallerId: {
type: "string",
description: "customerId",
description: "InstallerId",
},
},
},
@ -75,7 +75,7 @@ module.exports = function (fastify, opts, next) {
type: "object",
// required: ['phone'],
properties: {
customerId: { type: "string", default: null },
tankName: { type: "string", default: null },
blockName: { type: "string", default: null },
capacity: { type: "string" },
@ -101,17 +101,17 @@ module.exports = function (fastify, opts, next) {
fastify.route({
method: "PUT",
url: "/api/deleteTank/:customerId",
url: "/api/deleteTank/:InstallerId",
schema: {
tags: ["Tank"],
summary: "This is for delete tank",
params: {
required: ["customerId"],
required: ["InstallerId"],
type: "object",
properties: {
customerId: {
InstallerId: {
type: "string",
description: "customerId",
description: "InstallerId",
},
},
},
@ -123,7 +123,7 @@ module.exports = function (fastify, opts, next) {
// required: ['phone'],
properties: {
customerId: { type: "string", default: null },
tankLocation: { type: "string", default: null },
},
},
@ -140,17 +140,17 @@ module.exports = function (fastify, opts, next) {
fastify.route({
method: "PUT",
url: "/api/getConnectionsInfoOfParticularTank/:customerId",
url: "/api/getConnectionsInfoOfParticularTank/:InstallerId",
schema: {
tags: ["Tank"],
summary: "This is to get Connections Info Of ParticularTank",
params: {
required: ["customerId"],
required: ["InstallerId"],
type: "object",
properties: {
customerId: {
InstallerId: {
type: "string",
description: "customerId",
description: "InstallerId",
},
},
},
@ -159,6 +159,7 @@ module.exports = function (fastify, opts, next) {
type: "object",
// required: ['phone'],
properties: {
customerId: { type: "string", default: null },
tankName: {type: 'string'},
tankLocation: { type: "string", default: null },
@ -182,6 +183,7 @@ module.exports = function (fastify, opts, next) {
tags: ["Tank"],
description: "This is to Get Tank Data",
summary: "This is to Get Tank Data",
querystring: {
customerId: {type: 'string'}
},
@ -194,6 +196,25 @@ module.exports = function (fastify, opts, next) {
// preHandler: fastify.auth([fastify.authenticate]),
handler: tanksController.getTank,
});
fastify.get("/api/getTanksofParticularInstaller", {
schema: {
tags: ["Tank"],
description: "This is to Get Tank Data of Installer",
summary: "This is to Get Tank Data of Installer",
querystring: {
InstallerId: {type: 'string'}
},
security: [
{
basicAuth: [],
},
],
},
// preHandler: fastify.auth([fastify.authenticate]),
handler: tanksController.getTanksofParticularInstaller,
});
fastify.route({
method: "PUT",

Loading…
Cancel
Save