-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathgetSingleApplication.js
More file actions
60 lines (54 loc) · 1.75 KB
/
getSingleApplication.js
File metadata and controls
60 lines (54 loc) · 1.75 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const Applications = require("../../../models/applications");
const MsAdmin = require("../../../models/msadmins");
// const CommentModel = require("../../../models/comments");
const CustomError = require("../../../utils/customError");
const responseHandler = require("../../../utils/responseHandler");
/**
* @author Ekeyekwu Oscar
*
* Gets all applications using the microservice.
*
* @param {*} req - The request object
* @param {*} res - The response object
* @param {*} next - The function executed to call the next middleware
*/
const getSingleApplication = async (req, res, next) => {
//get msAdminId from token
const { msAdminId } = req.token;
const { applicationId } = req.params;
//get single application, map field names appropriately
let application;
try {
//check if msAdmin exists
const msAdmin = await MsAdmin.findById(msAdminId);
if (!msAdmin) {
next(new CustomError(404, "MsAdmin account not found"));
return;
}
//get applications
const singleApplication = await Applications.findOneWithDeleted({
_id: applicationId,
}).populate("organizationId");
if (!singleApplication) {
next(new CustomError(404, "Application not Found"));
return;
}
application = {
applicationId: singleApplication._id,
applicationName: singleApplication.name,
organizationId: singleApplication.organizationId,
organizationName: singleApplication.organizationId.name,
isBlocked: singleApplication.deleted || false,
};
} catch (error) {
next(new CustomError(400, "An error occured retrieving Application"));
return;
}
return responseHandler(
res,
200,
application,
"Application retrieved successfully"
);
};
module.exports = getSingleApplication;