Przeglądaj źródła

Merge pull request #8802 from overleaf/bg-reset-last-updated-in-migration

[web] reset last updated date in history migration

GitOrigin-RevId: 3d06eadf7d1dfb9b92a529d68de68f59370ab5de
Brian Gough 4 lat temu
rodzic
commit
12bd1d49e7

+ 25 - 1
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