Parcourir la source

fix lint error

ryoji-s il y a 2 ans
Parent
commit
aae50dc34f

+ 2 - 2
apps/app/src/server/models/activity.ts

@@ -1,6 +1,6 @@
 import { Ref, IPage } from '@growi/core';
 import {
-  Types, Document, Model, Schema,
+  Types, Document, Model, Schema, SortOrder,
 } from 'mongoose';
 import mongoosePaginate from 'mongoose-paginate-v2';
 
@@ -119,7 +119,7 @@ activitySchema.statics.updateByParameters = async function(activityId: string, p
 };
 
 activitySchema.statics.findSnapshotUsernamesByUsernameRegexWithTotalCount = async function(
-    q: string, option: { sortOpt: number | string, offset: number, limit: number},
+    q: string, option: { sortOpt: SortOrder, offset: number, limit: number},
 ): Promise<{usernames: string[], totalCount: number}> {
   const opt = option || {};
   const sortOpt = opt.sortOpt || 1;

+ 3 - 3
apps/app/src/server/service/in-app-notification.ts

@@ -2,7 +2,7 @@ import {
   HasObjectId, SubscriptionStatusType, Ref, IPage, IUser,
 } from '@growi/core';
 import { subDays } from 'date-fns';
-import { Types } from 'mongoose';
+import { Types, FilterQuery, UpdateQuery } from 'mongoose';
 
 import { AllEssentialActions, SupportedAction } from '~/interfaces/activity';
 import { InAppNotificationStatuses, PaginateResult } from '~/interfaces/in-app-notification';
@@ -87,10 +87,10 @@ export default class InAppNotificationService {
     const now = createdAt || Date.now();
     const lastWeek = subDays(now, 7);
     const operations = users.map((user) => {
-      const filter = {
+      const filter: FilterQuery<InAppNotificationDocument> = {
         user, target, action, createdAt: { $gt: lastWeek }, snapshot,
       };
-      const parameters = {
+      const parameters: UpdateQuery<InAppNotificationDocument> = {
         user,
         targetModel,
         target,

+ 7 - 7
apps/app/src/server/service/page.ts

@@ -10,7 +10,7 @@ import {
 } from '@growi/core';
 import { collectAncestorPaths } from '@growi/core/dist/utils/page-path-utils/collect-ancestor-paths';
 import escapeStringRegexp from 'escape-string-regexp';
-import mongoose, { ObjectId, QueryCursor } from 'mongoose';
+import mongoose, { ObjectId, Cursor } from 'mongoose';
 import streamToPromise from 'stream-to-promise';
 
 import { SupportedAction } from '~/interfaces/activity';
@@ -60,7 +60,7 @@ class PageCursorsForDescendantsFactory {
 
   private shouldIncludeEmpty: boolean;
 
-  private initialCursor: QueryCursor<any> | never[]; // TODO: wait for mongoose update
+  private initialCursor: Cursor<any> | never[]; // TODO: wait for mongoose update
 
   private Page: PageModel;
 
@@ -100,7 +100,7 @@ class PageCursorsForDescendantsFactory {
   /**
    * Generator that unorderedly yields descendant pages
    */
-  private async* generateOnlyDescendants(cursor: QueryCursor<any>) {
+  private async* generateOnlyDescendants(cursor: Cursor<any>) {
     for await (const page of cursor) {
       const nextCursor = await this.generateCursorToFindChildren(page);
       if (!this.isNeverArray(nextCursor)) {
@@ -111,7 +111,7 @@ class PageCursorsForDescendantsFactory {
     }
   }
 
-  private async generateCursorToFindChildren(page: any): Promise<QueryCursor<any> | never[]> {
+  private async generateCursorToFindChildren(page: any): Promise<Cursor<any> | never[]> {
     if (page == null) {
       return [];
     }
@@ -121,12 +121,12 @@ class PageCursorsForDescendantsFactory {
     const builder = new PageQueryBuilder(this.Page.find(), this.shouldIncludeEmpty);
     builder.addConditionToFilteringByParentId(page._id);
 
-    const cursor = builder.query.lean().cursor({ batchSize: BULK_REINDEX_SIZE }) as QueryCursor<any>;
+    const cursor = builder.query.lean().cursor({ batchSize: BULK_REINDEX_SIZE }) as Cursor<any>;
 
     return cursor;
   }
 
-  private isNeverArray(val: QueryCursor<any> | never[]): val is never[] {
+  private isNeverArray(val: Cursor<any> | never[]): val is never[] {
     return 'length' in val && val.length === 0;
   }
 
@@ -3206,7 +3206,7 @@ class PageService {
   /**
    * Recount descendantCount of pages one by one
    */
-  async recountAndUpdateDescendantCountOfPages(pageCursor: QueryCursor<any>, batchSize:number): Promise<void> {
+  async recountAndUpdateDescendantCountOfPages(pageCursor: Cursor<any>, batchSize:number): Promise<void> {
     const Page = this.crowi.model('Page');
     const recountWriteStream = new Writable({
       objectMode: true,

+ 2 - 1
apps/app/src/server/util/mongoose-utils.ts

@@ -29,7 +29,8 @@ export const getModelSafely = <T>(modelName: string): Model<T & Document> | null
   return null;
 };
 
-export const getOrCreateModel = <Interface, Method>(modelName: string, schema: Schema<Interface>): Method & Model<Interface & Document> => {
+// TODO: Do not use any type
+export const getOrCreateModel = <Interface, Method>(modelName: string, schema: any): any => {
   if (mongoose.modelNames().includes(modelName)) {
     return mongoose.model<Interface & Document, Method & Model<Interface & Document>>(modelName);
   }