mirror of
https://github.com/aditama-labs/nest-autocrud.git
synced 2024-11-25 13:36:21 +00:00
wip: test simple delegate
This commit is contained in:
parent
10f1e644b2
commit
3755f49181
1
libs/prisma/src/constants.ts
Normal file
1
libs/prisma/src/constants.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export declare const PRISMA_DELEGATE = 'PRISMA_DELEGATE';
|
@ -1,37 +1,13 @@
|
|||||||
import {
|
import { READ_ENTIRE_PROCESS } from '@autocrud/skeleton';
|
||||||
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 { Module } from '@nestjs/common';
|
||||||
import { PrismaService } from './prisma.service';
|
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 { 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({
|
@Module({
|
||||||
providers: [
|
providers: [
|
||||||
PrismaService,
|
PrismaService,
|
||||||
{ provide: CREATE_PROCESS, useClass: PrismaCreateProcess },
|
|
||||||
{ provide: READ_PROCESS, useClass: PrismaReadProcess },
|
|
||||||
{ provide: READ_PAGINATION_PROCESS, useClass: PrismaPaginationProcess },
|
|
||||||
{ provide: READ_ENTIRE_PROCESS, useClass: PrismaListProcess },
|
{ 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],
|
exports: [PrismaService],
|
||||||
})
|
})
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
import { DefaultProcess } from '@autocrud/skeleton/processes/default.process';
|
import { DefaultProcess } from '@autocrud/skeleton/processes/default.process';
|
||||||
|
import { Inject } from '@nestjs/common';
|
||||||
|
import { PRISMA_DELEGATE } from '../constants';
|
||||||
|
|
||||||
export class PrismaProcess extends DefaultProcess {
|
export class PrismaProcess extends DefaultProcess {
|
||||||
protected delegate;
|
constructor(
|
||||||
|
@Inject(PRISMA_DELEGATE)
|
||||||
setDelegate(delegate) {
|
private delegate: any,
|
||||||
this.delegate = delegate;
|
) {
|
||||||
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
get getDelegate() {
|
get getDelegate() {
|
||||||
|
@ -1,11 +1 @@
|
|||||||
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 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,13 +1,3 @@
|
|||||||
|
|
||||||
export interface ISkeletonCRUDController {
|
export interface ISkeletonCRUDController {
|
||||||
create();
|
|
||||||
readSelected(id);
|
|
||||||
readPagination();
|
|
||||||
readEntire();
|
readEntire();
|
||||||
updatePartial();
|
|
||||||
updatePartialBatch();
|
|
||||||
updateEntire();
|
|
||||||
updateEntireBatch();
|
|
||||||
deleteSelected();
|
|
||||||
deleteBatch();
|
|
||||||
}
|
}
|
||||||
|
@ -1,90 +1,16 @@
|
|||||||
import { Delete, Get, Inject, Param, Patch, Post, Put } from '@nestjs/common';
|
import { Get, Inject } from '@nestjs/common';
|
||||||
import {
|
import { READ_ENTIRE_PROCESS } from './constants';
|
||||||
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 { 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 {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(CREATE_PROCESS)
|
|
||||||
public readonly createProcess,
|
|
||||||
@Inject(READ_PROCESS)
|
|
||||||
public readonly readProcess,
|
|
||||||
@Inject(READ_PAGINATION_PROCESS)
|
|
||||||
public readonly readPaginationProcess,
|
|
||||||
@Inject(READ_ENTIRE_PROCESS)
|
@Inject(READ_ENTIRE_PROCESS)
|
||||||
public readonly readEntireProcess,
|
public readonly readEntireProcess: any,
|
||||||
@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,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Post()
|
|
||||||
async create(): Promise<any> {
|
|
||||||
return await DefaultExecutor.bootstrap(this.createProcess);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(':id')
|
|
||||||
async readSelected(@Param('id') id) {
|
|
||||||
return await DefaultExecutor.bootstrap(this.readProcess);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get()
|
|
||||||
async readPagination() {
|
|
||||||
return await DefaultExecutor.bootstrap(this.readPaginationProcess);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('list')
|
@Get('list')
|
||||||
async readEntire() {
|
async readEntire() {
|
||||||
return await DefaultExecutor.bootstrap(this.readEntireProcess);
|
return await DefaultExecutor.bootstrap(this.readEntireProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch()
|
|
||||||
async updatePartial() {
|
|
||||||
return await DefaultExecutor.bootstrap(this.updatePartialProcess);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Patch('batch')
|
|
||||||
async updatePartialBatch() {
|
|
||||||
return await DefaultExecutor.bootstrap(this.updateBatchProcess);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Put()
|
|
||||||
async updateEntire() {
|
|
||||||
return await DefaultExecutor.bootstrap(this.updateEntireProcess);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Put('batch')
|
|
||||||
async updateEntireBatch() {
|
|
||||||
return await DefaultExecutor.bootstrap(this.updateEntireBatchProcess);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Delete()
|
|
||||||
async deleteSelected() {
|
|
||||||
return await DefaultExecutor.bootstrap(this.deleteProcess);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Delete('batch')
|
|
||||||
async deleteBatch() {
|
|
||||||
return await DefaultExecutor.bootstrap(this.deleteBatchProcess);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,20 @@
|
|||||||
import { PrismaModule } from '@autocrud/prisma';
|
import { PrismaModule, PrismaService } from '@autocrud/prisma';
|
||||||
|
import { PRISMA_DELEGATE } from '@autocrud/prisma/constants';
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { AppController } from './app.controller';
|
import { AppController } from './app.controller';
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
|
|
||||||
|
const delegateFactory = {
|
||||||
|
provide: PRISMA_DELEGATE,
|
||||||
|
useFactory: (prisma: PrismaService) => {
|
||||||
|
return prisma.user;
|
||||||
|
},
|
||||||
|
inject: [PrismaService],
|
||||||
|
};
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [PrismaModule],
|
imports: [PrismaModule],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService, delegateFactory],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
Loading…
Reference in New Issue
Block a user