mirror of
https://github.com/aditama-labs/nest-autocrud.git
synced 2024-11-21 10:46:22 +00:00
feat: full working basic crud and customizable process
This commit is contained in:
parent
c150a75206
commit
a709ef4da8
@ -1,6 +1,6 @@
|
||||
export * from './prisma.module';
|
||||
export * from './prisma.service';
|
||||
export * from './config.module-definition';
|
||||
export * from './constants';
|
||||
export * from './interfaces';
|
||||
export * from './config.module-definition';
|
||||
export * from './processes/list.process';
|
||||
export * from './prisma.module';
|
||||
export * from './prisma.service';
|
||||
export * from './processes';
|
||||
|
2
scripts/unix/cleaner.sh
Executable file
2
scripts/unix/cleaner.sh
Executable file
@ -0,0 +1,2 @@
|
||||
rm -rf ./plugins
|
||||
rm -rf ./dist
|
@ -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!');
|
||||
});
|
||||
});
|
||||
});
|
@ -1,5 +0,0 @@
|
||||
import { SkeletonCRUDController } from '@aditama-labs/nest-autocrud/skeleton';
|
||||
import { Controller } from '@nestjs/common';
|
||||
|
||||
@Controller('example')
|
||||
export class AppController extends SkeletonCRUDController {}
|
@ -1,16 +1,10 @@
|
||||
import { PrismaModule } from '@aditama-labs/nest-autocrud/prisma';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { SimpleModule } from './example/simple/simple.module';
|
||||
import { CustomModule } from './example/custom/custom.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
PrismaModule.forRoot({
|
||||
delegate: (prisma: PrismaClient) => prisma.user,
|
||||
}),
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
imports: [SimpleModule, CustomModule],
|
||||
controllers: [],
|
||||
providers: [],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
@ -1,8 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
5
src/example/custom/custom.controller.ts
Normal file
5
src/example/custom/custom.controller.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { Controller } from '@nestjs/common';
|
||||
import { SkeletonCRUDController } from 'libs';
|
||||
|
||||
@Controller('example/custom')
|
||||
export class CustomController extends SkeletonCRUDController {}
|
19
src/example/custom/custom.module.ts
Normal file
19
src/example/custom/custom.module.ts
Normal 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 {}
|
12
src/example/custom/domain/custom.list.process.ts
Normal file
12
src/example/custom/domain/custom.list.process.ts
Normal 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();
|
||||
}
|
||||
}
|
19
src/example/custom/domain/custom.read.process.ts
Normal file
19
src/example/custom/domain/custom.read.process.ts
Normal 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;
|
||||
}
|
||||
}
|
5
src/example/simple/simple.controller.ts
Normal file
5
src/example/simple/simple.controller.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { Controller } from '@nestjs/common';
|
||||
import { SkeletonCRUDController } from 'libs';
|
||||
|
||||
@Controller('example/simple')
|
||||
export class SimpleController extends SkeletonCRUDController {}
|
15
src/example/simple/simple.module.ts
Normal file
15
src/example/simple/simple.module.ts
Normal 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 {}
|
@ -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 [];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user