From e3fb4236bea028a3d54bddc852b1f233e49baf84 Mon Sep 17 00:00:00 2001 From: Andrew Rumble Date: Mon, 8 Sep 2025 09:52:49 +0100 Subject: [PATCH] Merge pull request #28301 from overleaf/ar-fix-tscheck-on-project-helper [web] Add @ to ts-check annotation in ProjectHelper GitOrigin-RevId: 3db97fff7e8059f2940b9f446c95ead187d950b2 --- .../app/src/Features/Project/ProjectHelper.js | 25 +++++++++++++------ .../web/app/src/Features/Project/types.d.ts | 5 ++-- 2 files changed, 21 insertions(+), 9 deletions(-) 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[]