aboutsummaryrefslogtreecommitdiffstats
path: root/routes/admin.js
diff options
context:
space:
mode:
authorRanabir Guin <[email protected]>2021-05-14 23:06:03 -0700
committerAdam Soltys <[email protected]>2021-06-09 16:05:31 -0700
commit4f39e4a10804347e89a30201bade1a42e9df0ef0 (patch)
tree51ef1f626674cefa0942cb146a9ac1b79c024b70 /routes/admin.js
parentffc9d98b58e2af91bd9c6b063e6be88663f7b8c7 (diff)
downloadcoinos-server-4f39e4a10804347e89a30201bade1a42e9df0ef0.tar.gz
coinos-server-4f39e4a10804347e89a30201bade1a42e9df0ef0.zip
try join queries; order normalized models to enable HasMany, BelongsTo specs in applicable models (enabling all table specific logic to be in one file)
Diffstat (limited to 'routes/admin.js')
-rw-r--r--routes/admin.js47
1 files changed, 28 insertions, 19 deletions
diff --git a/routes/admin.js b/routes/admin.js
index 0d065a4d..b17e5aa4 100644
--- a/routes/admin.js
+++ b/routes/admin.js
@@ -39,29 +39,38 @@ router.get(
router.get(
"/accounts",
ah(async (req, res) => {
- // var referrals = await db.User
- // .findAll({
- // attributes: ['users.id', 'accounts.balance'],
- // where: {
- // '$accounts.user_id$' : '$users.id$'
- // // user_id: users.id
- // // $or: [
- // // {'$accounts.user_id$' : $users.id$},
- // // ]
- // },
- // include: [
- // {
- // model: Account,
- // required: false
- // }
- // ]
- // });
-
- var accounts = await db.Account.findAll()
+ var accounts = await db.Accounts.findAll({
+ include: [ db.User ]
+ })
debug('accounts: ' + JSON.stringify(accounts))
return res.send({accounts: accounts})
})
);
+// usage: GET '/user/transactions'
+//
+// Returns:
+// { users: [
+// <user attributes>,
+// Invoices:
+// <invoice attributes>,
+// Payments:
+// <invoice attributes>,
+// Orders:
+// <invoice attributes>,
+// ], ...
+// }
+router.get(
+ "/user_transactions",
+ ah(async (req, res) => {
+ var transactions = await db.User.findAll({
+ include: [ db.Invoice, db.Payment, db.Order ]
+ })
+
+ debug('transactions: ' + JSON.stringify(transactions))
+ return res.send({transactions: transactions})
+ })
+);
+
module.exports = router;