From 30f5aae36719d8d93ae5d0363f03072b92f0baeb Mon Sep 17 00:00:00 2001 From: varun Date: Thu, 9 Feb 2023 02:19:14 -0500 Subject: [PATCH] made changes in user by replacing username by customer id --- src/controllers/userController.js | 7 ++++--- src/routes/usersRoute.js | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/controllers/userController.js b/src/controllers/userController.js index 214d2f49..183736a7 100644 --- a/src/controllers/userController.js +++ b/src/controllers/userController.js @@ -35,7 +35,7 @@ async function bcryptComparePassword(pwd, encpassword) { // Get current users exports.getCurrentUser = async (req, reply) => { try { - const users = await await User.findOne({ username: req.user.username }); + const users = await User.findOne({ customerId: req.body.customerId }); return users; } catch (err) { throw boom.boomify(err); @@ -66,8 +66,8 @@ exports.getUsers = async (req, reply) => { // Get single user by ID exports.getSingleUser = async (req, reply) => { try { - const username = req.params.username; - const user = await User.findOne({ username: username }); + const customerId = req.params.customerId; + const user = await User.findOne({ customerId: customerId }); return user; } catch (err) { throw boom.boomify(err); @@ -78,6 +78,7 @@ exports.getSingleUser = async (req, reply) => { exports.editUserInfo = async (req, body) => { try { const { userId } = req.params; + console.log(customerId) const userInfo = await User.findById(userId); const updateData = req.body; console.log(updateData.firstName); diff --git a/src/routes/usersRoute.js b/src/routes/usersRoute.js index 4e80295f..96bf170b 100644 --- a/src/routes/usersRoute.js +++ b/src/routes/usersRoute.js @@ -20,17 +20,17 @@ module.exports = function (fastify, opts, next) { fastify.route({ method: "POST", - url: "/api/users/:username", + url: "/api/users/:customerId", schema: { - description: "To Get user by username", + description: "To Get user by customerId", tags: ["User"], - summary: "This is for Get a Single User by Username", + summary: "This is for Get a Single User by customerId", params: { type: "object", properties: { - username: { + customerId: { type: "string", - description: "username", + description: "customerId", }, }, }, @@ -49,13 +49,13 @@ module.exports = function (fastify, opts, next) { url: "/api/currentUser", schema: { tags: ["User"], - description: "This is for Get Current User by User Name by Post Body", + description: "This is for Get Current User by customerId by Post Body", summary: "This is for Get a Current User.", body: { type: "object", - required: ["username"], + required: ["customerId"], properties: { - username: { type: "string" }, + customerId: { type: "string" }, }, }, security: [ @@ -87,7 +87,7 @@ module.exports = function (fastify, opts, next) { properties: { userId: { type: "string", - description: "user id", + description: "userId", }, }, }, @@ -115,7 +115,7 @@ module.exports = function (fastify, opts, next) { }, preHandler: [ fastify.auth([fastify.operatorAuthenticate]), - validationHandler.validatePhoneFormat, + //validationHandler.validatePhoneFormat, ], // preHandler: fastify.auth([fastify.authenticate]), handler: userController.editUserInfo, @@ -265,7 +265,7 @@ module.exports = function (fastify, opts, next) { body: { type: "object", properties: { - userId: { type: "string" }, + customerId: { type: "string" }, }, }, security: [ @@ -329,7 +329,7 @@ module.exports = function (fastify, opts, next) { fastify.route({ method: "PUT", - url: "/api/update/currentUser/:username", + url: "/api/update/currentUser/:customerId", schema: { tags: ["User"], summary: "This is for update current user",