feat: full working basic crud and customizable process

This commit is contained in:
Supan Adit Pratama 2024-10-31 23:54:35 +07:00
parent c150a75206
commit a709ef4da8
13 changed files with 86 additions and 62 deletions

View File

@ -1,6 +1,6 @@
export * from './prisma.module'; export * from './config.module-definition';
export * from './prisma.service';
export * from './constants'; export * from './constants';
export * from './interfaces'; export * from './interfaces';
export * from './config.module-definition'; export * from './prisma.module';
export * from './processes/list.process'; export * from './prisma.service';
export * from './processes';

2
scripts/unix/cleaner.sh Executable file
View File

@ -0,0 +1,2 @@
rm -rf ./plugins
rm -rf ./dist

View File

@ -1,22 +0,0 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
describe('AppController', () => {
let appController: AppController;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
appController = app.get<AppController>(AppController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});

View File

@ -1,5 +0,0 @@
import { SkeletonCRUDController } from '@aditama-labs/nest-autocrud/skeleton';
import { Controller } from '@nestjs/common';
@Controller('example')
export class AppController extends SkeletonCRUDController {}

View File

@ -1,16 +1,10 @@
import { PrismaModule } from '@aditama-labs/nest-autocrud/prisma';
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { AppController } from './app.controller'; import { SimpleModule } from './example/simple/simple.module';
import { AppService } from './app.service'; import { CustomModule } from './example/custom/custom.module';
import { PrismaClient } from '@prisma/client';
@Module({ @Module({
imports: [ imports: [SimpleModule, CustomModule],
PrismaModule.forRoot({ controllers: [],
delegate: (prisma: PrismaClient) => prisma.user, providers: [],
}),
],
controllers: [AppController],
providers: [AppService],
}) })
export class AppModule {} export class AppModule {}

View File

@ -1,8 +0,0 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
}

View File

@ -0,0 +1,5 @@
import { Controller } from '@nestjs/common';
import { SkeletonCRUDController } from 'libs';
@Controller('example/custom')
export class CustomController extends SkeletonCRUDController {}

View File

@ -0,0 +1,19 @@
import { Module } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { PrismaModule } from 'libs';
import { CustomController } from './custom.controller';
import { CustomListProcess } from './domain/custom.list.process';
import { CustomReadProcess } from './domain/custom.read.process';
@Module({
imports: [
PrismaModule.forRoot({
delegate: (prisma: PrismaClient) => prisma.user,
processList: CustomListProcess,
processRead: CustomReadProcess,
}),
],
controllers: [CustomController],
providers: [],
})
export class CustomModule {}

View File

@ -0,0 +1,12 @@
import { PrismaListProcess } from '@aditama-labs/nest-autocrud/prisma';
export class CustomListProcess extends PrismaListProcess {
async before(): Promise<any> {
console.log('This is custom logic before query to database');
}
output() {
console.log('You can modify the output here');
return super.output();
}
}

View File

@ -0,0 +1,19 @@
import { PrismaReadProcess } from '@aditama-labs/nest-autocrud/prisma';
export class CustomReadProcess extends PrismaReadProcess {
customResult;
async before(): Promise<any> {
console.log('The ID requested in path parameter', this.id);
}
async after(): Promise<any> {
this.customResult = {
...super.output(),
custom_code: 'XXXX',
};
}
output() {
return this.customResult;
}
}

View File

@ -0,0 +1,5 @@
import { Controller } from '@nestjs/common';
import { SkeletonCRUDController } from 'libs';
@Controller('example/simple')
export class SimpleController extends SkeletonCRUDController {}

View File

@ -0,0 +1,15 @@
import { Module } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { PrismaModule } from 'libs';
import { SimpleController } from './simple.controller';
@Module({
imports: [
PrismaModule.forRoot({
delegate: (prisma: PrismaClient) => prisma.user,
}),
],
controllers: [SimpleController],
providers: [],
})
export class SimpleModule {}

View File

@ -1,12 +0,0 @@
import { PrismaListProcess } from '@aditama-labs/nest-autocrud/prisma';
export class AppListProcess extends PrismaListProcess {
async process(): Promise<any> {
console.log('Hello World');
super.process();
}
output() {
return [];
}
}