From 369d69d4ae4036dff183704f345c48b2a12dd6a0 Mon Sep 17 00:00:00 2001 From: varun Date: Thu, 9 Feb 2023 00:35:05 -0500 Subject: [PATCH] created get connections and linked connections create and delete with customer id --- src/controllers/createConnectionController.js | 26 +++++++++++++++---- src/controllers/userController.js | 12 ++++----- src/models/CreateConnections.js | 22 ++++++++-------- src/routes/createConnectionsRoute.js | 20 ++++++++++++++ src/routes/usersRoute.js | 4 +-- 5 files changed, 60 insertions(+), 24 deletions(-) diff --git a/src/controllers/createConnectionController.js b/src/controllers/createConnectionController.js index f3e6fc80..e01ff886 100644 --- a/src/controllers/createConnectionController.js +++ b/src/controllers/createConnectionController.js @@ -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); + } + }; + + diff --git a/src/controllers/userController.js b/src/controllers/userController.js index 96863c9f..214d2f49 100644 --- a/src/controllers/userController.js +++ b/src/controllers/userController.js @@ -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, diff --git a/src/models/CreateConnections.js b/src/models/CreateConnections.js index 06d88482..3480d9ed 100644 --- a/src/models/CreateConnections.js +++ b/src/models/CreateConnections.js @@ -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); \ No newline at end of file +//module.exports = mongoose.model("Connections", createConnectionsSchema); \ No newline at end of file diff --git a/src/routes/createConnectionsRoute.js b/src/routes/createConnectionsRoute.js index 3d015b36..ab913111 100644 --- a/src/routes/createConnectionsRoute.js +++ b/src/routes/createConnectionsRoute.js @@ -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(); diff --git a/src/routes/usersRoute.js b/src/routes/usersRoute.js index 11e46b1f..4e80295f 100644 --- a/src/routes/usersRoute.js +++ b/src/routes/usersRoute.js @@ -336,9 +336,9 @@ module.exports = function (fastify, opts, next) { params: { type: "object", properties: { - username: { + customerId: { type: "string", - description: "username", + description: "customerId", }, }, },