-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreducers.js
33 lines (31 loc) · 917 Bytes
/
reducers.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
var moment = require('moment');
var db = require('./model/db.js');
var error = require('./errors/error.js');
function dealAction(state, action) {
switch (action.type) {
case 'ADD_MESSAGE':
db.megBoard.put({
_id: new Date().toISOString(),
email: action.email,
content: action.content,
pubDate: moment(new Date().getTime()).format('YYYY-MM-DD h:mm:ss')
}).catch(function (err) {
errors.dbError(err);
});
return state;
case 'ADD_MESSAGE_REPLAY':
db.comment.put({
_id: new Date().toISOString(),
email: action.email,
content: action.content,
pubDate: moment(new Date().getTime()).format('YYYY-MM-DD h:mm:ss'),
replayId: action.replayId
}).catch(function (err) {
errors.dbError(err);
});
return state;
default:
return state;
}
}
module.exports = dealAction;