From c8c2b9df1c9f70a95673f436b7f1e14964a6744e Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 13 Apr 2020 19:59:16 -0700 Subject: getuser utility function --- lib/utils.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lib/utils.js (limited to 'lib/utils.js') diff --git a/lib/utils.js b/lib/utils.js new file mode 100644 index 00000000..c6e02a1a --- /dev/null +++ b/lib/utils.js @@ -0,0 +1,29 @@ +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 + } + } + }, + limit: 12 + }, + { + model: db.Account, + as: "accounts" + } + ], + where: { username } + }); + } +}; -- cgit v1.2.3