mirror of
https://github.com/aditama-labs/nest-autocrud.git
synced 2024-11-22 03:16:21 +00:00
wip: full fledge of API CRUD
This commit is contained in:
parent
f696145948
commit
64b7119347
@ -1,7 +1,19 @@
|
|||||||
import { PrismaService } from '../prisma.service';
|
import { PrismaService } from '../prisma.service';
|
||||||
|
import {
|
||||||
|
PrismaCreateProcess,
|
||||||
|
PrismaDeleteProcess,
|
||||||
|
PrismaPaginationProcess,
|
||||||
|
PrismaReadProcess,
|
||||||
|
PrismaUpdateProcess,
|
||||||
|
} from '../processes';
|
||||||
import { PrismaListProcess } from '../processes/list.process';
|
import { PrismaListProcess } from '../processes/list.process';
|
||||||
|
|
||||||
export interface PrismaModuleOptions {
|
export interface PrismaModuleOptions {
|
||||||
delegate: (prisma: PrismaService) => any;
|
delegate: (prisma: PrismaService) => any;
|
||||||
processList: typeof PrismaListProcess;
|
processCreate?: typeof PrismaCreateProcess;
|
||||||
|
processDelete?: typeof PrismaDeleteProcess;
|
||||||
|
processList?: typeof PrismaListProcess;
|
||||||
|
processPagination?: typeof PrismaPaginationProcess;
|
||||||
|
processRead?: typeof PrismaReadProcess;
|
||||||
|
processUpdate?: typeof PrismaUpdateProcess;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { READ_ENTIRE_PROCESS } from '@aditama-labs/nest-autocrud/skeleton';
|
import { LIST_PROCESS } from '@aditama-labs/nest-autocrud/skeleton';
|
||||||
import { DynamicModule, Module } from '@nestjs/common';
|
import { DynamicModule, Module } from '@nestjs/common';
|
||||||
import { ConfigurableModuleClass } from './config.module-definition';
|
import { ConfigurableModuleClass } from './config.module-definition';
|
||||||
import { PRISMA_DELEGATE } from './constants';
|
import { PRISMA_DELEGATE } from './constants';
|
||||||
@ -7,7 +7,7 @@ import { PrismaService } from './prisma.service';
|
|||||||
import { PrismaListProcess } from './processes/list.process';
|
import { PrismaListProcess } from './processes/list.process';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
exports: [PrismaService, PRISMA_DELEGATE, READ_ENTIRE_PROCESS],
|
exports: [PrismaService, PRISMA_DELEGATE, LIST_PROCESS],
|
||||||
})
|
})
|
||||||
export class PrismaModule extends ConfigurableModuleClass {
|
export class PrismaModule extends ConfigurableModuleClass {
|
||||||
static forRoot(options: PrismaModuleOptions): DynamicModule {
|
static forRoot(options: PrismaModuleOptions): DynamicModule {
|
||||||
@ -25,7 +25,7 @@ export class PrismaModule extends ConfigurableModuleClass {
|
|||||||
providers = [
|
providers = [
|
||||||
...providers,
|
...providers,
|
||||||
{
|
{
|
||||||
provide: READ_ENTIRE_PROCESS,
|
provide: LIST_PROCESS,
|
||||||
useClass: options.processList,
|
useClass: options.processList,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -33,7 +33,7 @@ export class PrismaModule extends ConfigurableModuleClass {
|
|||||||
providers = [
|
providers = [
|
||||||
...providers,
|
...providers,
|
||||||
{
|
{
|
||||||
provide: READ_ENTIRE_PROCESS,
|
provide: LIST_PROCESS,
|
||||||
useClass: PrismaListProcess,
|
useClass: PrismaListProcess,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
import { BatchDeleteProcess } from '@aditama-labs/nest-autocrud/skeleton';
|
|
||||||
|
|
||||||
export class PrismaBatchDeleteProcess extends BatchDeleteProcess {}
|
|
@ -1,2 +0,0 @@
|
|||||||
export * from './delete.process';
|
|
||||||
export * from './update.process';
|
|
@ -1,3 +0,0 @@
|
|||||||
import { BatchUpdateProcess } from '@aditama-labs/nest-autocrud/skeleton';
|
|
||||||
|
|
||||||
export class PrismaBatchUpdateProcess extends BatchUpdateProcess {}
|
|
@ -5,13 +5,18 @@ export class PrismaCreateProcess
|
|||||||
extends PrismaProcess
|
extends PrismaProcess
|
||||||
implements CreateProcess
|
implements CreateProcess
|
||||||
{
|
{
|
||||||
private data;
|
private dataInsert;
|
||||||
|
private dataResult;
|
||||||
|
|
||||||
setData(data) {
|
setData(data) {
|
||||||
this.data = data;
|
this.dataInsert = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(): Promise<any> {
|
async process(): Promise<any> {
|
||||||
await this.getDelegate().create(this.data);
|
this.dataResult = await this.getDelegate().create(this.dataInsert);
|
||||||
|
}
|
||||||
|
|
||||||
|
result() {
|
||||||
|
this.dataResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,20 @@
|
|||||||
import { DeleteProcess } from '@aditama-labs/nest-autocrud/skeleton';
|
import { CreateProcess } from '@aditama-labs/nest-autocrud/skeleton';
|
||||||
|
import { PrismaProcess } from './prisma.process';
|
||||||
|
|
||||||
export class PrismaDeleteProcess extends DeleteProcess {}
|
export class PrismaDeleteProcess
|
||||||
|
extends PrismaProcess
|
||||||
|
implements CreateProcess
|
||||||
|
{
|
||||||
|
private dataResult: any;
|
||||||
|
private id: any;
|
||||||
|
|
||||||
|
async process(): Promise<any> {
|
||||||
|
this.dataResult = await this.getDelegate().delete({
|
||||||
|
where: { id: this.id },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
result() {
|
||||||
|
return this.dataResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
export * from './batch';
|
|
||||||
export * from './create.process';
|
export * from './create.process';
|
||||||
export * from './delete.process';
|
export * from './delete.process';
|
||||||
export * from './list.process';
|
export * from './list.process';
|
||||||
export * from './pagination.process';
|
export * from './pagination.process';
|
||||||
export * from './partial';
|
|
||||||
export * from './read.process';
|
export * from './read.process';
|
||||||
export * from './update.process';
|
export * from './update.process';
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ export class PrismaListProcess extends PrismaProcess implements ListProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result() {
|
result() {
|
||||||
console.log('ASDASDASDASD');
|
|
||||||
return this.data;
|
return this.data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +0,0 @@
|
|||||||
export * from './update.process';
|
|
@ -1,3 +0,0 @@
|
|||||||
import { PartialBatchUpdateProcess } from '@aditama-labs/nest-autocrud/skeleton';
|
|
||||||
|
|
||||||
export class PrismaPartialBatchUpdateProcess extends PartialBatchUpdateProcess {}
|
|
@ -1,2 +0,0 @@
|
|||||||
export * from './update.process';
|
|
||||||
export * from './batch';
|
|
@ -1,3 +0,0 @@
|
|||||||
import { PartialUpdateProcess } from '@aditama-labs/nest-autocrud/skeleton';
|
|
||||||
|
|
||||||
export class PrismaPartialUpdateProcess extends PartialUpdateProcess {}
|
|
@ -1,3 +1,17 @@
|
|||||||
import { ReadProcess } from '@aditama-labs/nest-autocrud/skeleton';
|
import { CreateProcess } from '@aditama-labs/nest-autocrud/skeleton';
|
||||||
|
import { PrismaProcess } from './prisma.process';
|
||||||
|
|
||||||
export class PrismaReadProcess extends ReadProcess {}
|
export class PrismaReadProcess extends PrismaProcess implements CreateProcess {
|
||||||
|
private data: any;
|
||||||
|
private id: any;
|
||||||
|
|
||||||
|
async process(): Promise<any> {
|
||||||
|
this.data = await this.getDelegate().findUnique({
|
||||||
|
where: { id: this.id },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
result() {
|
||||||
|
return this.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,3 +1,22 @@
|
|||||||
import { UpdateProcess } from '@aditama-labs/nest-autocrud/skeleton';
|
import { CreateProcess } from '@aditama-labs/nest-autocrud/skeleton';
|
||||||
|
import { PrismaProcess } from './prisma.process';
|
||||||
|
|
||||||
export class PrismaUpdateProcess extends UpdateProcess {}
|
export class PrismaUpdateProcess
|
||||||
|
extends PrismaProcess
|
||||||
|
implements CreateProcess
|
||||||
|
{
|
||||||
|
private dataResult: any;
|
||||||
|
private dataUpdate: any;
|
||||||
|
private id: any;
|
||||||
|
|
||||||
|
async process(): Promise<any> {
|
||||||
|
this.dataResult = await this.getDelegate().update({
|
||||||
|
data: this.dataUpdate,
|
||||||
|
where: { id: this.id },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
result() {
|
||||||
|
return this.dataResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1 +1,6 @@
|
|||||||
export const READ_ENTIRE_PROCESS = 'READ_ENTIRE_PROCESS';
|
export const CREATE_PROCESS = 'CREATE_PROCESS';
|
||||||
|
export const DELETE_PROCESS = 'DELETE_PROCESS';
|
||||||
|
export const LIST_PROCESS = 'LIST_PROCESS';
|
||||||
|
export const PAGINATION_PROCESS = 'PAGINATION_PROCESS';
|
||||||
|
export const READ_PROCESS = 'READ_PROCESS';
|
||||||
|
export const UPDATE_PROCESS = 'UPDATE_PROCESS';
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
export interface ISkeletonCRUDController {
|
export interface ISkeletonCRUDController {
|
||||||
readEntire();
|
create();
|
||||||
|
delete();
|
||||||
|
list();
|
||||||
|
pagination();
|
||||||
|
read(id);
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
import { DefaultProcess } from '../default.process';
|
|
||||||
|
|
||||||
export class BatchDeleteProcess extends DefaultProcess {}
|
|
@ -1,2 +0,0 @@
|
|||||||
export * from './delete.process';
|
|
||||||
export * from './update.process';
|
|
@ -1,3 +0,0 @@
|
|||||||
import { DefaultProcess } from '../default.process';
|
|
||||||
|
|
||||||
export class BatchUpdateProcess extends DefaultProcess {}
|
|
@ -5,5 +5,3 @@ export * from './list.process';
|
|||||||
export * from './pagination.process';
|
export * from './pagination.process';
|
||||||
export * from './read.process';
|
export * from './read.process';
|
||||||
export * from './update.process';
|
export * from './update.process';
|
||||||
export * from './batch';
|
|
||||||
export * from './partial';
|
|
||||||
|
@ -1 +0,0 @@
|
|||||||
export * from './update.process';
|
|
@ -1,3 +0,0 @@
|
|||||||
import { DefaultProcess } from '../../default.process';
|
|
||||||
|
|
||||||
export class PartialBatchUpdateProcess extends DefaultProcess {}
|
|
@ -1,2 +0,0 @@
|
|||||||
export * from './update.process';
|
|
||||||
export * from './batch';
|
|
@ -1,3 +0,0 @@
|
|||||||
import { DefaultProcess } from '../default.process';
|
|
||||||
|
|
||||||
export class PartialUpdateProcess extends DefaultProcess {}
|
|
@ -1,16 +1,58 @@
|
|||||||
import { Get, Inject } from '@nestjs/common';
|
import { Delete, Get, Inject, Param, Patch, Post } from '@nestjs/common';
|
||||||
import { READ_ENTIRE_PROCESS } from './constants';
|
import {
|
||||||
|
CREATE_PROCESS,
|
||||||
|
DELETE_PROCESS,
|
||||||
|
LIST_PROCESS,
|
||||||
|
PAGINATION_PROCESS,
|
||||||
|
READ_PROCESS,
|
||||||
|
UPDATE_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(READ_ENTIRE_PROCESS)
|
@Inject(CREATE_PROCESS)
|
||||||
public readonly readEntireProcess: any,
|
public readonly createProcess,
|
||||||
|
@Inject(DELETE_PROCESS)
|
||||||
|
public readonly deleteProcess,
|
||||||
|
@Inject(LIST_PROCESS)
|
||||||
|
public readonly listProcess,
|
||||||
|
@Inject(PAGINATION_PROCESS)
|
||||||
|
public readonly paginationProcess,
|
||||||
|
@Inject(READ_PROCESS)
|
||||||
|
public readonly readProcess,
|
||||||
|
@Inject(UPDATE_PROCESS)
|
||||||
|
public readonly updateProcess,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
async create(): Promise<any> {
|
||||||
|
return await DefaultExecutor.bootstrap(this.createProcess);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete(':id')
|
||||||
|
async delete() {
|
||||||
|
return await DefaultExecutor.bootstrap(this.deleteProcess);
|
||||||
|
}
|
||||||
|
|
||||||
@Get('list')
|
@Get('list')
|
||||||
async readEntire() {
|
async list() {
|
||||||
return await DefaultExecutor.bootstrap(this.readEntireProcess);
|
return await DefaultExecutor.bootstrap(this.listProcess);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
async pagination() {
|
||||||
|
return await DefaultExecutor.bootstrap(this.paginationProcess);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
async read(@Param('id') id) {
|
||||||
|
return await DefaultExecutor.bootstrap(this.readProcess);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch()
|
||||||
|
async update() {
|
||||||
|
return await DefaultExecutor.bootstrap(this.updateProcess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user