aboutsummaryrefslogtreecommitdiffstats
path: root/lib/utils.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-04-24 22:46:45 -0700
committerAdam Soltys <[email protected]>2020-04-28 22:33:02 -0700
commitfae6e8b55ea12989d688eb777c002222199c169b (patch)
tree3efed4974408fc1bc8911aa9fb9fc657456d69ee /lib/utils.js
parent306357c24d3014b55ae1cd25b954a695ea2e5cc6 (diff)
downloadcoinos-server-fae6e8b55ea12989d688eb777c002222199c169b.tar.gz
coinos-server-fae6e8b55ea12989d688eb777c002222199c169b.zip
improved assets support
Diffstat (limited to 'lib/utils.js')
-rw-r--r--lib/utils.js85
1 files changed, 62 insertions, 23 deletions
diff --git a/lib/utils.js b/lib/utils.js
index 7784ae5c..2f0214d5 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -1,30 +1,69 @@
const { Op } = require("sequelize");
-module.exports = {
- async getUser(username) {
- return db.User.findOne({
- include: [
- {
- model: db.Payment,
- as: "payments",
- order: [["id", "DESC"]],
- where: {
- [Op.or]: {
- received: true,
- amount: {
- [Op.lt]: 0
- }
+getUser = async username => {
+ return db.User.findOne({
+ include: [
+ {
+ model: db.Payment,
+ as: "payments",
+ order: [["id", "DESC"]],
+ where: {
+ [Op.or]: {
+ received: true,
+ amount: {
+ [Op.lt]: 0
}
- },
- limit: 12
+ }
},
- {
+ limit: 12,
+ include: {
model: db.Account,
- as: "accounts"
+ as: "account"
}
- ],
- where:
- { [Op.or]: { username, id: username }}
- });
- }
+ },
+ {
+ model: db.Account,
+ as: "accounts"
+ },
+ {
+ model: db.Account,
+ as: "account"
+ }
+ ],
+ where: { username }
+ });
+};
+
+getUserById = async id => {
+ return 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"
+ },
+ {
+ model: db.Account,
+ as: "account"
+ }
+ ],
+ where: { id }
+ });
};