diff --git a/src/controllers/tankersController.js b/src/controllers/tankersController.js index ef2af941..083b4a90 100644 --- a/src/controllers/tankersController.js +++ b/src/controllers/tankersController.js @@ -1,4 +1,4 @@ -const { Tanker, Tankerbooking,Bore } = require('../models/tankers') +const { Tanker, Tankerbooking,Bore,GovtPipeLine } = require('../models/tankers') const User = require("../models/User"); const boom = require("boom"); @@ -196,7 +196,7 @@ exports.addBores = async (req, reply) => { if (checkFormEncoding.isUserFormUrlEncoded) { usertobeInserted = checkFormEncoding.bores; console.log("thsi true url string"); - tank.customerId = usertobeInserted.customerId + bores.customerId = usertobeInserted.customerId bores.boreName = usertobeInserted.boreName; bores.typeofwater = usertobeInserted.typeofwater; bores.description = usertobeInserted.description; @@ -264,3 +264,106 @@ exports.updateBoresInfo = async (req, reply) => { } }; + +exports.addGovtPIpeline = async (req, reply) => { + try { + + + var customerId = req.params.customerId; + //console.log(customerId); + //const username = loginObject.user.username; + + pipelineData = { + customerId:customerId, + Name: req.body.Name, + typeofwater: req.body.typeofwater, + description: req.body.description, + }; + + + var pipeline_Name = req.body.Name + var i_pipe = await GovtPipeLine.findOne({ Name: pipeline_Name,customerId:customerId}) + if(i_pipe){ + throw new Error('Pipeline already exists'); + } + else { + + var pipe_line = new GovtPipeLine(pipelineData); + + checkFormEncoding = isUserFormUrlEncoded(req); + if (checkFormEncoding.isUserFormUrlEncoded) { + usertobeInserted = checkFormEncoding.pipe_line; + console.log("thsi true url string"); + pipe_line.customerId = usertobeInserted.customerId + pipe_line.Name = usertobeInserted.Name; + pipe_line.typeofwater = usertobeInserted.typeofwater; + pipe_line.description = usertobeInserted.description; + } + } + const insertedpipeline = await pipe_line.save(); + + return insertedpipeline; + + + } catch (err) { + throw boom.boomify(err); + } +}; + + + +exports.getPipeline = async (req, reply) => { + try { + await GovtPipeLine.find({customerId: req.query.customerId}) + .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.deletePipelineInfo = async (req, reply) => { + try { + + + await GovtPipeLine.findOneAndDelete({customerId: req.params.customerId,Name: req.query.Name}); + //console.log(Bore) + + reply.send({ status_code: 200}); + // return Bore; + } catch (err) { + throw boom.boomify(err); + } +} + + + + +exports.updatePipelineInfo = async (req, reply) => { + + try { + var customerId = req.params.customerId; + var Name = req.query.Name; + const pipeline = req.body; + const { ...updateData } = pipeline; + const update = await GovtPipeLine.findOneAndUpdate({ customerId:customerId,Name: Name, }, updateData, { new: true }); + //console.log(update.username) + //return update; + + reply.send({ status_code: 200, data: update }); + + + } + catch (err) { + throw boom.boomify(err); + } +}; + diff --git a/src/models/tankers.js b/src/models/tankers.js index 2cca5ae0..7a995566 100644 --- a/src/models/tankers.js +++ b/src/models/tankers.js @@ -41,17 +41,28 @@ const boreSchema = new mongoose.Schema({ boreName: { type: String, default: null }, typeofwater: { type: String, default: null }, description: { type: String, default: null }, - type: { type: String, default: "bore" }, + }); +const GovtPipeLineSchema = new mongoose.Schema({ + customerId: { type: String, default: null }, + Name: { type: String, default: null }, + typeofwater: { type: String, default: null }, + description: { type: String, default: null }, + + +}); + + const Tanker = mongoose.model("Tanker", tankersSchema); const Tankerbooking = mongoose.model("Tankerbooking", tankersbookingSchema); const Bore = mongoose.model("Bore", boreSchema); +const GovtPipeLine = mongoose.model("GovtPipeLine", GovtPipeLineSchema); // Exporting our model objects module.exports = { - Tanker, Tankerbooking,Bore + Tanker, Tankerbooking,Bore,GovtPipeLine } diff --git a/src/routes/tankersRoute.js b/src/routes/tankersRoute.js index 8d104783..b1a5ff73 100644 --- a/src/routes/tankersRoute.js +++ b/src/routes/tankersRoute.js @@ -331,6 +331,143 @@ module.exports = function (fastify, opts, next) { + + fastify.route({ + method: "POST", + url: "/api/addGovtPIpeline/:customerId", + schema: { + tags: ["Supplier"], + description: "This is to cretae New addGovtPIpeline", + summary: "This is to Create New addGovtPIpeline.", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + body: { + type: "object", + properties: { + Name: { type: "string" }, + typeofwater: { type: "string" }, + description: { type: "string" }, + }, + }, + security: [ + { + basicAuth: [], + }, + ], + + }, + preHandler: fastify.auth([fastify.authenticate]), + handler: tankersController.addGovtPIpeline, + // onResponse: (request, reply) => { + // validationHandler.sendPhoneVerificationCode(request, reply); + // }, + //onResponse: validationHandler.sendPhoneVerificationCode, + }); + + fastify.get("/api/getPipelines", { + schema: { + tags: ["Supplier"], + description: "This is for Get Pipeline Data", + summary: "This is for to Get Pipeline Data", + querystring: { + customerId: {type: 'string'} + }, + security: [ + { + basicAuth: [], + }, + ], + }, + preHandler: fastify.auth([fastify.authenticate]), + handler: tankersController.getPipeline, + }); + + fastify.route({ + method: "PUT", + url: "/api/deletePipeline/:customerId", + schema: { + tags: ["Supplier"], + summary: "This is for delete Pipeline", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + querystring: { + Name: {type: 'string'} + }, + security: [ + { + basicAuth: [], + }, + ], + }, + + + //preHandler: fastify.auth([fastify.authenticate]), + handler: tankersController.deletePipelineInfo, + }); + + fastify.route({ + method: "PUT", + url: "/api/updatePipeline/:customerId", + schema: { + tags: ["Supplier"], + summary: "This is for update Pipeline", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + querystring: { + Name: {type: 'string'} + }, + + body: { + type: "object", + // required: ['phone'], + properties: { + + Name: { type: "string" }, + typeofwater: { type: "string" }, + description: { type: "string" }, + }, + }, + security: [ + { + basicAuth: [], + }, + ], + }, + // preHandler: [ + // fastify.auth([fastify.operatorAuthenticate]), + // validationHandler.validatePhoneFormat, + // ], + preHandler: fastify.auth([fastify.authenticate]), + handler: tankersController.updatePipelineInfo, + }); + + + +