diff --git a/services/web/app/src/Features/Project/ProjectHelper.js b/services/web/app/src/Features/Project/ProjectHelper.js index ef2e671e85..ab03600347 100644 --- a/services/web/app/src/Features/Project/ProjectHelper.js +++ b/services/web/app/src/Features/Project/ProjectHelper.js @@ -1,4 +1,4 @@ -// ts-check +// @ts-check const { ObjectId } = require('mongodb-legacy') const _ = require('lodash') const { promisify } = require('util') @@ -33,22 +33,22 @@ function compilerFromV1Engine(engine) { /** @param {MongoProject} project - @param {string} userId + @param {string} rawUserId * @returns {boolean} */ -function isArchived(project, userId) { - userId = new ObjectId(userId) +function isArchived(project, rawUserId) { + const userId = new ObjectId(rawUserId) return (project.archived || []).some(id => id.equals(userId)) } /** * @param {MongoProject} project - * @param {string} userId + * @param {string} rawUserId * @returns {boolean} */ -function isTrashed(project, userId) { - userId = new ObjectId(userId) +function isTrashed(project, rawUserId) { + const userId = new ObjectId(rawUserId) return (project.trashed || []).some(id => id.equals(userId)) } @@ -62,6 +62,12 @@ function isArchivedOrTrashed(project, userId) { return isArchived(project, userId) || isTrashed(project, userId) } +/** + * @param {string[]} nameList + * @param {string} name + * @param {string[]} suffixes + * @param {number} maxLength + */ function ensureNameIsUnique(nameList, name, suffixes, maxLength, callback) { // create a set of all project names if (suffixes == null) { @@ -98,6 +104,11 @@ function _addSuffixToProjectName(name, suffix, maxLength) { return name.substr(0, truncatedLength) + suffix } +/** + * @param {string} name + * @param {Set} allProjectNames + * @param {number} maxLength + */ function _addNumericSuffixToProjectName(name, allProjectNames, maxLength) { const NUMERIC_SUFFIX_MATCH = / \((\d+)\)$/ const suffixedName = function (basename, number) { diff --git a/services/web/app/src/Features/Project/types.d.ts b/services/web/app/src/Features/Project/types.d.ts index c59f55163c..215e03c5f7 100644 --- a/services/web/app/src/Features/Project/types.d.ts +++ b/services/web/app/src/Features/Project/types.d.ts @@ -3,6 +3,7 @@ import { GetProjectsRequestBody, GetProjectsResponseBody, } from '../../../../types/project/dashboard/api' +import { ObjectId } from 'mongodb-legacy' export type GetProjectsRequest = express.Request< unknown, @@ -19,8 +20,8 @@ export type MongoProject = { lastUpdated: Date lastUpdatedBy: string publicAccesLevel: string - archived: string[] - trashed: boolean + archived: ObjectId[] + trashed: ObjectId[] owner_ref: string tokens: { readOnly: string[]