Просмотр исходного кода

Merge pull request #28301 from overleaf/ar-fix-tscheck-on-project-helper

[web] Add @ to ts-check annotation in ProjectHelper

GitOrigin-RevId: 3db97fff7e8059f2940b9f446c95ead187d950b2
Andrew Rumble 1 год назад
Родитель
Сommit
b4d8ab2d71

+ 18 - 7
services/web/app/src/Features/Project/ProjectHelper.js

@@ -1,4 +1,4 @@
-// ts-check
+// @ts-check
 const { ObjectId } = require('mongodb-legacy')
 const { ObjectId } = require('mongodb-legacy')
 const _ = require('lodash')
 const _ = require('lodash')
 const { promisify } = require('util')
 const { promisify } = require('util')
@@ -33,22 +33,22 @@ function compilerFromV1Engine(engine) {
 
 
 /**
 /**
  @param {MongoProject} project
  @param {MongoProject} project
- @param {string} userId
+ @param {string} rawUserId
  * @returns {boolean}
  * @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))
   return (project.archived || []).some(id => id.equals(userId))
 }
 }
 
 
 /**
 /**
  * @param {MongoProject} project
  * @param {MongoProject} project
- * @param {string} userId
+ * @param {string} rawUserId
  * @returns {boolean}
  * @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))
   return (project.trashed || []).some(id => id.equals(userId))
 }
 }
@@ -62,6 +62,12 @@ function isArchivedOrTrashed(project, userId) {
   return isArchived(project, userId) || isTrashed(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) {
 function ensureNameIsUnique(nameList, name, suffixes, maxLength, callback) {
   // create a set of all project names
   // create a set of all project names
   if (suffixes == null) {
   if (suffixes == null) {
@@ -98,6 +104,11 @@ function _addSuffixToProjectName(name, suffix, maxLength) {
   return name.substr(0, truncatedLength) + suffix
   return name.substr(0, truncatedLength) + suffix
 }
 }
 
 
+/**
+ * @param {string} name
+ * @param {Set<string>} allProjectNames
+ * @param {number} maxLength
+ */
 function _addNumericSuffixToProjectName(name, allProjectNames, maxLength) {
 function _addNumericSuffixToProjectName(name, allProjectNames, maxLength) {
   const NUMERIC_SUFFIX_MATCH = / \((\d+)\)$/
   const NUMERIC_SUFFIX_MATCH = / \((\d+)\)$/
   const suffixedName = function (basename, number) {
   const suffixedName = function (basename, number) {

+ 3 - 2
services/web/app/src/Features/Project/types.d.ts

@@ -3,6 +3,7 @@ import {
   GetProjectsRequestBody,
   GetProjectsRequestBody,
   GetProjectsResponseBody,
   GetProjectsResponseBody,
 } from '../../../../types/project/dashboard/api'
 } from '../../../../types/project/dashboard/api'
+import { ObjectId } from 'mongodb-legacy'
 
 
 export type GetProjectsRequest = express.Request<
 export type GetProjectsRequest = express.Request<
   unknown,
   unknown,
@@ -19,8 +20,8 @@ export type MongoProject = {
   lastUpdated: Date
   lastUpdated: Date
   lastUpdatedBy: string
   lastUpdatedBy: string
   publicAccesLevel: string
   publicAccesLevel: string
-  archived: string[]
-  trashed: boolean
+  archived: ObjectId[]
+  trashed: ObjectId[]
   owner_ref: string
   owner_ref: string
   tokens: {
   tokens: {
     readOnly: string[]
     readOnly: string[]