From af2e8b262a20340f84305957f8c6bb86eb76dd07 Mon Sep 17 00:00:00 2001 From: kaveeshadinamidu Date: Sat, 19 Nov 2022 23:18:13 +0530 Subject: [PATCH] New api added --- src/controllers/userController.js | 6 ++++++ src/repositories/userRepository.js | 18 ++++++++++++++++++ src/services/userService.js | 10 ++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/controllers/userController.js b/src/controllers/userController.js index b3d2087..14ebe77 100644 --- a/src/controllers/userController.js +++ b/src/controllers/userController.js @@ -17,6 +17,12 @@ router.get("/alluser/desktop", authenticateToken, async (req, res) => { res.send(response); }); +router.get("/alluser/details", authenticateToken, async (req, res) => { + const response = await userService.getAllUsersWithDetails(); + res.status(200); + res.send(response); +}); + router.get("/alluser/mobile", authenticateToken, async (req, res) => { const response = await userService.getTotalMobileUserCount(); res.status(200); diff --git a/src/repositories/userRepository.js b/src/repositories/userRepository.js index e847ccc..15f2c34 100644 --- a/src/repositories/userRepository.js +++ b/src/repositories/userRepository.js @@ -1,4 +1,5 @@ const { PrismaClient } = require("@prisma/client"); +const { transformDocument } = require("@prisma/client/runtime"); const prisma = new PrismaClient(); @@ -174,6 +175,22 @@ async function getMobileUserCount() { } } +async function getAllUsersWithDetails() { + try { + const response = await prisma.user.findMany({ + select: { + id: true, + firstName: true, + lastName: true, + email: true, + }, + }); + return response; + } catch (error) { + throw error; + } +} + module.exports = { registerUser, getUser, @@ -188,4 +205,5 @@ module.exports = { getUserById, getDesktopUserCount, getMobileUserCount, + getAllUsersWithDetails, }; diff --git a/src/services/userService.js b/src/services/userService.js index b0f7178..26f13c4 100644 --- a/src/services/userService.js +++ b/src/services/userService.js @@ -227,6 +227,15 @@ async function getTotalMobileUserCount() { } } +async function getAllUsersWithDetails() { + try { + const response = await userRepository.getAllUsersWithDetails(); + return createOutput(200, response); + } catch (error) { + return createOutput(500, "Error in getting all the users"); + } +} + module.exports = { registerUser, logInUser, @@ -239,4 +248,5 @@ module.exports = { changePassword, getTotalUserCount, getTotalMobileUserCount, + getAllUsersWithDetails, };