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

[web] reset last updated date in history migration

GitOrigin-RevId: 3d06eadf7d1dfb9b92a529d68de68f59370ab5de
This commit is contained in:
Brian Gough
2022-07-11 09:11:52 +01:00
committed by Copybot
parent d474edd7cd
commit daeb11da46

View File

@@ -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