diff --git a/src/controllers/tankersController.js b/src/controllers/tankersController.js index 684eb176..9f36d0f1 100644 --- a/src/controllers/tankersController.js +++ b/src/controllers/tankersController.js @@ -28,14 +28,15 @@ console.log(req.params); tankersData = { supplierId:supplierId, - supplier_name:req.body.username, + supplier_name:req.body.supplier_name, supplier_address : req.body.supplier_address, tankerName: req.body.tankerName, phoneNumber: req.body.phoneNumber, alternative_phoneNumber: req.body.alternative_phoneNumber, typeofwater: req.body.typeofwater, capacity: req.body.capacity, - price: req.body.price + price: req.body.price, + status: req.body.status }; console.log(req.body.typeofwater,req.body.capacity) @@ -61,6 +62,7 @@ console.log(req.params); tankers.typeofwater = usertobeInserted.typeofwater; tankers.supplierId = usertobeInserted.supplierId; tankers.price = usertobeInserted.price; + tankers.status = usertobeInserted.status; } } const insertedTanker = await tankers.save(); @@ -437,3 +439,26 @@ exports.updatePipelineInfo = async (req, reply) => { } }; +exports.status = async (req, reply) => { + + try { + var status = req.query.status; + + if (status === 'connected') { + try { + const tankers = await Tanker.find({}); + console.log("tankers...", tankers) + reply.send(tankers); + } catch (err) { + reply.send({ message: err }); + } + } else { + reply.send({ message: 'Not Connected' }); + } + + } + catch (err) { + throw boom.boomify(err); + } +}; + diff --git a/src/models/tankers.js b/src/models/tankers.js index e73e520d..bf8e8efb 100644 --- a/src/models/tankers.js +++ b/src/models/tankers.js @@ -26,6 +26,7 @@ const tankersSchema = new mongoose.Schema({ type: [String], default: [] }, + status: { type: String} }); diff --git a/src/routes/tankersRoute.js b/src/routes/tankersRoute.js index 6cbf5cd4..c5ed7755 100644 --- a/src/routes/tankersRoute.js +++ b/src/routes/tankersRoute.js @@ -33,7 +33,8 @@ module.exports = function (fastify, opts, next) { alternative_phoneNumber: { type: "string"}, typeofwater: { type: "string"}, capacity: { type: "string"}, - price: {type : "string"} + price: {type : "string"}, + status: {type: "string"} }, }, @@ -523,16 +524,30 @@ module.exports = function (fastify, opts, next) { }, ], }, - // preHandler: [ - // fastify.auth([fastify.operatorAuthenticate]), - // validationHandler.validatePhoneFormat, - // ], preHandler: fastify.auth([fastify.authenticate]), handler: tankersController.updatePipelineInfo, }); + + fastify.get("/api/getTanks/status", { + schema: { + tags: ["Supplier"], + description: "This is for Get Tank Data for status connected", + summary: "This is for to Get Tank Data for status connected ", + querystring: { + status: {type: 'string'} + }, + security: [ + { + basicAuth: [], + }, + ], + }, + preHandler: fastify.auth([fastify.authenticate]), + handler: tankersController.status, + }); next(); }