From f997db5936742852dcae363921f54cf9244e45e9 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 11 Nov 2022 12:28:55 -0800 Subject: order contacts --- routes/users.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'routes') diff --git a/routes/users.js b/routes/users.js index c3ceb35e..319a39c4 100644 --- a/routes/users.js +++ b/routes/users.js @@ -673,12 +673,12 @@ app.get("/contacts", auth, async function(req, res) { model: db.User, as: "with" }, - attributes: ["id"], + attributes: ["createdAt"], group: ["with_id"], - order: [[{ model: db.User, as: "with" }, "username", "ASC"]] + order: [['createdAt'], [{ model: db.User, as: "with" }, "username", "ASC"]] }); - res.send(contacts.map(c => c.with)); + res.send(contacts.map(c => ({ ...c.with.get({ plain: true }), last: c.createdAt }))); } catch (e) { console.log(e); res.code(500).send(e.message); -- cgit v1.2.3