changed host name

master
varun 3 years ago
parent d77078a392
commit 45e48c594c

@ -15,7 +15,7 @@ exports.options = {
// We have to change this beacause this is running on local // We have to change this beacause this is running on local
// we have to run on this on swagger // we have to run on this on swagger
// host: "localhost:3000", //Devlopemnt host on lcoal // host: "localhost:3000", //Devlopemnt host on lcoal
host: "localhost:3000", //Production for swagger host: "35.207.198.4:3000", //Production for swagger
schemes: ["http"], schemes: ["http"],
consumes: ["application/json"], consumes: ["application/json"],
produces: ["application/json"], produces: ["application/json"],

@ -1,4 +1,6 @@
const Connections = require("../models/CreateConnections"); const Connections = require("../models/CreateConnections");
const Tank = require("../models/tanks");
const User = require("../models/User"); const User = require("../models/User");
const boom = require("boom"); const boom = require("boom");
const fastify = require("fastify")({ const fastify = require("fastify")({
@ -7,31 +9,41 @@ const fastify = require("fastify")({
// add new tanks // add new tanks
exports.createConnections = async (req, reply) => {
try {
//const username = loginObject.user.username; exports.createConnections = async (req, body) => {
try {
var tankname = req.body.source;
createConnections = { const tankInfo = await Tank.findOne({ tankName: tankname.toString() })
//userName: username, const updateData = req.body;
source: req.body.source, console.log(updateData.inputConnections);
inputConnections: req.body.inputConnections, if (updateData.source) tankInfo.connections.source = updateData.source;
outputConnections:req.body.outputConnections, if (updateData.inputConnections) tankInfo.connections.inputConnections = updateData.inputConnections;
}; if (updateData.outputConnections) tankInfo.connections.outputConnections = updateData.outputConnections;
const tank_connections = await tankInfo.save();
var connections = new Connections(createConnections); return tank_connections;
} catch (err) {
checkFormEncoding = isUserFormUrlEncoded(req); throw boom.boomify(err);
if (checkFormEncoding.isUserFormUrlEncoded) {
usertobeInserted = checkFormEncoding.connections;
connections.source = usertobeInserted.source;
connections.inputConnections = req.body.inputConnections;
connections.outputConnections = req.body.outputConnections;
} }
const insertedConnection = await connections.save(); };
return insertedConnection;
exports.updateconnectionInfo = async (req, reply) => {
try {
//const username = loginObject.user.username;
const tankName = req.params.source;
const tankInfo = await Tank.findOne({ tankName: tankName.toString() })
const updateData = req.body;
if (updateData.source) tankInfo.connections.source = updateData.source;
if (updateData.inputConnections) tankInfo.connections.inputConnections = updateData.inputConnections;
if (updateData.outputConnections) tankInfo.connections.outputConnections = updateData.outputConnections;
const tank_connections = await tankInfo.save();
return tank_connections;
} catch (err) { } catch (err) {
throw boom.boomify(err); throw boom.boomify(err);
} }
}; };

@ -17,7 +17,11 @@ const tanksSchema = new mongoose.Schema({
typeOfWater: { type: String, default: null }, typeOfWater: { type: String, default: null },
type: { type: String, default: null }, type: { type: String, default: null },
tankLocation: { type: String, default: null }, tankLocation: { type: String, default: null },
connections: {
source: { type: String},
inputConnections: [{ inputConnections: String}],
outputConnections: [{ outputConnections: String}]
}
}); });

@ -52,5 +52,67 @@ module.exports = function (fastify, opts, next) {
}); });
fastify.route({
method: "PUT",
url: "/api/updateConnections/:source",
schema: {
tags: ["Connections"],
summary: "This is for update connections",
params: {
required: ["source"],
type: "object",
properties: {
source: {
type: "string",
description: "source",
},
},
},
body: {
type: "object",
// required: ['phone'],
properties: {
source: { type: "string" },
inputConnections: {
type: "array",
maxItems: 2,
items: {
type: "object",
properties: {
inputConnections: { type: "string", default: null },
},
},
},
outputConnections: {
type: "array",
maxItems: 2,
items: {
type: "object",
properties: {
outputConnections: { type: "string", default: null },
},
},
},
},
},
security: [
{
basicAuth: [],
},
],
},
// preHandler: [
// fastify.auth([fastify.operatorAuthenticate]),
// validationHandler.validatePhoneFormat,
// ],
preHandler: fastify.auth([fastify.authenticate]),
handler: createConnectionController.updateconnectionInfo,
});
next(); next();
} }

Loading…
Cancel
Save