wip: injection

This commit is contained in:
Supan Adit Pratama 2024-10-27 00:07:59 +07:00
parent 2c0e0b8ae8
commit 10f1e644b2
9 changed files with 109 additions and 16 deletions

View File

@ -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 { 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 { 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: [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], exports: [PrismaService],
}) })
export class PrismaModule {} export class PrismaModule {}

View File

@ -1,9 +1,17 @@
import { CreateProcess } from '@autocrud/skeleton/processes/create.process'; 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> { async process(): Promise<any> {
this.prisma['asd'].create({ await this.getDelegate().create(this.data);
data,
});
} }
} }

View File

@ -1,3 +1,14 @@
import { ListProcess } from '@autocrud/skeleton/processes/list.process'; 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;
}
}

View 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;
}
}

View 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';

View File

@ -1 +1,3 @@
export * from './constants';
export * from './skeleton-crud.controller'; export * from './skeleton-crud.controller';

View File

@ -8,5 +8,7 @@ export class DefaultProcess implements ISkeletonProcess {
async end(): Promise<any> {} async end(): Promise<any> {}
async after(): Promise<any> {} async after(): Promise<any> {}
result(): any {} result(): any {
return 'Hello World';
}
} }

View File

@ -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 { 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, public readonly createProcess,
@Inject(READ_PROCESS)
public readonly readProcess, public readonly readProcess,
@Inject(READ_PAGINATION_PROCESS)
public readonly readPaginationProcess, public readonly readPaginationProcess,
@Inject(READ_ENTIRE_PROCESS)
public readonly readEntireProcess, public readonly readEntireProcess,
@Inject(UPDATE_PARTIAL_PROCESS)
public readonly updatePartialProcess, public readonly updatePartialProcess,
@Inject(UPDATE_BATCH_PROCESS)
public readonly updateBatchProcess, public readonly updateBatchProcess,
@Inject(UPDATE_ENTIRE_PROCESS)
public readonly updateEntireProcess, public readonly updateEntireProcess,
@Inject(UPDATE_ENTIRE_BATCH_PROCESS)
public readonly updateEntireBatchProcess, public readonly updateEntireBatchProcess,
@Inject(DELETE_PROCESS)
public readonly deleteProcess, public readonly deleteProcess,
@Inject(DELETE_BATCH_PROCESS)
public readonly deleteBatchProcess, public readonly deleteBatchProcess,
) {} ) {}

View File

@ -1,11 +1,5 @@
import { PrismaCRUDController } from '@autocrud/prisma/prisma-crud.controller'; import { SkeletonCRUDController } from '@autocrud/skeleton';
import { Controller } from '@nestjs/common'; import { Controller } from '@nestjs/common';
@Controller('hello') @Controller('hello')
export class AppController extends PrismaCRUDController { export class AppController extends SkeletonCRUDController {}
constructor() {}
// Read(): void {
// console.log(this.appService.getHello());
// }
}