-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
celebrations.js
42 lines (40 loc) · 1.37 KB
/
celebrations.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
const UserController = require('../../controller/users'),
Controller = require('../../controller/celebrations'),
{ Celebration, User, Pol } = require('../../models'),
tokenizer = require('../../auth/tokenizer'),
{ STRIPE } = require('../../constants'),
router = require('express').Router();
// All routes prefixed with '/api/celebrations'
router.route('/').post(tokenizer.guard(), async (req, res) => {
req.body.fee =
req.body.donation * STRIPE.FEES.PERCENTAGE + STRIPE.FEES.ADDEND;
let newCelebration = await Controller.create(req, res, Celebration);
if (newCelebration) {
const {
settings: { autoTweet, showToolTips, ...autoEmailsOn },
} = await UserController.contact(req.body.donatedBy, User);
// controls auto-email via user settings
if (autoEmailsOn.emailReceipts)
Controller.receipt(newCelebration, User, Pol);
}
res.json(newCelebration);
});
router
.route('/user/:userId')
.get(tokenizer.guard(), (req, res) =>
Controller.byUserId(req, res, Celebration)
);
router
.route('/escrow')
.get((req, res) => Controller.escrowed(req, res, Celebration));
router
.route('/:celebrationId')
.patch(tokenizer.guard(), (req, res) =>
Controller.resolve(req, res, Celebration)
);
router
.route('/receipt')
.post(tokenizer.guard(), (req, res) =>
res.json(Controller.receipt(req.body, User, Pol))
);
module.exports = router;