wip: implementing executor

This commit is contained in:
Supan Adit Pratama 2024-10-26 23:34:11 +07:00
parent b15a07d16a
commit ff07bd1ec3
15 changed files with 124 additions and 96 deletions

View File

@ -15,4 +15,10 @@ export class PrismaExecutor {
getResult(): any {
return this.process.result();
}
static async default(process: ISkeletonProcess): Promise<any> {
const executor = new PrismaExecutor(process);
await executor.execute();
return executor.getResult();
}
}

View File

@ -3,8 +3,6 @@ import { PrismaExecutor } from './executors/prisma.executor';
export class PrismaCRUDController extends SkeletonCRUDController {
async create(): Promise<any> {
const executor = new PrismaExecutor(this.createProcess);
await executor.execute();
return executor.getResult();
return await PrismaExecutor.default(this.createProcess);
}
}

View File

@ -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();
}

View File

@ -0,0 +1,24 @@
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
export class DefaultExecutor {
constructor(private process: ISkeletonProcess) {}
async execute(): Promise<void> {
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<any> {
const executor = new DefaultExecutor(process);
await executor.execute();
return executor.getResult();
}
}

View File

@ -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<any> {}
async before(): Promise<any> {}
async begin(): Promise<any> {}
async process(): Promise<any> {}
async end(): Promise<any> {}
async after(): Promise<any> {}
async result(): Promise<any> {}
}

View File

@ -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<any> {}
async before(): Promise<any> {}
async begin(): Promise<any> {}
async process(): Promise<any> {}
async end(): Promise<any> {}
async after(): Promise<any> {}
async result(): Promise<any> {}
}

View File

@ -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<any> {}
async before(): Promise<any> {}
async begin(): Promise<any> {}
async process(): Promise<any> {}
async end(): Promise<any> {}
async after(): Promise<any> {}
async result(): Promise<any> {}
}

View File

@ -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<any> {}
async before(): Promise<any> {}
async begin(): Promise<any> {}
async process(): Promise<any> {}
async end(): Promise<any> {}
async after(): Promise<any> {}
async result(): Promise<any> {}
}

View File

@ -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<any> {}
async before(): Promise<any> {}
async begin(): Promise<any> {}
async process(): Promise<any> {}
async end(): Promise<any> {}
async after(): Promise<any> {}
async result(): Promise<any> {}
}

View File

@ -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<any> {}
async before(): Promise<any> {}
async begin(): Promise<any> {}
async process(): Promise<any> {}
async end(): Promise<any> {}
async after(): Promise<any> {}
async result(): Promise<any> {}
}

View File

@ -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<any> {}
async before(): Promise<any> {}
async begin(): Promise<any> {}
async process(): Promise<any> {}
async end(): Promise<any> {}
async after(): Promise<any> {}
async result(): Promise<any> {}
}

View File

@ -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<any> {}
async before(): Promise<any> {}
async begin(): Promise<any> {}
async process(): Promise<any> {}
async end(): Promise<any> {}
async after(): Promise<any> {}
async result(): Promise<any> {}
}

View File

@ -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<any> {}
async before(): Promise<any> {}
async begin(): Promise<any> {}
async process(): Promise<any> {}
async end(): Promise<any> {}
async after(): Promise<any> {}
async result(): Promise<any> {}
}

View File

@ -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<any> {}
async before(): Promise<any> {}
async begin(): Promise<any> {}
async process(): Promise<any> {}
async end(): Promise<any> {}
async after(): Promise<any> {}
async result(): Promise<any> {}
}

View File

@ -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<any> {
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);
}
}