From 435ae846c1ff37fa031e14583175815db16e53a7 Mon Sep 17 00:00:00 2001 From: j-weissen Date: Tue, 27 Sep 2022 08:50:13 +0200 Subject: [PATCH] lasviewed timestamp now set by findOne --- backend/strapi/src/api/note/controllers/note.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/strapi/src/api/note/controllers/note.js b/backend/strapi/src/api/note/controllers/note.js index f54309f..fdc5a92 100644 --- a/backend/strapi/src/api/note/controllers/note.js +++ b/backend/strapi/src/api/note/controllers/note.js @@ -18,7 +18,6 @@ module.exports = createCoreController(noteUid, ({strapi}) => ({ */ async find(ctx) { const userId = ctx.state.user.id; - const entries = await strapi.entityService.findMany(noteUid, { populate: ['owners'], filters: { @@ -33,18 +32,24 @@ module.exports = createCoreController(noteUid, ({strapi}) => ({ return JSON.stringify(entries); }, /** - * Finds the note by id. Exits 403 if the note does not belong to the user making the request + * Finds the note by id and updates lastViewed. Exits 403 if the note does not belong to the user making the request. * @param ctx * @returns {Promise} */ async findOne(ctx) { const noteId = getNoteIdFromUrl(ctx.request.url); const userId = ctx.state.user.id; - const entry = await strapi.entityService.findOne(noteUid, noteId, { + let entry = await strapi.entityService.findOne(noteUid, noteId, { populate: ['owners'], }); const authorized = entry.owners.some(owner => owner.id === userId) + console.log(authorized) if (authorized) { + entry = await strapi.entityService.update(noteUid, noteId, { + data: { + lastViewed: Date.now() + } + }) return JSON.stringify(entry); } else { ctx.response.status = 403;