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

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

Loading…
Cancel
Save