diff options
| author | Adam Soltys <[email protected]> | 2020-04-27 11:14:43 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-04-28 22:33:02 -0700 |
| commit | e166ab2c743e4c66eacb51c6484711c5965dd090 (patch) | |
| tree | a3b309cb38ceceb6e581963f0001a6869452b531 /lib/utils.js | |
| parent | fae6e8b55ea12989d688eb777c002222199c169b (diff) | |
| download | coinos-server-e166ab2c743e4c66eacb51c6484711c5965dd090.tar.gz coinos-server-e166ab2c743e4c66eacb51c6484711c5965dd090.zip | |
select payments from current account
Diffstat (limited to 'lib/utils.js')
| -rw-r--r-- | lib/utils.js | 81 |
1 files changed, 42 insertions, 39 deletions
diff --git a/lib/utils.js b/lib/utils.js index 2f0214d5..58bf29f9 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,27 +1,10 @@ -const { Op } = require("sequelize"); +const sequelize = require("sequelize"); +const { Op } = sequelize; getUser = async username => { - return db.User.findOne({ + let user = await db.User.findOne({ include: [ { - model: db.Payment, - as: "payments", - order: [["id", "DESC"]], - where: { - [Op.or]: { - received: true, - amount: { - [Op.lt]: 0 - } - } - }, - limit: 12, - include: { - model: db.Account, - as: "account" - } - }, - { model: db.Account, as: "accounts" }, @@ -32,30 +15,31 @@ getUser = async username => { ], where: { username } }); + + user = user.get({ plain: true }); + + user.payments = await db.Payment.findAll({ + order: [["id", "DESC"]], + where: { + user_id: user.id, + account_id: user.account.id, + [Op.or]: { + received: true, + amount: { + [Op.lt]: 0 + } + } + }, + limit: 12 + }); + + return user; }; getUserById = async id => { - return db.User.findOne({ + let user = db.User.findOne({ include: [ { - model: db.Payment, - as: "payments", - order: [["id", "DESC"]], - where: { - [Op.or]: { - received: true, - amount: { - [Op.lt]: 0 - } - } - }, - limit: 12, - include: { - model: db.Account, - as: "account" - } - }, - { model: db.Account, as: "accounts" }, @@ -66,4 +50,23 @@ getUserById = async id => { ], where: { id } }); + + user = user.get({ plain: true }); + + user.payments = await db.Payment.findAll({ + order: [["id", "DESC"]], + where: { + user_id: user.id, + account_id: user.account.id, + [Op.or]: { + received: true, + amount: { + [Op.lt]: 0 + } + } + }, + limit: 12 + }); + + return user; }; |
