mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #16669 from overleaf/dp-decaf
Decaf cleanup of LabelsManager GitOrigin-RevId: 4c261d3fb92cda9f8d493593d7d951ccb3b012ea
This commit is contained in:
parent
f9682f6bb2
commit
285607b185
1 changed files with 40 additions and 58 deletions
|
@ -1,13 +1,3 @@
|
||||||
// TODO: This file was created by bulk-decaffeinate.
|
|
||||||
// Sanity-check the conversion and remove this comment.
|
|
||||||
/*
|
|
||||||
* decaffeinate suggestions:
|
|
||||||
* DS101: Remove unnecessary use of Array.from
|
|
||||||
* DS102: Remove unnecessary code created because of implicit returns
|
|
||||||
* DS201: Simplify complex destructure assignments
|
|
||||||
* DS207: Consider shorter variations of null checks
|
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
||||||
*/
|
|
||||||
import OError from '@overleaf/o-error'
|
import OError from '@overleaf/o-error'
|
||||||
import { db, ObjectId } from './mongodb.js'
|
import { db, ObjectId } from './mongodb.js'
|
||||||
import * as HistoryStoreManager from './HistoryStoreManager.js'
|
import * as HistoryStoreManager from './HistoryStoreManager.js'
|
||||||
|
@ -15,18 +5,18 @@ import * as UpdatesProcessor from './UpdatesProcessor.js'
|
||||||
import * as WebApiManager from './WebApiManager.js'
|
import * as WebApiManager from './WebApiManager.js'
|
||||||
|
|
||||||
export function getLabels(projectId, callback) {
|
export function getLabels(projectId, callback) {
|
||||||
return _toObjectId(projectId, function (error, projectId) {
|
_toObjectId(projectId, function (error, projectId) {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return callback(OError.tag(error))
|
return callback(OError.tag(error))
|
||||||
}
|
}
|
||||||
return db.projectHistoryLabels
|
db.projectHistoryLabels
|
||||||
.find({ project_id: new ObjectId(projectId) })
|
.find({ project_id: new ObjectId(projectId) })
|
||||||
.toArray(function (error, labels) {
|
.toArray(function (error, labels) {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return callback(OError.tag(error))
|
return callback(OError.tag(error))
|
||||||
}
|
}
|
||||||
const formattedLabels = labels.map(_formatLabel)
|
const formattedLabels = labels.map(_formatLabel)
|
||||||
return callback(null, formattedLabels)
|
callback(null, formattedLabels)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -42,22 +32,18 @@ export function createLabel(
|
||||||
) {
|
) {
|
||||||
const validateVersionExists = function (callback) {
|
const validateVersionExists = function (callback) {
|
||||||
if (shouldValidateExists === false) {
|
if (shouldValidateExists === false) {
|
||||||
return callback()
|
callback()
|
||||||
} else {
|
} else {
|
||||||
return _validateChunkExistsForVersion(
|
_validateChunkExistsForVersion(projectId.toString(), version, callback)
|
||||||
projectId.toString(),
|
|
||||||
version,
|
|
||||||
callback
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _toObjectId(projectId, userId, function (error, projectId, userId) {
|
_toObjectId(projectId, userId, function (error, projectId, userId) {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return callback(OError.tag(error))
|
return callback(OError.tag(error))
|
||||||
}
|
}
|
||||||
return validateVersionExists(function (error) {
|
validateVersionExists(function (error) {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return callback(OError.tag(error))
|
return callback(OError.tag(error))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +57,7 @@ export function createLabel(
|
||||||
created_at: createdAt,
|
created_at: createdAt,
|
||||||
}
|
}
|
||||||
db.projectHistoryLabels.insertOne(label, function (error, confirmation) {
|
db.projectHistoryLabels.insertOne(label, function (error, confirmation) {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return callback(OError.tag(error))
|
return callback(OError.tag(error))
|
||||||
}
|
}
|
||||||
label._id = confirmation.insertedId
|
label._id = confirmation.insertedId
|
||||||
|
@ -82,15 +68,15 @@ export function createLabel(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteLabelForUser(projectId, userId, labelId, callback) {
|
export function deleteLabelForUser(projectId, userId, labelId, callback) {
|
||||||
return _toObjectId(
|
_toObjectId(
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
labelId,
|
labelId,
|
||||||
function (error, projectId, userId, labelId) {
|
function (error, projectId, userId, labelId) {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return callback(OError.tag(error))
|
return callback(OError.tag(error))
|
||||||
}
|
}
|
||||||
return db.projectHistoryLabels.deleteOne(
|
db.projectHistoryLabels.deleteOne(
|
||||||
{
|
{
|
||||||
_id: new ObjectId(labelId),
|
_id: new ObjectId(labelId),
|
||||||
project_id: new ObjectId(projectId),
|
project_id: new ObjectId(projectId),
|
||||||
|
@ -103,11 +89,11 @@ export function deleteLabelForUser(projectId, userId, labelId, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteLabel(projectId, labelId, callback) {
|
export function deleteLabel(projectId, labelId, callback) {
|
||||||
return _toObjectId(projectId, labelId, function (error, projectId, labelId) {
|
_toObjectId(projectId, labelId, function (error, projectId, labelId) {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return callback(OError.tag(error))
|
return callback(OError.tag(error))
|
||||||
}
|
}
|
||||||
return db.projectHistoryLabels.deleteOne(
|
db.projectHistoryLabels.deleteOne(
|
||||||
{
|
{
|
||||||
_id: new ObjectId(labelId),
|
_id: new ObjectId(labelId),
|
||||||
project_id: new ObjectId(projectId),
|
project_id: new ObjectId(projectId),
|
||||||
|
@ -118,14 +104,11 @@ export function deleteLabel(projectId, labelId, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function transferLabels(fromUserId, toUserId, callback) {
|
export function transferLabels(fromUserId, toUserId, callback) {
|
||||||
return _toObjectId(
|
_toObjectId(fromUserId, toUserId, function (error, fromUserId, toUserId) {
|
||||||
fromUserId,
|
if (error) {
|
||||||
toUserId,
|
|
||||||
function (error, fromUserId, toUserId) {
|
|
||||||
if (error != null) {
|
|
||||||
return callback(OError.tag(error))
|
return callback(OError.tag(error))
|
||||||
}
|
}
|
||||||
return db.projectHistoryLabels.updateMany(
|
db.projectHistoryLabels.updateMany(
|
||||||
{
|
{
|
||||||
user_id: fromUserId,
|
user_id: fromUserId,
|
||||||
},
|
},
|
||||||
|
@ -134,8 +117,7 @@ export function transferLabels(fromUserId, toUserId, callback) {
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _toObjectId(...args1) {
|
function _toObjectId(...args1) {
|
||||||
|
@ -144,9 +126,9 @@ function _toObjectId(...args1) {
|
||||||
const callback = args1[adjustedLength - 1]
|
const callback = args1[adjustedLength - 1]
|
||||||
try {
|
try {
|
||||||
const ids = args.map(id => new ObjectId(id))
|
const ids = args.map(id => new ObjectId(id))
|
||||||
return callback(null, ...Array.from(ids))
|
callback(null, ...ids)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return callback(error)
|
callback(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,23 +143,23 @@ function _formatLabel(label) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _validateChunkExistsForVersion(projectId, version, callback) {
|
function _validateChunkExistsForVersion(projectId, version, callback) {
|
||||||
return UpdatesProcessor.processUpdatesForProject(projectId, function (error) {
|
UpdatesProcessor.processUpdatesForProject(projectId, function (error) {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
return WebApiManager.getHistoryId(projectId, function (error, historyId) {
|
WebApiManager.getHistoryId(projectId, function (error, historyId) {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
return HistoryStoreManager.getChunkAtVersion(
|
HistoryStoreManager.getChunkAtVersion(
|
||||||
projectId,
|
projectId,
|
||||||
historyId,
|
historyId,
|
||||||
version,
|
version,
|
||||||
function (error) {
|
function (error) {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
return callback()
|
callback()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue