-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathgetSingleMsAdmin.js
More file actions
43 lines (39 loc) · 1.11 KB
/
getSingleMsAdmin.js
File metadata and controls
43 lines (39 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const MsAdmin = require("../../models/msadmins");
const CustomError = require("../../utils/customError");
const responseHandler = require("../../utils/responseHandler");
/**
* @author David Okanlawon
*
* Gets single microservice system admin account.
*
* @param {*} req - The request object
* @param {*} res - The response object
* @param {*} next - The function executed to call the next middleware
*/
const getSingleMsAdmin = async (req, res, next) => {
const { msAdminId } = req.params;
//get msAdmin account
try {
const msAdmin = await MsAdmin.findOneWithDeleted({ _id: msAdminId });
if (!msAdmin) {
next(new CustomError(404, "MsAdmin account not found"));
return;
}
const data = {
fullname: msAdmin.fullname,
email: msAdmin.email,
role: msAdmin.role,
isDisabled: msAdmin.deleted || false,
};
return responseHandler(
res,
200,
data,
"MsAdmin account retrieved successfully"
);
} catch (error) {
next(new CustomError(400, "An error occured retrieving msAdmin account"));
return;
}
};
module.exports = getSingleMsAdmin;