Skip to content

Commit

Permalink
Merge pull request #48 from Ninety-Camera/dev
Browse files Browse the repository at this point in the history
New api added
  • Loading branch information
kaveeshadinamidu authored Nov 19, 2022
2 parents 7e1ce36 + af2e8b2 commit d9f1092
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions src/repositories/userRepository.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { PrismaClient } = require("@prisma/client");
const { transformDocument } = require("@prisma/client/runtime");

const prisma = new PrismaClient();

Expand Down Expand Up @@ -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,
Expand All @@ -188,4 +205,5 @@ module.exports = {
getUserById,
getDesktopUserCount,
getMobileUserCount,
getAllUsersWithDetails,
};
10 changes: 10 additions & 0 deletions src/services/userService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -239,4 +248,5 @@ module.exports = {
changePassword,
getTotalUserCount,
getTotalMobileUserCount,
getAllUsersWithDetails,
};

0 comments on commit d9f1092

Please sign in to comment.