mirror of
https://github.com/aditama-labs/nest-autocrud.git
synced 2024-11-21 19:06:21 +00:00
wip: implementing executor
This commit is contained in:
parent
b15a07d16a
commit
ff07bd1ec3
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
24
libs/skeleton/src/executors/default.executor.ts
Normal file
24
libs/skeleton/src/executors/default.executor.ts
Normal 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();
|
||||
}
|
||||
}
|
@ -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> {}
|
||||
}
|
||||
|
@ -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> {}
|
||||
}
|
||||
|
@ -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> {}
|
||||
}
|
||||
|
@ -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> {}
|
||||
}
|
||||
|
@ -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> {}
|
||||
}
|
||||
|
@ -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> {}
|
||||
}
|
||||
|
@ -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> {}
|
||||
}
|
||||
|
@ -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> {}
|
||||
}
|
||||
|
@ -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> {}
|
||||
}
|
||||
|
@ -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> {}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user