made changes in user by replacing username by customer id

master
varun 3 years ago
parent 369d69d4ae
commit 30f5aae367

@ -35,7 +35,7 @@ async function bcryptComparePassword(pwd, encpassword) {
// Get current users // Get current users
exports.getCurrentUser = async (req, reply) => { exports.getCurrentUser = async (req, reply) => {
try { try {
const users = await await User.findOne({ username: req.user.username }); const users = await User.findOne({ customerId: req.body.customerId });
return users; return users;
} catch (err) { } catch (err) {
throw boom.boomify(err); throw boom.boomify(err);
@ -66,8 +66,8 @@ exports.getUsers = async (req, reply) => {
// Get single user by ID // Get single user by ID
exports.getSingleUser = async (req, reply) => { exports.getSingleUser = async (req, reply) => {
try { try {
const username = req.params.username; const customerId = req.params.customerId;
const user = await User.findOne({ username: username }); const user = await User.findOne({ customerId: customerId });
return user; return user;
} catch (err) { } catch (err) {
throw boom.boomify(err); throw boom.boomify(err);
@ -78,6 +78,7 @@ exports.getSingleUser = async (req, reply) => {
exports.editUserInfo = async (req, body) => { exports.editUserInfo = async (req, body) => {
try { try {
const { userId } = req.params; const { userId } = req.params;
console.log(customerId)
const userInfo = await User.findById(userId); const userInfo = await User.findById(userId);
const updateData = req.body; const updateData = req.body;
console.log(updateData.firstName); console.log(updateData.firstName);

@ -20,17 +20,17 @@ module.exports = function (fastify, opts, next) {
fastify.route({ fastify.route({
method: "POST", method: "POST",
url: "/api/users/:username", url: "/api/users/:customerId",
schema: { schema: {
description: "To Get user by username", description: "To Get user by customerId",
tags: ["User"], tags: ["User"],
summary: "This is for Get a Single User by Username", summary: "This is for Get a Single User by customerId",
params: { params: {
type: "object", type: "object",
properties: { properties: {
username: { customerId: {
type: "string", type: "string",
description: "username", description: "customerId",
}, },
}, },
}, },
@ -49,13 +49,13 @@ module.exports = function (fastify, opts, next) {
url: "/api/currentUser", url: "/api/currentUser",
schema: { schema: {
tags: ["User"], 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.", summary: "This is for Get a Current User.",
body: { body: {
type: "object", type: "object",
required: ["username"], required: ["customerId"],
properties: { properties: {
username: { type: "string" }, customerId: { type: "string" },
}, },
}, },
security: [ security: [
@ -87,7 +87,7 @@ module.exports = function (fastify, opts, next) {
properties: { properties: {
userId: { userId: {
type: "string", type: "string",
description: "user id", description: "userId",
}, },
}, },
}, },
@ -115,7 +115,7 @@ module.exports = function (fastify, opts, next) {
}, },
preHandler: [ preHandler: [
fastify.auth([fastify.operatorAuthenticate]), fastify.auth([fastify.operatorAuthenticate]),
validationHandler.validatePhoneFormat, //validationHandler.validatePhoneFormat,
], ],
// preHandler: fastify.auth([fastify.authenticate]), // preHandler: fastify.auth([fastify.authenticate]),
handler: userController.editUserInfo, handler: userController.editUserInfo,
@ -265,7 +265,7 @@ module.exports = function (fastify, opts, next) {
body: { body: {
type: "object", type: "object",
properties: { properties: {
userId: { type: "string" }, customerId: { type: "string" },
}, },
}, },
security: [ security: [
@ -329,7 +329,7 @@ module.exports = function (fastify, opts, next) {
fastify.route({ fastify.route({
method: "PUT", method: "PUT",
url: "/api/update/currentUser/:username", url: "/api/update/currentUser/:customerId",
schema: { schema: {
tags: ["User"], tags: ["User"],
summary: "This is for update current user", summary: "This is for update current user",

Loading…
Cancel
Save