-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
77 lines (71 loc) · 2.25 KB
/
api.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
module.exports = function api(options) {
// Traite les requetes GET pour l'affichage des stats
this.add('role:api,path:stats', function(msg, respond) {
this.act('role:stats', {
cmd: msg.request$.method,
user: msg.args.params.user
}, respond)
});
// Traite les requetes GET pour la recherche
this.add('role:api,path:search', function(msg, respond) {
this.act('role:indexation', {
cmd: msg.request$.method,
work: msg.args.params.work
}, respond)
});
// Traite les operations CRUD pour la gestion des DT
this.add('role:api,path:dt', function (msg, respond) {
var data = msg.args.body;
var params = msg.args.params;
this.act('role:dt', {
cmd: msg.request$.method,
data: {
applicant: data.applicant,
work: data.work,
state: data.state,
date: data.date,
id: params.id
}
}, respond)
});
// Definition des routes du service web
this.add('init:api', function(msg, respond) {
this.act('role:web', {
routes: [
{
prefix: '/api/dt',
pin: 'role:api,path:stats',
map: {
stats: {
GET: true,
suffix: '/:user?'
}
}
},
{
prefix: '/api/dt',
pin: 'role:api,path:search',
map: {
search: {
GET: true,
suffix: '/:work'
}
}
},
{
prefix: '/api',
pin: 'role:api,path:dt',
map: {
dt: {
GET: true,
POST: true,
PUT: true,
DELETE: true,
suffix: '/:id?'
}
}
}
]
}, respond)
})
}