-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
56 lines (51 loc) · 1.09 KB
/
index.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
import UserStore from './UserStore'
const Hp = require('hemera-plugin')
export default Hp(
async function userStorePlugin(hemera) {
const Joi = hemera.joi
const topic = 'user'
const store = new UserStore()
hemera.add(
{
topic,
cmd: 'getUserById',
id: Joi.number().required()
},
function getUserById(req, reply) {
reply(null, store.getUserById(req.id))
}
)
hemera.add(
{
topic,
cmd: 'getUserByEmail',
email: Joi.string()
.email()
.required()
},
function getUserByEmail(req, reply) {
reply(null, store.getUserByEmail(req.email))
}
)
hemera.add(
{
topic,
cmd: 'createUser',
user: Joi.object().keys({
name: Joi.string().required(),
email: Joi.string()
.email()
.required()
})
},
function createUser(req, reply) {
reply(null, store.createUser(req.user))
}
)
},
{
name: 'myUserStore',
options: {},
dependencies: []
}
)