forked from juice-shop/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallet.js
28 lines (25 loc) · 866 Bytes
/
wallet.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
/*
* Copyright (c) 2014-2020 Bjoern Kimminich.
* SPDX-License-Identifier: MIT
*/
const models = require('../models/index')
module.exports.getWalletBalance = function getWalletBalance () {
return async (req, res, next) => {
const wallet = await models.Wallet.findOne({ where: { UserId: req.body.UserId } })
if (wallet) {
res.status(200).json({ status: 'success', data: wallet.balance })
} else {
res.status(400).json({ status: 'error' })
}
}
}
module.exports.addWalletBalance = function addWalletBalance () {
return async (req, res, next) => {
const wallet = await models.Wallet.increment({ balance: req.body.balance }, { where: { UserId: req.body.UserId } })
if (wallet) {
res.status(200).json({ status: 'success', data: wallet.balance })
} else {
res.status(400).json({ status: 'error' })
}
}
}