aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-11-11 11:56:14 -0800
committerAdam Soltys <[email protected]>2022-11-11 11:56:14 -0800
commit9b4e84941531ba97c3dc836524d1b84ee75ffcaa (patch)
treed658228ec88214b46b7ce3999ec4f9b88a427230
parent34cecd097f152a4816042e790253cc9db62a6ba0 (diff)
downloadcoinos-server-9b4e84941531ba97c3dc836524d1b84ee75ffcaa.tar.gz
coinos-server-9b4e84941531ba97c3dc836524d1b84ee75ffcaa.zip
contacts endpoint
-rw-r--r--routes/payments.js2
-rw-r--r--routes/users.js24
2 files changed, 25 insertions, 1 deletions
diff --git a/routes/payments.js b/routes/payments.js
index dc298c1a..416bc20a 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -126,7 +126,7 @@ app.get("/payments", auth, async (req, res) => {
as: "account"
},
include: {
- attrs: ["username", "profile"],
+ attributes: ["username", "profile"],
model: db.User,
as: "with"
},
diff --git a/routes/users.js b/routes/users.js
index 6181a957..c3ceb35e 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -660,3 +660,27 @@ app.post("/otpsecret", auth, async function(req, res) {
res.code(500).send(e.message);
}
});
+
+app.get("/contacts", auth, async function(req, res) {
+ try {
+ let contacts = await db.Payment.findAll({
+ where: {
+ user_id: req.user.id,
+ with_id: { [Sequelize.Op.ne]: null }
+ },
+ include: {
+ attributes: ["username", "profile"],
+ model: db.User,
+ as: "with"
+ },
+ attributes: ["id"],
+ group: ["with_id"],
+ order: [[{ model: db.User, as: "with" }, "username", "ASC"]]
+ });
+
+ res.send(contacts.map(c => c.with));
+ } catch (e) {
+ console.log(e);
+ res.code(500).send(e.message);
+ }
+});