Skip to content

Commit 9c63cf9

Browse files
committed
challenge #30056080 PREFLIGHT CHECKLIST
1 parent 0fd4a4f commit 9c63cf9

15 files changed

+7215
-13
lines changed

common/Permission.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,35 @@ function providerRoleCheck(req, res, next) {
3737
next();
3838
});
3939
}
40+
/**
41+
* check the user permission
42+
* if user role not pilot, then cannot perform pilot actions
43+
* @param req
44+
* @param res
45+
* @param next
46+
*/
47+
function pilotRoleCheck(req, res, next) {
48+
User.findOne({_id: req.auth.sub}, (err, user) => {
49+
if (!user) {
50+
throw new errors.AuthenticationRequiredError('Anonymous is not allowed to access', 401);
51+
}
52+
53+
if (user.role !== Role.PILOT) {
54+
throw new errors.NotPermittedError('Non-pilot is not allowed to access', 403);
55+
}
56+
req.auth.payload = {
57+
role: Role.PILOT,
58+
};
59+
next();
60+
});
61+
}
4062

4163

4264
module.exports = {
4365
providerRole() {
4466
return providerRoleCheck;
4567
},
68+
pilotRole() {
69+
return pilotRoleCheck;
70+
},
4671
};

controllers/MissionController.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ module.exports = {
2323
getAllByDrone,
2424
download,
2525
remove,
26+
getPilotChecklist,
27+
updatePilotChecklist,
28+
fetchPilotMissions,
2629
};
2730

2831
/**
@@ -98,3 +101,33 @@ function* monthlyCountByDrone(req, res) {
98101
function* getAllByDrone(req, res) {
99102
res.json(yield MissionService.getAllByDrone(req.params.droneId, req.query));
100103
}
104+
105+
/**
106+
* Get a pilot checklist
107+
*
108+
* @param req the request
109+
* @param res the response
110+
*/
111+
function* getPilotChecklist(req, res) {
112+
res.json(yield MissionService.getPilotChecklist(req.params.id, req.auth.sub));
113+
}
114+
115+
/**
116+
* Update a pilot checklist
117+
*
118+
* @param req the request
119+
* @param res the response
120+
*/
121+
function* updatePilotChecklist(req, res) {
122+
res.json(yield MissionService.updatePilotChecklist(req.params.id, req.auth.sub, req.body));
123+
}
124+
125+
/**
126+
* Fetch pilot mission list
127+
*
128+
* @param req the request
129+
* @param res the response
130+
*/
131+
function* fetchPilotMissions(req, res) {
132+
res.json(yield MissionService.fetchPilotMissions(req.auth.sub, req.query));
133+
}

0 commit comments

Comments
 (0)