From 03ed41c7a9046b34d5f2955ab2819e949f0afe87 Mon Sep 17 00:00:00 2001 From: varun Date: Wed, 8 Feb 2023 01:11:27 -0500 Subject: [PATCH] working on delete bores --- src/controllers/tankersController.js | 30 +++++++++++++++++ src/routes/tankersRoute.js | 49 ++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/src/controllers/tankersController.js b/src/controllers/tankersController.js index f9794c35..d2f46ccd 100644 --- a/src/controllers/tankersController.js +++ b/src/controllers/tankersController.js @@ -216,6 +216,36 @@ exports.addBores = async (req, reply) => { return insertedBore; + } catch (err) { + throw boom.boomify(err); + } +}; + +exports.getBores = async (req, reply) => { + try { + await Bore.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.deleteBoreInfo = async (req, reply) => { + try { + var customerId = req.params.customerId; + var boreName = req.query.boreName; + const Bore = await Tanker.findOneAndDelete({ boreName: boreName,customerId:customerId }); + reply.send({ status_code: 200, data: Bore}); + // return tanker; } catch (err) { throw boom.boomify(err); } diff --git a/src/routes/tankersRoute.js b/src/routes/tankersRoute.js index d4a6d573..41ecef84 100644 --- a/src/routes/tankersRoute.js +++ b/src/routes/tankersRoute.js @@ -200,6 +200,55 @@ module.exports = function (fastify, opts, next) { // }, //onResponse: validationHandler.sendPhoneVerificationCode, }); + + fastify.get("/api/getBores", { + schema: { + tags: ["Supplier"], + description: "This is for Get Bore Data", + summary: "This is for to Get Bore Data", + querystring: { + customerId: {type: 'string'} + }, + security: [ + { + basicAuth: [], + }, + ], + }, + preHandler: fastify.auth([fastify.authenticate]), + handler: tankersController.getBores, + }); + + fastify.route({ + method: "PUT", + url: "/api/deleteBore/:customerId", + schema: { + tags: ["Supplier"], + summary: "This is for delete bore", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + querystring: { + boreName: {type: 'string'} + }, + security: [ + { + basicAuth: [], + }, + ], + }, + preHandler: fastify.auth([fastify.authenticate]), + handler: tankersController.deleteBoreInfo, + }); + +