made changes in create connections

master
varun 3 years ago
parent b096ddce3a
commit cc67a0fef7

@ -12,11 +12,12 @@ const fastify = require("fastify")({
exports.createConnections = async (req, body) => {
try {
var customerId = req.body.source;
const customerId = req.params.customerId;
var tankname = req.body.tankname;
const tankInfo = await Tank.findOne({ customerId: customerId.toString() })
const tankInfo = await Tank.findOne({ customerId: customerId.toString(),tankName:tankname })
const usertobeInserted = req.body;
if (usertobeInserted.source) tankInfo.connections.source = usertobeInserted.source;
tankInfo.connections.source = tankInfo.tankName;
if (usertobeInserted.inputConnections) tankInfo.connections.inputConnections = usertobeInserted.inputConnections;
if (usertobeInserted.outputConnections) tankInfo.connections.outputConnections = usertobeInserted.outputConnections;
const tank_connections = await tankInfo.save();
@ -31,11 +32,12 @@ exports.createConnections = async (req, body) => {
exports.updateconnectionInfo = async (req, reply) => {
try {
//const username = loginObject.user.username;
const customerId = req.params.source;
const tankInfo = await Tank.findOne({ customerId: customerId.toString() })
const tankname = req.body.tankname
const customerId = req.params.customerId;
const tankInfo = await Tank.findOne({ customerId: customerId.toString(),tankName:tankname })
const updateData = req.body;
if (updateData.source) tankInfo.connections.source = updateData.source;
tankInfo.connections.source = tankInfo.tankName;
if (updateData.inputConnections) tankInfo.connections.inputConnections = updateData.inputConnections;
if (updateData.outputConnections) tankInfo.connections.outputConnections = updateData.outputConnections;
const tank_connections = await tankInfo.save();

@ -5,15 +5,25 @@ module.exports = function (fastify, opts, next) {
fastify.route({
method: "POST",
url: "/api/createConnections",
url: "/api/createConnections/:customerId",
schema: {
tags: ["Connections"],
description: "This is for cretae New Connection",
summary: "This is for cretae New Connection.",
params: {
required: ["customerId"],
type: "object",
properties: {
customerId: {
type: "string",
description: "customerId",
},
},
},
body: {
type: "object",
properties: {
source: { type: "string" },
tankname: { type: "string" },
inputConnections: {
type: "array",
maxItems: 2500,
@ -55,25 +65,26 @@ module.exports = function (fastify, opts, next) {
fastify.route({
method: "PUT",
url: "/api/updateConnections/:source",
url: "/api/updateConnections/:customerId",
schema: {
tags: ["Connections"],
summary: "This is for update connections",
params: {
required: ["source"],
required: ["customerId"],
type: "object",
properties: {
source: {
customerId: {
type: "string",
description: "source",
description: "customerId",
},
},
},
body: {
type: "object",
// required: ['phone'],
properties: {
source: { type: "string" },
tankname: { type: "string" },
inputConnections: {
type: "array",
maxItems: 2500,

Loading…
Cancel
Save