mirror of
https://github.com/aditama-labs/nest-autocrud.git
synced 2024-11-21 19:06:21 +00:00
wip: injection
This commit is contained in:
parent
2c0e0b8ae8
commit
10f1e644b2
@ -1,8 +1,38 @@
|
||||
import {
|
||||
CREATE_PROCESS,
|
||||
READ_ENTIRE_PROCESS,
|
||||
READ_PAGINATION_PROCESS,
|
||||
READ_PROCESS,
|
||||
UPDATE_BATCH_PROCESS,
|
||||
UPDATE_ENTIRE_BATCH_PROCESS,
|
||||
UPDATE_ENTIRE_PROCESS,
|
||||
UPDATE_PARTIAL_PROCESS,
|
||||
} from '@autocrud/skeleton';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { PrismaService } from './prisma.service';
|
||||
import { PrismaBatchUpdateProcess } from './processes/batch/update.process';
|
||||
import { PrismaCreateProcess } from './processes/create.process';
|
||||
import { PrismaListProcess } from './processes/list.process';
|
||||
import { PrismaPaginationProcess } from './processes/pagination.process';
|
||||
import { PrismaPartialUpdateProcess } from './processes/partial/update.process';
|
||||
import { PrismaReadProcess } from './processes/read.process';
|
||||
import { PrismaUpdateProcess } from './processes/update.process';
|
||||
|
||||
@Module({
|
||||
providers: [PrismaService],
|
||||
providers: [
|
||||
PrismaService,
|
||||
{ provide: CREATE_PROCESS, useClass: PrismaCreateProcess },
|
||||
{ provide: READ_PROCESS, useClass: PrismaReadProcess },
|
||||
{ provide: READ_PAGINATION_PROCESS, useClass: PrismaPaginationProcess },
|
||||
{ provide: READ_ENTIRE_PROCESS, useClass: PrismaListProcess },
|
||||
{ provide: UPDATE_PARTIAL_PROCESS, useClass: PrismaPartialUpdateProcess },
|
||||
{ provide: UPDATE_BATCH_PROCESS, useClass: PrismaPartialUpdateProcess },
|
||||
{ provide: UPDATE_ENTIRE_PROCESS, useClass: PrismaUpdateProcess },
|
||||
{
|
||||
provide: UPDATE_ENTIRE_BATCH_PROCESS,
|
||||
useClass: PrismaBatchUpdateProcess,
|
||||
},
|
||||
],
|
||||
exports: [PrismaService],
|
||||
})
|
||||
export class PrismaModule {}
|
||||
|
@ -1,9 +1,17 @@
|
||||
import { CreateProcess } from '@autocrud/skeleton/processes/create.process';
|
||||
import { PrismaProcess } from './prisma.process';
|
||||
|
||||
export class PrismaCreateProcess
|
||||
extends PrismaProcess
|
||||
implements CreateProcess
|
||||
{
|
||||
private data;
|
||||
|
||||
setData(data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
export class PrismaCreateProcess extends CreateProcess {
|
||||
async process(): Promise<any> {
|
||||
this.prisma['asd'].create({
|
||||
data,
|
||||
});
|
||||
await this.getDelegate().create(this.data);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,14 @@
|
||||
import { ListProcess } from '@autocrud/skeleton/processes/list.process';
|
||||
import { PrismaProcess } from './prisma.process';
|
||||
|
||||
export class PrismaListProcess extends ListProcess {}
|
||||
export class PrismaListProcess extends PrismaProcess implements ListProcess {
|
||||
private data;
|
||||
|
||||
async process(): Promise<any> {
|
||||
this.data = await this.getDelegate().findMany();
|
||||
}
|
||||
|
||||
result() {
|
||||
return this.data;
|
||||
}
|
||||
}
|
||||
|
13
libs/prisma/src/processes/prisma.process.ts
Normal file
13
libs/prisma/src/processes/prisma.process.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { DefaultProcess } from '@autocrud/skeleton/processes/default.process';
|
||||
|
||||
export class PrismaProcess extends DefaultProcess {
|
||||
protected delegate;
|
||||
|
||||
setDelegate(delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
get getDelegate() {
|
||||
return this.delegate;
|
||||
}
|
||||
}
|
11
libs/skeleton/src/constants.ts
Normal file
11
libs/skeleton/src/constants.ts
Normal file
@ -0,0 +1,11 @@
|
||||
export declare const CREATE_PROCESS = 'CREATE_PROCESS';
|
||||
export declare const READ_PROCESS = 'READ_PROCESS';
|
||||
export declare const READ_PAGINATION_PROCESS = 'READ_PAGINATION_PROCESS';
|
||||
export declare const READ_ENTIRE_PROCESS = 'READ_ENTIRE_PROCESS';
|
||||
export declare const UPDATE_PARTIAL_PROCESS = 'UPDATE_PARTIAL_PROCESS';
|
||||
export declare const UPDATE_BATCH_PROCESS = 'UPDATE_BATCH_PROCESS';
|
||||
export declare const UPDATE_ENTIRE_PROCESS = 'UPDATE_ENTIRE_PROCESS';
|
||||
export declare const UPDATE_ENTIRE_BATCH_PROCESS =
|
||||
'UPDATE_ENTIRE_BATCH_PROCESS';
|
||||
export declare const DELETE_PROCESS = 'DELETE_PROCESS';
|
||||
export declare const DELETE_BATCH_PROCESS = 'DELETE_BATCH_PROCESS';
|
@ -1 +1,3 @@
|
||||
export * from './constants';
|
||||
export * from './skeleton-crud.controller';
|
||||
|
||||
|
@ -8,5 +8,7 @@ export class DefaultProcess implements ISkeletonProcess {
|
||||
async end(): Promise<any> {}
|
||||
async after(): Promise<any> {}
|
||||
|
||||
result(): any {}
|
||||
result(): any {
|
||||
return 'Hello World';
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,40 @@
|
||||
import { Delete, Get, Param, Patch, Post, Put } from '@nestjs/common';
|
||||
import { Delete, Get, Inject, Param, Patch, Post, Put } from '@nestjs/common';
|
||||
import {
|
||||
CREATE_PROCESS,
|
||||
DELETE_BATCH_PROCESS,
|
||||
DELETE_PROCESS,
|
||||
READ_ENTIRE_PROCESS,
|
||||
READ_PAGINATION_PROCESS,
|
||||
READ_PROCESS,
|
||||
UPDATE_BATCH_PROCESS,
|
||||
UPDATE_ENTIRE_BATCH_PROCESS,
|
||||
UPDATE_ENTIRE_PROCESS,
|
||||
UPDATE_PARTIAL_PROCESS,
|
||||
} from './constants';
|
||||
import { DefaultExecutor } from './executors/default.executor';
|
||||
import { ISkeletonCRUDController } from './interfaces/controller/skeleton-crud.controller.interface';
|
||||
|
||||
export class SkeletonCRUDController implements ISkeletonCRUDController {
|
||||
constructor(
|
||||
@Inject(CREATE_PROCESS)
|
||||
public readonly createProcess,
|
||||
@Inject(READ_PROCESS)
|
||||
public readonly readProcess,
|
||||
@Inject(READ_PAGINATION_PROCESS)
|
||||
public readonly readPaginationProcess,
|
||||
@Inject(READ_ENTIRE_PROCESS)
|
||||
public readonly readEntireProcess,
|
||||
@Inject(UPDATE_PARTIAL_PROCESS)
|
||||
public readonly updatePartialProcess,
|
||||
@Inject(UPDATE_BATCH_PROCESS)
|
||||
public readonly updateBatchProcess,
|
||||
@Inject(UPDATE_ENTIRE_PROCESS)
|
||||
public readonly updateEntireProcess,
|
||||
@Inject(UPDATE_ENTIRE_BATCH_PROCESS)
|
||||
public readonly updateEntireBatchProcess,
|
||||
@Inject(DELETE_PROCESS)
|
||||
public readonly deleteProcess,
|
||||
@Inject(DELETE_BATCH_PROCESS)
|
||||
public readonly deleteBatchProcess,
|
||||
) {}
|
||||
|
||||
|
@ -1,11 +1,5 @@
|
||||
import { PrismaCRUDController } from '@autocrud/prisma/prisma-crud.controller';
|
||||
import { SkeletonCRUDController } from '@autocrud/skeleton';
|
||||
import { Controller } from '@nestjs/common';
|
||||
|
||||
@Controller('hello')
|
||||
export class AppController extends PrismaCRUDController {
|
||||
constructor() {}
|
||||
|
||||
// Read(): void {
|
||||
// console.log(this.appService.getHello());
|
||||
// }
|
||||
}
|
||||
export class AppController extends SkeletonCRUDController {}
|
||||
|
Loading…
Reference in New Issue
Block a user