-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusersMilestones.controller.js
More file actions
40 lines (36 loc) · 1.44 KB
/
usersMilestones.controller.js
File metadata and controls
40 lines (36 loc) · 1.44 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
const usersMilestonesService = require('../services/usersMilestonesService');
const responses = require('../models/responses/index');
const mentorsClientListService = require('../services/mentorsClientList.service');
const types = require('../enums/userTypes')
const readByUserIdAndMentorId = (req, res) => {
const userId = req.params.userId;
const mentorId = req.params.mentorId;
const typeId = req.auth.roles
const authId = req.auth.id
if ((parseInt(mentorId) !== authId) || (typeId !== types.MENTOR)) {
res.status(401).send('')
} else {
const promise = mentorsClientListService.readByMentorId(mentorId)
promise
.then(response => {
const responseArr = response.some(e => e.userId === parseInt(userId))
if (responseArr === true) {
const promise = usersMilestonesService.readByUserIdAndMentorId(userId, mentorId)
return promise
}
})
.then(response => {
const responseObj = new responses.ItemsResponse()
responseObj.items = response;
res.status(200).json(responseObj)
})
.catch(err => {
const responseObj = new responses.ErrorResponse()
responseObj.error = err.stack;
res.status(500).send(responseObj);
})
}
}
module.exports = {
readByUserIdAndMentorId
}