created get connections and linked connections create and delete with customer id

master
varun 3 years ago
parent b384644672
commit 369d69d4ae

@ -1,4 +1,4 @@
const Connections = require("../models/CreateConnections");
//const Connections = require("../models/CreateConnections");
const Tank = require("../models/tanks");
const User = require("../models/User");
@ -12,9 +12,9 @@ const fastify = require("fastify")({
exports.createConnections = async (req, body) => {
try {
var tankname = req.body.source;
var customerId = req.body.source;
const tankInfo = await Tank.findOne({ tankName: tankname.toString() })
const tankInfo = await Tank.findOne({ customerId: customerId.toString() })
const usertobeInserted = req.body;
if (usertobeInserted.source) tankInfo.connections.source = usertobeInserted.source;
if (usertobeInserted.inputConnections) tankInfo.connections.inputConnections = usertobeInserted.inputConnections;
@ -31,8 +31,8 @@ exports.createConnections = async (req, body) => {
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 customerId = req.params.source;
const tankInfo = await Tank.findOne({ customerId: customerId.toString() })
const updateData = req.body;
if (updateData.source) tankInfo.connections.source = updateData.source;
@ -45,4 +45,20 @@ exports.updateconnectionInfo = async (req, reply) => {
}
};
exports.getConnections = async (req, reply) => {
try {
var connectionsData=await Tank.findOne({customerId: req.query.customerId})
var connection_data = connectionsData.connections
reply.send({ status_code: 200, data: connection_data});
// return tank;
// return tank;
} catch (err) {
throw boom.boomify(err);
}
};

@ -102,8 +102,8 @@ exports.editUserInfo = async (req, body) => {
exports.editCuurentUserInfo = async (req, reply) => {
try {
const { username } = req.params;
const userInfo = await User.findOne({ username: username.toString() });
const { customerId } = req.params;
const userInfo = await User.findOne({ customerId: customerId.toString() });
const updateData = req.body;
if (updateData.firstName) userInfo.profile.firstName = updateData.firstName;
@ -115,15 +115,15 @@ exports.editCuurentUserInfo = async (req, reply) => {
if (updateData.state) userInfo.profile.state = updateData.state;
if (updateData.country) userInfo.profile.country = updateData.country;
if (updateData.zip) userInfo.profile.zip = updateData.zip;
// if (updateData.phone) userInfo.phone = updateData.phone;
if (updateData.phone) userInfo.phone = updateData.phone;
if (updateData.email) userInfo.emails[0].email = updateData.email;
if (updateData.role) userInfo.profile.role = updateData.role;
if (updateData.phone) {
const phoneNumber = libphonenumberjs.parsePhoneNumber(updateData.phone);
const phoneNumber = updateData.phone //libphonenumberjs.parsePhoneNumber(updateData.phone);
if (phoneNumber) {
// access returned collection
if (!phoneNumber.isValid()) {
if (!phoneNumber) { //if (!phoneNumber.isValid()) {
error = {
armintatankdata: {
error: true,

@ -1,20 +1,20 @@
const mongoose = require("mongoose");
//const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const ObjectId = Schema.Types.ObjectId;
//const Schema = mongoose.Schema;
//const ObjectId = Schema.Types.ObjectId;
// Store a random password reset code
const code = Math.floor(100000 + Math.random() * 900000);
const inputSchema = new Schema({ name: String });
const createConnectionsSchema = new mongoose.Schema({
//const code = Math.floor(100000 + Math.random() * 900000);
//const inputSchema = new Schema({ name: String });
//const createConnectionsSchema = new mongoose.Schema({
// userName: { type: String, default: null },
source: { type: String,unique:false,trim: true ,required: true},
inputConnections: [{ inputConnections: String}],
outputConnections: [{ outputConnections: String}]
//source: { type: String,unique:false,trim: true ,required: true},
//inputConnections: [{ inputConnections: String}],
//outputConnections: [{ outputConnections: String}]
});
//});
module.exports = mongoose.model("Connections", createConnectionsSchema);
//module.exports = mongoose.model("Connections", createConnectionsSchema);

@ -112,6 +112,26 @@ module.exports = function (fastify, opts, next) {
fastify.get("/api/getConnections", {
schema: {
tags: ["Connections"],
description: "This is for Get Connections Data",
summary: "This is for to Get Connections Data",
querystring: {
customerId: {type: 'string'}
},
security: [
{
basicAuth: [],
},
],
},
preHandler: fastify.auth([fastify.authenticate]),
handler: createConnectionController.getConnections,
});
next();

@ -336,9 +336,9 @@ module.exports = function (fastify, opts, next) {
params: {
type: "object",
properties: {
username: {
customerId: {
type: "string",
description: "username",
description: "customerId",
},
},
},

Loading…
Cancel
Save