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

Implemented PageOperation model

Taichi Masuyama 4 лет назад
Родитель
Сommit
3077893acf

+ 5 - 45
packages/app/src/server/interfaces/page-operation.ts

@@ -15,51 +15,11 @@ export type IPageForResuming = {
   creator?: ObjectIdLike,
 };
 
-/*
- * PageService interfaces
- */
-export type ResumeRenameArgs = { // (page, newPagePath, user, options, shouldUseV4Process, renamedPage, oldPageParentId)
-  page: IPageForResuming, // TODO: improve type
-  newPagePath: string,
-  user: any, // TODO: improve type
-  options: boolean,
-  shouldUseV4Process,
-  renamedPage,
-  oldPageParentId,
-};
-export type ResumeDuplicateArgs = { // (page, newPagePath, user, shouldUseV4Process, createdPageId)
-  page: IPageForResuming,
-  newPagePath: any,
-  user: any,
-  shouldUseV4Process?: boolean,
-  createdPageId,
-};
-export type ResumeDeleteArgs = { // (page, user, shouldUseV4Process)
-  page: IPageForResuming,
-  user: any,
-  shouldUseV4Process?: boolean,
-};
-export type ResumeDeleteCompletelyArgs = { // (page, user, options, shouldUseV4Process)
-  page: IPageForResuming,
-  user: any,
-  options: any,
-  shouldUseV4Process?: boolean,
-};
-export type ResumeRevertArgs = { // (page, user, options, shouldUseV4Process)
-  page: IPageForResuming,
-  user: any,
-  options: any,
-  shouldUseV4Process?: boolean,
+export type IUserForResuming = {
+  _id: ObjectIdLike,
 };
 
-
-export type ResumeNormalizeParentArgs = {
-  a: any,
+export type IOptionsForResuming = {
+  updateMetadata?: boolean,
+  createRedirectPage?: boolean,
 };
-
-export type ResumerArgs = ResumeRenameArgs | ResumeDuplicateArgs | ResumeDeleteArgs | ResumeDeleteCompletelyArgs | ResumeRevertArgs | ResumeNormalizeParentArgs;
-
-
-/*
- * PageOperationService interfaces
- */

+ 24 - 4
packages/app/src/server/models/page-operation.ts

@@ -4,7 +4,7 @@ import mongoose, {
 import { getOrCreateModel } from '@growi/core';
 
 import {
-  IPageForResuming,
+  IPageForResuming, IUserForResuming, IOptionsForResuming,
 } from '~/server/interfaces/page-operation';
 
 type IObjectId = mongoose.Types.ObjectId;
@@ -28,6 +28,11 @@ export interface IPageOperation {
   actionType: PageActionType,
   pathsToBlock: string[],
   page: IPageForResuming,
+  user: IUserForResuming,
+  options?: IOptionsForResuming,
+  newPath?: string,
+  newTarget?: IPageForResuming,
+  incForUpdatingDescendantCount?: number,
 }
 
 export interface PageOperationDocument extends IPageOperation, Document {}
@@ -36,7 +41,8 @@ export interface PageOperationModel extends Model<PageOperationDocument> {
   [x:string]: any // TODO: improve type
 }
 
-const pageArgSchema = new Schema<IPageForResuming>({
+const pageSchemaForResuming = new Schema<IPageForResuming>({
+  _id: { type: ObjectId, ref: 'Page' },
   parent: { type: ObjectId, ref: 'Page' },
   descendantCount: { type: Number },
   isEmpty: { type: Boolean },
@@ -48,7 +54,16 @@ const pageArgSchema = new Schema<IPageForResuming>({
   grantedGroup: { type: ObjectId, ref: 'UserGroup' },
   creator: { type: ObjectId, ref: 'User' },
   lastUpdateUser: { type: ObjectId, ref: 'User' },
-}, { strict: false, strictQuery: false });
+});
+
+const userSchemaForResuming = new Schema<IUserForResuming>({
+  _id: { type: ObjectId, ref: 'User', required: true },
+});
+
+const optionsSchemaForResuming = new Schema<IOptionsForResuming>({
+  createRedirectPage: { type: Boolean },
+  updateMetadata: { type: Boolean },
+}, { _id: false });
 
 const schema = new Schema<PageOperationDocument, PageOperationModel>({
   actionType: {
@@ -64,7 +79,12 @@ const schema = new Schema<PageOperationDocument, PageOperationModel>({
       validate: [v => v.length >= 1, 'Must have minimum one path'],
     },
   ],
-  page: { type: pageArgSchema, required: true },
+  page: { type: pageSchemaForResuming, required: true },
+  user: { type: userSchemaForResuming, required: true },
+  options: { type: optionsSchemaForResuming },
+  newPath: { type: String },
+  newTarget: { type: pageSchemaForResuming },
+  incForUpdatingDescendantCount: { type: Number },
 });
 
 export default getOrCreateModel<PageOperationDocument, PageOperationModel>('PageOperation', schema);

+ 0 - 37
packages/app/src/server/service/page-operation.ts

@@ -1,37 +0,0 @@
-import {
-  ResumeRenameArgs, ResumeDuplicateArgs, ResumeDeleteArgs, ResumeDeleteCompletelyArgs, ResumeRevertArgs,
-  ResumeNormalizeParentArgs, ResumerArgs,
-} from '~/server/interfaces/page-operation';
-import PageService from '~/server/service/page';
-
-// eslint-disable-next-line @typescript-eslint/ban-types
-export type Resumer = [Function, ResumerArgs];
-
-class PageOperationService {
-
-  crowi: any;
-
-  pageService: typeof PageService
-
-  constructor(crowi) {
-    this.crowi = crowi;
-    this.pageService = crowi.pageService;
-  }
-
-  async resumeAll(): Promise<void> {
-    const resumers = await this.prepareResumers();
-
-    await this.processResume(resumers);
-  }
-
-  private async prepareResumers(): Promise<Resumer[]> {
-    return [];
-  }
-
-  private async processResume(resumers: Resumer[]): Promise<void> {
-    return;
-  }
-
-}
-
-export default PageOperationService;