-
Notifications
You must be signed in to change notification settings - Fork 3
/
actions.js
43 lines (39 loc) · 835 Bytes
/
actions.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
const uuidv1 = require('uuid/v1');
const { encryptPassword } = require('./bcrypt');
const {
EVENT_NEW_USER,
EVENT_USER_CONFIRMED,
EVENT_SHOPPING_CARD_CREATED,
} = require('./events');
const createUserAction = async (user) => ({
type: EVENT_NEW_USER,
data: {
...user,
password: await encryptPassword(user.password),
uuid: uuidv1(),
confirmed: false,
createdAt: new Date(),
},
});
const confirmUserAction = (uuid) => ({
type: EVENT_USER_CONFIRMED,
data: {
uuid,
confirmedAt: new Date(),
},
});
const createShoppingCardAction = (userId, name) => ({
type: EVENT_SHOPPING_CARD_CREATED,
data: {
name,
uuid: uuidv1(),
userId: userId,
createdAt: new Date(),
items: [],
},
});
module.exports = {
createUserAction,
confirmUserAction,
createShoppingCardAction,
};