aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-11-11 14:47:24 -0800
committerAdam Soltys <[email protected]>2022-11-11 14:47:39 -0800
commit3a217080186ecad1878ea3a1af24d17b0beff84c (patch)
tree02bbc35837d1a58d481b81ce9f89ba58c5160097
parentf997db5936742852dcae363921f54cf9244e45e9 (diff)
downloadcoinos-server-3a217080186ecad1878ea3a1af24d17b0beff84c.tar.gz
coinos-server-3a217080186ecad1878ea3a1af24d17b0beff84c.zip
sort contacts
-rw-r--r--routes/users.js13
1 files changed, 10 insertions, 3 deletions
diff --git a/routes/users.js b/routes/users.js
index 319a39c4..02e7e3ed 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -673,12 +673,19 @@ app.get("/contacts", auth, async function(req, res) {
model: db.User,
as: "with"
},
- attributes: ["createdAt"],
+ attributes: [
+ [Sequelize.fn("max", Sequelize.col("payments_model.createdAt")), "last"]
+ ],
group: ["with_id"],
- order: [['createdAt'], [{ model: db.User, as: "with" }, "username", "ASC"]]
+ order: [[{ model: db.User, as: "with" }, "username", "ASC"]]
});
- res.send(contacts.map(c => ({ ...c.with.get({ plain: true }), last: c.createdAt })));
+ res.send(
+ contacts.map(c => {
+ c = c.get({ plain: true });
+ return { ...c.with, last: c.last };
+ })
+ );
} catch (e) {
console.log(e);
res.code(500).send(e.message);