aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--db/index.js44
-rw-r--r--routes/admin.js47
2 files changed, 54 insertions, 37 deletions
diff --git a/db/index.js b/db/index.js
index 37394ecf..658a51a0 100644
--- a/db/index.js
+++ b/db/index.js
@@ -21,22 +21,29 @@ require("./models/orders.js");
require("./models/users.js");
require("./models/withdrawals.js");
-// require("./normalized/accounts.js");
+// Require models in order (to enable FK relationship specs in models)
+
+// require("./normalized/users.js");
+// require("./normalized/user_keys.js");
+// require("./normalized/user_preferences.js");
+
+require("./normalized/referrals.js");
+require("./normalized/waiting_list.js");
+
+// require("./normalized/subscriptions.js");
+// require("./normalized/user_subscriptions.js");
+
// require("./normalized/assets.js");
// require("./normalized/codes.js");
// require("./normalized/currencies.js");
-// require("./normalized/deposits.js");
-// require("./normalized/institutions.js");
// require("./normalized/networks.js");
+// require("./normalized/institutions.js");
+
+// require("./normalized/accounts.js");
// require("./normalized/non_custodial_accounts.js");
-// require("./normalized/payments.js");
-require("./normalized/referrals.js");
-// require("./normalized/user_keys.js");
-// require("./normalized/user_preferences.js");
-// require("./normalized/user_subscriptions.js");
-// require("./normalized/users.js");
-require("./normalized/waiting_list.js");
+// require("./normalized/deposits.js");
// require("./normalized/withdrawals.js");
+// require("./normalized/payments.js");
// ** Need to add ? ***
// require("./normalized/orders.js");
@@ -44,10 +51,11 @@ require("./normalized/waiting_list.js");
const { User, Account, Payment, Invoice, Key, Order } = db;
-User.hasMany(Account, {
- as: "accounts",
- foreignKey: "user_id"
-});
+// move relationships to specfic models
+// User.hasMany(Account, {
+// as: "accounts",
+// foreignKey: "user_id"
+// });
User.hasMany(Invoice, {
as: "invoices",
@@ -74,10 +82,10 @@ Invoice.belongsTo(Account, {
foreignKey: "account_id"
});
-Account.belongsTo(User, {
- as: "user",
- foreignKey: "user_id"
-});
+// Account.belongsTo(User, {
+// as: "user",
+// foreignKey: "user_id"
+// });
Invoice.belongsTo(User, {
as: "user",
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;