overleaf/services/track-changes/app/js/UpdateTrimmer.js
Brian Gough 8960e56e20 Merge pull request #9020 from overleaf/bg-decaff-guard
decaff cleanup of __guard__ calls

GitOrigin-RevId: 0d61e4d44a2fda19285674040ba92e500deae78d
2022-07-29 08:03:23 +00:00

67 lines
2.1 KiB
JavaScript

/* eslint-disable
camelcase,
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
*/
let UpdateTrimmer
const MongoManager = require('./MongoManager')
const WebApiManager = require('./WebApiManager')
const logger = require('@overleaf/logger')
module.exports = UpdateTrimmer = {
shouldTrimUpdates(project_id, callback) {
if (callback == null) {
callback = function () {}
}
return MongoManager.getProjectMetaData(
project_id,
function (error, metadata) {
if (error != null) {
return callback(error)
}
if (metadata != null ? metadata.preserveHistory : undefined) {
return callback(null, false)
} else {
return WebApiManager.getProjectDetails(
project_id,
function (error, details) {
if (error != null) {
return callback(error)
}
logger.debug({ project_id, details }, 'got details')
if (details?.features?.versioning) {
return MongoManager.setProjectMetaData(
project_id,
{ preserveHistory: true },
function (error) {
if (error != null) {
return callback(error)
}
return MongoManager.upgradeHistory(
project_id,
function (error) {
if (error != null) {
return callback(error)
}
return callback(null, false)
}
)
}
)
} else {
return callback(null, true)
}
}
)
}
}
)
},
}