diff --git a/libs/prisma/src/executors/prisma.executor.ts b/libs/prisma/src/executors/prisma.executor.ts index 8b74f46..6cd0115 100644 --- a/libs/prisma/src/executors/prisma.executor.ts +++ b/libs/prisma/src/executors/prisma.executor.ts @@ -15,4 +15,10 @@ export class PrismaExecutor { getResult(): any { return this.process.result(); } + + static async default(process: ISkeletonProcess): Promise { + const executor = new PrismaExecutor(process); + await executor.execute(); + return executor.getResult(); + } } diff --git a/libs/prisma/src/prisma-crud.controller.ts b/libs/prisma/src/prisma-crud.controller.ts index eb79123..0781b2c 100644 --- a/libs/prisma/src/prisma-crud.controller.ts +++ b/libs/prisma/src/prisma-crud.controller.ts @@ -3,8 +3,6 @@ import { PrismaExecutor } from './executors/prisma.executor'; export class PrismaCRUDController extends SkeletonCRUDController { async create(): Promise { - const executor = new PrismaExecutor(this.createProcess); - await executor.execute(); - return executor.getResult(); + return await PrismaExecutor.default(this.createProcess); } } diff --git a/libs/prisma/src/processes/create.process.ts b/libs/prisma/src/processes/create.process.ts index c101ffd..59e2180 100644 --- a/libs/prisma/src/processes/create.process.ts +++ b/libs/prisma/src/processes/create.process.ts @@ -1,18 +1,17 @@ import { CreateProcess } from '@autocrud/skeleton/processes/create.process'; -import { Prisma, PrismaClient } from '@prisma/client'; -export abstract class PrismaCreateProcess implements CreateProcess { - constructor(private readonly prisma: PrismaClient) {} +export class PrismaCreateProcess implements CreateProcess { + initialization(); + before(); + begin(); - abstract initialization(): T; - abstract before(): T; - abstract begin(): T; process(): T { this.prisma['asd'].create({ data, }); } - abstract end(): T; - abstract after(): T; - abstract result(): R; + + end(); + after(); + result(); } diff --git a/libs/skeleton/src/executors/default.executor.ts b/libs/skeleton/src/executors/default.executor.ts new file mode 100644 index 0000000..4bf0a45 --- /dev/null +++ b/libs/skeleton/src/executors/default.executor.ts @@ -0,0 +1,24 @@ +import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; + +export class DefaultExecutor { + constructor(private process: ISkeletonProcess) {} + + async execute(): Promise { + this.process.initialization(); + this.process.before(); + this.process.begin(); + this.process.process(); + this.process.end(); + this.process.after(); + } + + getResult(): any { + return this.process.result(); + } + + static async bootstrap(process: ISkeletonProcess): Promise { + const executor = new DefaultExecutor(process); + await executor.execute(); + return executor.getResult(); + } +} diff --git a/libs/skeleton/src/processes/batch/delete.process.ts b/libs/skeleton/src/processes/batch/delete.process.ts index 1f69e53..df98b48 100644 --- a/libs/skeleton/src/processes/batch/delete.process.ts +++ b/libs/skeleton/src/processes/batch/delete.process.ts @@ -1,11 +1,11 @@ import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface'; export abstract class BatchDeleteProcess implements ISkeletonProcess { - abstract initialization(); - abstract before(); - abstract begin(); - abstract process(); - abstract end(); - abstract after(); - abstract result(); + async initialization(): Promise {} + async before(): Promise {} + async begin(): Promise {} + async process(): Promise {} + async end(): Promise {} + async after(): Promise {} + async result(): Promise {} } diff --git a/libs/skeleton/src/processes/batch/update.process.ts b/libs/skeleton/src/processes/batch/update.process.ts index 8c18e20..71c75a3 100644 --- a/libs/skeleton/src/processes/batch/update.process.ts +++ b/libs/skeleton/src/processes/batch/update.process.ts @@ -1,11 +1,11 @@ import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface'; export abstract class BatchUpdateProcess implements ISkeletonProcess { - abstract initialization(); - abstract before(); - abstract begin(); - abstract process(); - abstract end(); - abstract after(); - abstract result(); + async initialization(): Promise {} + async before(): Promise {} + async begin(): Promise {} + async process(): Promise {} + async end(): Promise {} + async after(): Promise {} + async result(): Promise {} } diff --git a/libs/skeleton/src/processes/create.process.ts b/libs/skeleton/src/processes/create.process.ts index 0725033..8705fa1 100644 --- a/libs/skeleton/src/processes/create.process.ts +++ b/libs/skeleton/src/processes/create.process.ts @@ -1,11 +1,11 @@ import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; -export abstract class CreateProcess implements ISkeletonProcess { - abstract initialization(); - abstract before(); - abstract begin(); - abstract process(); - abstract end(); - abstract after(); - abstract result(); +export class CreateProcess implements ISkeletonProcess { + async initialization(): Promise {} + async before(): Promise {} + async begin(): Promise {} + async process(): Promise {} + async end(): Promise {} + async after(): Promise {} + async result(): Promise {} } diff --git a/libs/skeleton/src/processes/delete.process.ts b/libs/skeleton/src/processes/delete.process.ts index e29c66c..9d389b1 100644 --- a/libs/skeleton/src/processes/delete.process.ts +++ b/libs/skeleton/src/processes/delete.process.ts @@ -1,11 +1,11 @@ import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; -export abstract class DeleteProcess implements ISkeletonProcess { - abstract initialization(); - abstract before(); - abstract begin(); - abstract process(); - abstract end(); - abstract after(); - abstract result(); +export class DeleteProcess implements ISkeletonProcess { + async initialization(): Promise {} + async before(): Promise {} + async begin(): Promise {} + async process(): Promise {} + async end(): Promise {} + async after(): Promise {} + async result(): Promise {} } diff --git a/libs/skeleton/src/processes/list.process.ts b/libs/skeleton/src/processes/list.process.ts index 3290bc2..8197ea0 100644 --- a/libs/skeleton/src/processes/list.process.ts +++ b/libs/skeleton/src/processes/list.process.ts @@ -1,11 +1,11 @@ import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; export abstract class ListProcess implements ISkeletonProcess { - abstract initialization(); - abstract before(); - abstract begin(); - abstract process(); - abstract end(); - abstract after(); - abstract result(); + async initialization(): Promise {} + async before(): Promise {} + async begin(): Promise {} + async process(): Promise {} + async end(): Promise {} + async after(): Promise {} + async result(): Promise {} } diff --git a/libs/skeleton/src/processes/pagination.process.ts b/libs/skeleton/src/processes/pagination.process.ts index 77e14ad..a280d1d 100644 --- a/libs/skeleton/src/processes/pagination.process.ts +++ b/libs/skeleton/src/processes/pagination.process.ts @@ -1,11 +1,11 @@ import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; export abstract class PaginationProcess implements ISkeletonProcess { - abstract initialization(); - abstract before(); - abstract begin(); - abstract process(); - abstract end(); - abstract after(); - abstract result(); + async initialization(): Promise {} + async before(): Promise {} + async begin(): Promise {} + async process(): Promise {} + async end(): Promise {} + async after(): Promise {} + async result(): Promise {} } diff --git a/libs/skeleton/src/processes/partial/batch/update.process.ts b/libs/skeleton/src/processes/partial/batch/update.process.ts index 907989d..e24b5a0 100644 --- a/libs/skeleton/src/processes/partial/batch/update.process.ts +++ b/libs/skeleton/src/processes/partial/batch/update.process.ts @@ -1,11 +1,11 @@ import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface'; export abstract class PartialBatchUpdateProcess implements ISkeletonProcess { - abstract initialization(); - abstract before(); - abstract begin(); - abstract process(); - abstract end(); - abstract after(); - abstract result(); + async initialization(): Promise {} + async before(): Promise {} + async begin(): Promise {} + async process(): Promise {} + async end(): Promise {} + async after(): Promise {} + async result(): Promise {} } diff --git a/libs/skeleton/src/processes/partial/update.process.ts b/libs/skeleton/src/processes/partial/update.process.ts index fa0fd6d..176e7ca 100644 --- a/libs/skeleton/src/processes/partial/update.process.ts +++ b/libs/skeleton/src/processes/partial/update.process.ts @@ -1,11 +1,11 @@ import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface'; export abstract class PartialUpdateProcess implements ISkeletonProcess { - abstract initialization(); - abstract before(); - abstract begin(); - abstract process(); - abstract end(); - abstract after(); - abstract result(); + async initialization(): Promise {} + async before(): Promise {} + async begin(): Promise {} + async process(): Promise {} + async end(): Promise {} + async after(): Promise {} + async result(): Promise {} } diff --git a/libs/skeleton/src/processes/read.process.ts b/libs/skeleton/src/processes/read.process.ts index 7929e6f..f0ff422 100644 --- a/libs/skeleton/src/processes/read.process.ts +++ b/libs/skeleton/src/processes/read.process.ts @@ -1,11 +1,11 @@ import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; export abstract class ReadProcess implements ISkeletonProcess { - abstract initialization(); - abstract before(); - abstract begin(); - abstract process(); - abstract end(); - abstract after(); - abstract result(); + async initialization(): Promise {} + async before(): Promise {} + async begin(): Promise {} + async process(): Promise {} + async end(): Promise {} + async after(): Promise {} + async result(): Promise {} } diff --git a/libs/skeleton/src/processes/update.process.ts b/libs/skeleton/src/processes/update.process.ts index 8054483..6ff4a89 100644 --- a/libs/skeleton/src/processes/update.process.ts +++ b/libs/skeleton/src/processes/update.process.ts @@ -1,11 +1,11 @@ import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; -export abstract class UpdateProcess implements ISkeletonProcess { - abstract initialization(); - abstract before(); - abstract begin(); - abstract process(); - abstract end(); - abstract after(); - abstract result(); +export class UpdateProcess implements ISkeletonProcess { + async initialization(): Promise {} + async before(): Promise {} + async begin(): Promise {} + async process(): Promise {} + async end(): Promise {} + async after(): Promise {} + async result(): Promise {} } diff --git a/libs/skeleton/src/skeleton-crud.controller.ts b/libs/skeleton/src/skeleton-crud.controller.ts index c209cfd..51bfa77 100644 --- a/libs/skeleton/src/skeleton-crud.controller.ts +++ b/libs/skeleton/src/skeleton-crud.controller.ts @@ -1,4 +1,5 @@ import { Delete, Get, Param, Patch, Post, Put } from '@nestjs/common'; +import { DefaultExecutor } from './executors/default.executor'; import { ISkeletonCRUDController } from './interfaces/controller/skeleton-crud.controller.interface'; export class SkeletonCRUDController implements ISkeletonCRUDController { @@ -16,52 +17,52 @@ export class SkeletonCRUDController implements ISkeletonCRUDController { ) {} @Post() - async create() { - return this.createProcess.result(); + async create(): Promise { + return await DefaultExecutor.bootstrap(this.createProcess); } @Get(':id') async readSelected(@Param('id') id) { - return this.readProcess.result(); + return await DefaultExecutor.bootstrap(this.readProcess); } @Get() async readPagination() { - return this.readPaginationProcess.result(); + return await DefaultExecutor.bootstrap(this.readPaginationProcess); } @Get('list') async readEntire() { - return this.readEntireProcess.result(); + return await DefaultExecutor.bootstrap(this.readEntireProcess); } @Patch() async updatePartial() { - return this.updatePartialProcess.result(); + return await DefaultExecutor.bootstrap(this.updatePartialProcess); } @Patch('batch') async updatePartialBatch() { - return this.updateBatchProcess.result(); + return await DefaultExecutor.bootstrap(this.updateBatchProcess); } @Put() async updateEntire() { - return this.updateEntireProcess.result(); + return await DefaultExecutor.bootstrap(this.updateEntireProcess); } @Put('batch') async updateEntireBatch() { - return this.updateEntireBatchProcess.result(); + return await DefaultExecutor.bootstrap(this.updateEntireBatchProcess); } @Delete() async deleteSelected() { - return this.deleteProcess.result(); + return await DefaultExecutor.bootstrap(this.deleteProcess); } @Delete('batch') async deleteBatch() { - return this.deleteBatchProcess.result(); + return await DefaultExecutor.bootstrap(this.deleteBatchProcess); } }