2019-05-29 05:21:06 -04:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
2022-05-16 10:25:49 -04:00
|
|
|
n/handle-callback-err,
|
2019-05-29 05:21:06 -04:00
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
const { Project } = require('../../models/Project')
|
2021-11-10 08:40:18 -05:00
|
|
|
const logger = require('@overleaf/logger')
|
2022-07-11 04:11:52 -04:00
|
|
|
const { promisifyAll } = require('../../util/promises')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2022-07-11 04:11:52 -04:00
|
|
|
const ProjectUpdateHandler = {
|
2019-05-29 05:21:06 -04:00
|
|
|
markAsUpdated(projectId, lastUpdatedAt, lastUpdatedBy, callback) {
|
|
|
|
if (callback == null) {
|
2021-04-14 09:17:21 -04:00
|
|
|
callback = function () {}
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
if (lastUpdatedAt == null) {
|
|
|
|
lastUpdatedAt = new Date()
|
|
|
|
}
|
|
|
|
|
|
|
|
const conditions = {
|
|
|
|
_id: projectId,
|
2021-04-27 03:52:58 -04:00
|
|
|
lastUpdated: { $lt: lastUpdatedAt },
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const update = {
|
|
|
|
lastUpdated: lastUpdatedAt || new Date().getTime(),
|
2021-04-27 03:52:58 -04:00
|
|
|
lastUpdatedBy,
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2020-11-03 04:19:05 -05:00
|
|
|
return Project.updateOne(conditions, update, {}, callback)
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
|
2022-07-11 04:11:52 -04:00
|
|
|
// 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)
|
|
|
|
},
|
|
|
|
|
2019-05-29 05:21:06 -04:00
|
|
|
markAsOpened(project_id, callback) {
|
|
|
|
const conditions = { _id: project_id }
|
|
|
|
const update = { lastOpened: Date.now() }
|
2021-04-14 09:17:21 -04:00
|
|
|
return Project.updateOne(conditions, update, {}, function (err) {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (callback != null) {
|
|
|
|
return callback()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
markAsInactive(project_id, callback) {
|
|
|
|
const conditions = { _id: project_id }
|
|
|
|
const update = { active: false }
|
2021-04-14 09:17:21 -04:00
|
|
|
return Project.updateOne(conditions, update, {}, function (err) {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (callback != null) {
|
|
|
|
return callback()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
markAsActive(project_id, callback) {
|
|
|
|
const conditions = { _id: project_id }
|
|
|
|
const update = { active: true }
|
2021-04-14 09:17:21 -04:00
|
|
|
return Project.updateOne(conditions, update, {}, function (err) {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (callback != null) {
|
|
|
|
return callback()
|
|
|
|
}
|
|
|
|
})
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2022-07-11 04:11:52 -04:00
|
|
|
|
|
|
|
ProjectUpdateHandler.promises = promisifyAll(ProjectUpdateHandler)
|
|
|
|
module.exports = ProjectUpdateHandler
|