diff --git a/src/controllers/createConnectionController.js b/src/controllers/createConnectionController.js index d7d71682..1f282ba5 100644 --- a/src/controllers/createConnectionController.js +++ b/src/controllers/createConnectionController.js @@ -61,6 +61,26 @@ exports.getConnections = async (req, reply) => { throw boom.boomify(err); } }; + + + exports.deleteTankConnections = async (req, reply) => { + try { + const customerId = req.params.customerId; + const tankname = req.query.tankName; + + const tankInfo = await Tank.findOne({ customerId: customerId.toString(),tankName:tankname }) + console.log(tankInfo) + + tankInfo.connections.source = tankInfo.tankName; + tankInfo.connections.inputConnections = []; + tankInfo.connections.outputConnections = []; + const tank_connections = await tankInfo.save(); + return tank_connections; + } catch (err) { + throw boom.boomify(err); + } + }; + diff --git a/src/routes/createConnectionsRoute.js b/src/routes/createConnectionsRoute.js index 5280e075..a938e4a8 100644 --- a/src/routes/createConnectionsRoute.js +++ b/src/routes/createConnectionsRoute.js @@ -145,6 +145,35 @@ module.exports = function (fastify, opts, next) { handler: createConnectionController.getConnections, }); + fastify.route({ + method: "PUT", + url: "/api/deleteTankConnections/:customerId", + schema: { + tags: ["Tank"], + summary: "This is for delete tank connections", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + querystring: { + tankName: {type: 'string'} + }, + security: [ + { + basicAuth: [], + }, + ], + }, + preHandler: fastify.auth([fastify.authenticate]), + handler: createConnectionController.deleteTankConnections, + }); +