diff --git a/src/controllers/tankersController.js b/src/controllers/tankersController.js index 2df06947..fd43c617 100644 --- a/src/controllers/tankersController.js +++ b/src/controllers/tankersController.js @@ -1,4 +1,4 @@ -const { Tanker, Tankerbooking } = require('../models/tankers') +const { Tanker, Tankerbooking,Bore } = require('../models/tankers') const User = require("../models/User"); const boom = require("boom"); @@ -166,6 +166,55 @@ exports.getTanker = async (req, reply) => { console.log(err); reply.send({ error: err }); }); + } catch (err) { + throw boom.boomify(err); + } +}; + +exports.addBores = async (req, reply) => { + try { + + //const username = req.params.username; + + //console.log(req.params); + const username = loginObject.user.username; + //console.log(loginObject.user.username) + // const userInfo = await User.findOne({ username: username.toString() }); + // const updateData = req.body; + + + + // console.log("This is the reply in the handler after the validations", reply); + boresData = { + boreName: req.body.boreName, + typeofwater: req.body.typeofwater, + description: req.body.description, + }; + + + var bore_Name = req.body.boreName + var i_bore = await Bore.findOne({ boreName: bore_Name}) + if(i_bore){ + throw new Error('Bore already exists'); + } + else { + + var bores = new Bore(boresData); + + checkFormEncoding = isUserFormUrlEncoded(req); + if (checkFormEncoding.isUserFormUrlEncoded) { + usertobeInserted = checkFormEncoding.bores; + console.log("thsi true url string"); + bores.boreName = usertobeInserted.boreName; + bores.typeofwater = usertobeInserted.typeofwater; + bores.description = usertobeInserted.description; + } + } + const insertedBore = await bores.save(); + + return insertedBore; + + } catch (err) { throw boom.boomify(err); } diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index fefcb13a..39dc5cfb 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -26,7 +26,7 @@ console.log(req.params); blockName: req.body.blockName, capacity: req.body.capacity, typeOfWater: req.body.typeOfWater, - type: req.body.type, + tankLocation:req.body.tankLocation, }; @@ -47,7 +47,7 @@ console.log(req.params); tank.blockName = usertobeInserted.blockName; tank.capacity = usertobeInserted.capacity; tank.typeOfWater = usertobeInserted.typeOfWater; - tank.typer = usertobeInserted.type; + tank.tankLocation = usertobeInserted.tankLocation; } } diff --git a/src/models/tankers.js b/src/models/tankers.js index 2c0a0545..c8d76a18 100644 --- a/src/models/tankers.js +++ b/src/models/tankers.js @@ -36,11 +36,21 @@ const tankersbookingSchema = new mongoose.Schema({ }); +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 Tanker = mongoose.model("Tanker", tankersSchema); const Tankerbooking = mongoose.model("Tankerbooking", tankersbookingSchema); +const Bore = mongoose.model("Bore", boreSchema); // Exporting our model objects module.exports = { - Tanker, Tankerbooking + Tanker, Tankerbooking,Bore } diff --git a/src/models/tanks.js b/src/models/tanks.js index b16f598c..7d24b2b8 100644 --- a/src/models/tanks.js +++ b/src/models/tanks.js @@ -15,7 +15,7 @@ const tanksSchema = new mongoose.Schema({ blockName: { type: String, default: null }, capacity: { type: String, default: null }, typeOfWater: { type: String, default: null }, - type: { type: String, default: null }, + tankLocation: { type: String, default: null }, connections: { source: { type: String}, diff --git a/src/routes/tankersRoute.js b/src/routes/tankersRoute.js index 623038fc..394a1f85 100644 --- a/src/routes/tankersRoute.js +++ b/src/routes/tankersRoute.js @@ -10,9 +10,9 @@ module.exports = function (fastify, opts, next) { method: "POST", url: "/api/addTankers", schema: { - tags: ["Tanker"], - description: "This is for cretae New Tanker", - summary: "This is for Create New Tanker.", + tags: ["Supplier"], + description: "This is to cretae New Tanker", + summary: "This is to Create New Tanker.", body: { type: "object", properties: { @@ -43,8 +43,8 @@ module.exports = function (fastify, opts, next) { method: "PUT", url: "/api/updateTankers/:tankerName", schema: { - tags: ["Tanker"], - summary: "This is for update tanker", + tags: ["Supplier"], + summary: "This is to update tanker", params: { required: ["tankerName"], type: "object", @@ -84,8 +84,8 @@ module.exports = function (fastify, opts, next) { method: "PUT", url: "/api/deleteTanker/:tankerName", schema: { - tags: ["Tanker"], - summary: "This is for delete tanker", + tags: ["Supplier"], + summary: "This is to delete tanker", params: { required: ["tankerName"], type: "object", @@ -113,7 +113,7 @@ module.exports = function (fastify, opts, next) { method: "POST", url: "/api/bookingData", schema: { - tags: ["Tanker"], + tags: ["Supplier"], description: "This is for storing booking data of a Tanker", summary: "This is for storing booking data of a Tanker", body: { @@ -145,7 +145,7 @@ module.exports = function (fastify, opts, next) { fastify.get("/api/getTankers", { schema: { - tags: ["Tanker"], + tags: ["Supplier"], description: "This is for Get Tanker Data", summary: "This is for to Get Tanker Data", querystring: { @@ -160,6 +160,36 @@ module.exports = function (fastify, opts, next) { preHandler: fastify.auth([fastify.authenticate]), handler: tankersController.getTanker, }); + + fastify.route({ + method: "POST", + url: "/api/addBores", + schema: { + tags: ["Supplier"], + description: "This is to cretae New Bore", + summary: "This is to Create New Bore.", + body: { + type: "object", + properties: { + boreName: { type: "string" }, + typeofwater: { type: "string" }, + description: { type: "string" }, + }, + }, + security: [ + { + basicAuth: [], + }, + ], + + }, + preHandler: fastify.auth([fastify.authenticate]), + handler: tankersController.addBores, + // onResponse: (request, reply) => { + // validationHandler.sendPhoneVerificationCode(request, reply); + // }, + //onResponse: validationHandler.sendPhoneVerificationCode, + });