mirror of
https://github.com/aditama-labs/nest-autocrud.git
synced 2024-11-22 03:16:21 +00:00
wip: implementing executor
This commit is contained in:
parent
b15a07d16a
commit
ff07bd1ec3
@ -15,4 +15,10 @@ export class PrismaExecutor {
|
|||||||
getResult(): any {
|
getResult(): any {
|
||||||
return this.process.result();
|
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 {
|
export class PrismaCRUDController extends SkeletonCRUDController {
|
||||||
async create(): Promise<any> {
|
async create(): Promise<any> {
|
||||||
const executor = new PrismaExecutor(this.createProcess);
|
return await PrismaExecutor.default(this.createProcess);
|
||||||
await executor.execute();
|
|
||||||
return executor.getResult();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
import { CreateProcess } from '@autocrud/skeleton/processes/create.process';
|
import { CreateProcess } from '@autocrud/skeleton/processes/create.process';
|
||||||
import { Prisma, PrismaClient } from '@prisma/client';
|
|
||||||
|
|
||||||
export abstract class PrismaCreateProcess implements CreateProcess {
|
export class PrismaCreateProcess implements CreateProcess {
|
||||||
constructor(private readonly prisma: PrismaClient) {}
|
initialization();
|
||||||
|
before();
|
||||||
|
begin();
|
||||||
|
|
||||||
abstract initialization(): T;
|
|
||||||
abstract before(): T;
|
|
||||||
abstract begin(): T;
|
|
||||||
process(): T {
|
process(): T {
|
||||||
this.prisma['asd'].create({
|
this.prisma['asd'].create({
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
abstract end(): T;
|
|
||||||
abstract after(): T;
|
end();
|
||||||
abstract result(): R;
|
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';
|
import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface';
|
||||||
|
|
||||||
export abstract class BatchDeleteProcess implements ISkeletonProcess {
|
export abstract class BatchDeleteProcess implements ISkeletonProcess {
|
||||||
abstract initialization();
|
async initialization(): Promise<any> {}
|
||||||
abstract before();
|
async before(): Promise<any> {}
|
||||||
abstract begin();
|
async begin(): Promise<any> {}
|
||||||
abstract process();
|
async process(): Promise<any> {}
|
||||||
abstract end();
|
async end(): Promise<any> {}
|
||||||
abstract after();
|
async after(): Promise<any> {}
|
||||||
abstract result();
|
async result(): Promise<any> {}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface';
|
import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface';
|
||||||
|
|
||||||
export abstract class BatchUpdateProcess implements ISkeletonProcess {
|
export abstract class BatchUpdateProcess implements ISkeletonProcess {
|
||||||
abstract initialization();
|
async initialization(): Promise<any> {}
|
||||||
abstract before();
|
async before(): Promise<any> {}
|
||||||
abstract begin();
|
async begin(): Promise<any> {}
|
||||||
abstract process();
|
async process(): Promise<any> {}
|
||||||
abstract end();
|
async end(): Promise<any> {}
|
||||||
abstract after();
|
async after(): Promise<any> {}
|
||||||
abstract result();
|
async result(): Promise<any> {}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
|
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
|
||||||
|
|
||||||
export abstract class CreateProcess implements ISkeletonProcess {
|
export class CreateProcess implements ISkeletonProcess {
|
||||||
abstract initialization();
|
async initialization(): Promise<any> {}
|
||||||
abstract before();
|
async before(): Promise<any> {}
|
||||||
abstract begin();
|
async begin(): Promise<any> {}
|
||||||
abstract process();
|
async process(): Promise<any> {}
|
||||||
abstract end();
|
async end(): Promise<any> {}
|
||||||
abstract after();
|
async after(): Promise<any> {}
|
||||||
abstract result();
|
async result(): Promise<any> {}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
|
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
|
||||||
|
|
||||||
export abstract class DeleteProcess implements ISkeletonProcess {
|
export class DeleteProcess implements ISkeletonProcess {
|
||||||
abstract initialization();
|
async initialization(): Promise<any> {}
|
||||||
abstract before();
|
async before(): Promise<any> {}
|
||||||
abstract begin();
|
async begin(): Promise<any> {}
|
||||||
abstract process();
|
async process(): Promise<any> {}
|
||||||
abstract end();
|
async end(): Promise<any> {}
|
||||||
abstract after();
|
async after(): Promise<any> {}
|
||||||
abstract result();
|
async result(): Promise<any> {}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
|
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
|
||||||
|
|
||||||
export abstract class ListProcess implements ISkeletonProcess {
|
export abstract class ListProcess implements ISkeletonProcess {
|
||||||
abstract initialization();
|
async initialization(): Promise<any> {}
|
||||||
abstract before();
|
async before(): Promise<any> {}
|
||||||
abstract begin();
|
async begin(): Promise<any> {}
|
||||||
abstract process();
|
async process(): Promise<any> {}
|
||||||
abstract end();
|
async end(): Promise<any> {}
|
||||||
abstract after();
|
async after(): Promise<any> {}
|
||||||
abstract result();
|
async result(): Promise<any> {}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
|
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
|
||||||
|
|
||||||
export abstract class PaginationProcess implements ISkeletonProcess {
|
export abstract class PaginationProcess implements ISkeletonProcess {
|
||||||
abstract initialization();
|
async initialization(): Promise<any> {}
|
||||||
abstract before();
|
async before(): Promise<any> {}
|
||||||
abstract begin();
|
async begin(): Promise<any> {}
|
||||||
abstract process();
|
async process(): Promise<any> {}
|
||||||
abstract end();
|
async end(): Promise<any> {}
|
||||||
abstract after();
|
async after(): Promise<any> {}
|
||||||
abstract result();
|
async result(): Promise<any> {}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface';
|
import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface';
|
||||||
|
|
||||||
export abstract class PartialBatchUpdateProcess implements ISkeletonProcess {
|
export abstract class PartialBatchUpdateProcess implements ISkeletonProcess {
|
||||||
abstract initialization();
|
async initialization(): Promise<any> {}
|
||||||
abstract before();
|
async before(): Promise<any> {}
|
||||||
abstract begin();
|
async begin(): Promise<any> {}
|
||||||
abstract process();
|
async process(): Promise<any> {}
|
||||||
abstract end();
|
async end(): Promise<any> {}
|
||||||
abstract after();
|
async after(): Promise<any> {}
|
||||||
abstract result();
|
async result(): Promise<any> {}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface';
|
import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface';
|
||||||
|
|
||||||
export abstract class PartialUpdateProcess implements ISkeletonProcess {
|
export abstract class PartialUpdateProcess implements ISkeletonProcess {
|
||||||
abstract initialization();
|
async initialization(): Promise<any> {}
|
||||||
abstract before();
|
async before(): Promise<any> {}
|
||||||
abstract begin();
|
async begin(): Promise<any> {}
|
||||||
abstract process();
|
async process(): Promise<any> {}
|
||||||
abstract end();
|
async end(): Promise<any> {}
|
||||||
abstract after();
|
async after(): Promise<any> {}
|
||||||
abstract result();
|
async result(): Promise<any> {}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
|
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
|
||||||
|
|
||||||
export abstract class ReadProcess implements ISkeletonProcess {
|
export abstract class ReadProcess implements ISkeletonProcess {
|
||||||
abstract initialization();
|
async initialization(): Promise<any> {}
|
||||||
abstract before();
|
async before(): Promise<any> {}
|
||||||
abstract begin();
|
async begin(): Promise<any> {}
|
||||||
abstract process();
|
async process(): Promise<any> {}
|
||||||
abstract end();
|
async end(): Promise<any> {}
|
||||||
abstract after();
|
async after(): Promise<any> {}
|
||||||
abstract result();
|
async result(): Promise<any> {}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
|
import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
|
||||||
|
|
||||||
export abstract class UpdateProcess implements ISkeletonProcess {
|
export class UpdateProcess implements ISkeletonProcess {
|
||||||
abstract initialization();
|
async initialization(): Promise<any> {}
|
||||||
abstract before();
|
async before(): Promise<any> {}
|
||||||
abstract begin();
|
async begin(): Promise<any> {}
|
||||||
abstract process();
|
async process(): Promise<any> {}
|
||||||
abstract end();
|
async end(): Promise<any> {}
|
||||||
abstract after();
|
async after(): Promise<any> {}
|
||||||
abstract result();
|
async result(): Promise<any> {}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Delete, Get, Param, Patch, Post, Put } from '@nestjs/common';
|
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';
|
import { ISkeletonCRUDController } from './interfaces/controller/skeleton-crud.controller.interface';
|
||||||
|
|
||||||
export class SkeletonCRUDController implements ISkeletonCRUDController {
|
export class SkeletonCRUDController implements ISkeletonCRUDController {
|
||||||
@ -16,52 +17,52 @@ export class SkeletonCRUDController implements ISkeletonCRUDController {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
async create() {
|
async create(): Promise<any> {
|
||||||
return this.createProcess.result();
|
return await DefaultExecutor.bootstrap(this.createProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
async readSelected(@Param('id') id) {
|
async readSelected(@Param('id') id) {
|
||||||
return this.readProcess.result();
|
return await DefaultExecutor.bootstrap(this.readProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async readPagination() {
|
async readPagination() {
|
||||||
return this.readPaginationProcess.result();
|
return await DefaultExecutor.bootstrap(this.readPaginationProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('list')
|
@Get('list')
|
||||||
async readEntire() {
|
async readEntire() {
|
||||||
return this.readEntireProcess.result();
|
return await DefaultExecutor.bootstrap(this.readEntireProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch()
|
@Patch()
|
||||||
async updatePartial() {
|
async updatePartial() {
|
||||||
return this.updatePartialProcess.result();
|
return await DefaultExecutor.bootstrap(this.updatePartialProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch('batch')
|
@Patch('batch')
|
||||||
async updatePartialBatch() {
|
async updatePartialBatch() {
|
||||||
return this.updateBatchProcess.result();
|
return await DefaultExecutor.bootstrap(this.updateBatchProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
async updateEntire() {
|
async updateEntire() {
|
||||||
return this.updateEntireProcess.result();
|
return await DefaultExecutor.bootstrap(this.updateEntireProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put('batch')
|
@Put('batch')
|
||||||
async updateEntireBatch() {
|
async updateEntireBatch() {
|
||||||
return this.updateEntireBatchProcess.result();
|
return await DefaultExecutor.bootstrap(this.updateEntireBatchProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete()
|
@Delete()
|
||||||
async deleteSelected() {
|
async deleteSelected() {
|
||||||
return this.deleteProcess.result();
|
return await DefaultExecutor.bootstrap(this.deleteProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete('batch')
|
@Delete('batch')
|
||||||
async deleteBatch() {
|
async deleteBatch() {
|
||||||
return this.deleteBatchProcess.result();
|
return await DefaultExecutor.bootstrap(this.deleteBatchProcess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user