-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
36 lines (30 loc) · 1.2 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
var express = require('express');
var router = express.Router();
var seneca = require('seneca')();
seneca.use('./microservices');
router.get('/users/list', (req, res) => {
seneca.act({role: 'users', cmd: 'getAllUsers'}, (err, result) => {
if (err) return console.error(err);
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify(result[0], null, 2));
});
});
router.get('/users/:userId', (req, res) => {
seneca.act({role: 'users', cmd: 'getUserById', userId: req.params.userId}, (err, result) => {
if (err) return console.error(err);
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify(result[0], null, 2));
});
});
router.get('/math-party', (req, res) => {
seneca.act({role: 'math', cmd: 'sum', left: 4.5, right: 2.5, integer: true}, (err, result) => {
if (err) return console.error(err);
console.log('add answer ', result.answer);
})
.act({role: 'math', cmd: 'multiply', left: 3, right: 4}, (err, result) => {
if (err) return console.error(err);
console.log('multiply answer ', result.answer);
});
res.send(`Maths have been completed successfully, please check console and celebrate.`);
});
module.exports = router;