From daeb11da465aae5fd3918c0bd597a075a19521b0 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Mon, 11 Jul 2022 09:11:52 +0100 Subject: [PATCH] Merge pull request #8802 from overleaf/bg-reset-last-updated-in-migration [web] reset last updated date in history migration GitOrigin-RevId: 3d06eadf7d1dfb9b92a529d68de68f59370ab5de --- .../Features/Project/ProjectUpdateHandler.js | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/services/web/app/src/Features/Project/ProjectUpdateHandler.js b/services/web/app/src/Features/Project/ProjectUpdateHandler.js index 80646dbca8..2df473970e 100644 --- a/services/web/app/src/Features/Project/ProjectUpdateHandler.js +++ b/services/web/app/src/Features/Project/ProjectUpdateHandler.js @@ -13,8 +13,9 @@ */ const { Project } = require('../../models/Project') const logger = require('@overleaf/logger') +const { promisifyAll } = require('../../util/promises') -module.exports = { +const ProjectUpdateHandler = { markAsUpdated(projectId, lastUpdatedAt, lastUpdatedBy, callback) { if (callback == null) { callback = function () {} @@ -35,6 +36,26 @@ module.exports = { return Project.updateOne(conditions, update, {}, callback) }, + // like markAsUpdated but allows lastUpdatedAt to be reset to earlier time + resetUpdated(projectId, lastUpdatedAt, lastUpdatedBy, callback) { + if (callback == null) { + callback = function () {} + } + if (lastUpdatedAt == null) { + lastUpdatedAt = new Date() + } + + const conditions = { + _id: projectId, + } + + const update = { + lastUpdated: lastUpdatedAt || new Date().getTime(), + lastUpdatedBy, + } + return Project.updateOne(conditions, update, {}, callback) + }, + markAsOpened(project_id, callback) { const conditions = { _id: project_id } const update = { lastOpened: Date.now() } @@ -65,3 +86,6 @@ module.exports = { }) }, } + +ProjectUpdateHandler.promises = promisifyAll(ProjectUpdateHandler) +module.exports = ProjectUpdateHandler