-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathroutes.js
51 lines (43 loc) · 1.17 KB
/
routes.js
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
const express = require('express');
const passport = require('passport');
const MessagesService = require('./messagesService');
// strategy JWT
require('../../utils/auth/strategies/jwt');
function messagesApi(app) {
const router = express.Router();
app.use('/api/messages', router);
const messagesService = new MessagesService();
router.get(
'/',
passport.authenticate('jwt', { session: false }),
async function (req, res, next) {
const { patientId } = req.query;
try {
const messages = await messagesService.getMessages(patientId);
res.status(200).json({
data: messages,
message: 'Messages retrieved',
});
} catch (err) {
next(err);
}
}
);
router.post(
'/',
passport.authenticate('jwt', { session: false }),
async function (req, res, next) {
const message = req.body;
try {
const createUserId = await messagesService.createMessages(message);
res.status(201).json({
data: createUserId,
message: 'Message created',
});
} catch (error) {
next(error);
}
}
);
}
module.exports = messagesApi;