From 22f8f0ab141b385519c3c51031387077c60c7693 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 3 Feb 2021 10:18:24 +1100 Subject: [PATCH] Added createdAt and updatedAt to queries --- README.md | 21 +++++++++++++-------- server/news/query.js | 4 ++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 84dac94..7582232 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,13 @@ GET /news/archive/:id //result (if only a single article is specified, returns just that article rather than an array): [ { - "index": index, //absolute index of the result - "title": title, //title of the article - "author": author, //author of the aricle - "body": body, //body of the article - "edits": edits //number of times this article has been edited + "index": index, //absolute index of the result + "title": title, //title of the article + "author": author, //author of the aricle + "body": body, //body of the article + "edits": edits //number of times this article has been edited + "createdAt": createdAt //time created + "updatedAt": updatedAt //time updated }, ... ] @@ -41,9 +43,12 @@ GET /news/archive/titles/:id //result (if only a single article is specified, returns just that article rather than an array): [ { - "index": index, //absolute index of the result - "title": title, //title of the article - "author": author //author of the article + "index": index, //absolute index of the result + "title": title, //title of the article + "author": author //author of the article + "edits": edits //number of times this article has been edited + "createdAt": createdAt //time created + "updatedAt": updatedAt //time updated }, ... ] diff --git a/server/news/query.js b/server/news/query.js index 22cc216..5ecf741 100644 --- a/server/news/query.js +++ b/server/news/query.js @@ -7,7 +7,7 @@ const query = (ascending, titlesOnly) => async (req, res) => { if (req.params.id && typeof(parseInt(req.params.id)) === 'number') { const result = await articles.findOne({ attributes: [ - 'index', 'title', 'author', ...(!titlesOnly ? ['body', 'edits'] : []) + 'index', 'title', 'author', 'edits', 'createdAt', 'updatedAt', ...(!titlesOnly ? ['body'] : []) ], where: { index: { @@ -24,7 +24,7 @@ const query = (ascending, titlesOnly) => async (req, res) => { else { const result = await articles.findAndCountAll({ attributes: [ - 'index', 'title', 'author', ...(!titlesOnly ? ['body', 'edits'] : []) + 'index', 'title', 'author', 'edits', 'createdAt', 'updatedAt', ...(!titlesOnly ? ['body'] : []) ], order: [ ['index', ascending ? 'ASC' : 'DESC']