mirror of
https://github.com/aditama-labs/nest-autocrud.git
synced 2024-11-21 10:46:22 +00:00
wip: default params
This commit is contained in:
parent
37d5f6b746
commit
87f951fe08
@ -16,7 +16,7 @@ export class PrismaCreateProcess
|
||||
this.dataResult = await this.getDelegate().create(this.dataInsert);
|
||||
}
|
||||
|
||||
result() {
|
||||
output() {
|
||||
this.dataResult;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ export class PrismaDeleteProcess
|
||||
});
|
||||
}
|
||||
|
||||
result() {
|
||||
output() {
|
||||
return this.dataResult;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ export class PrismaListProcess extends PrismaProcess implements ListProcess {
|
||||
this.data = await this.getDelegate().findMany();
|
||||
}
|
||||
|
||||
result() {
|
||||
output() {
|
||||
return this.data;
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ export class PrismaReadProcess extends PrismaProcess implements CreateProcess {
|
||||
});
|
||||
}
|
||||
|
||||
result() {
|
||||
output() {
|
||||
return this.data;
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ export class PrismaUpdateProcess
|
||||
});
|
||||
}
|
||||
|
||||
result() {
|
||||
output() {
|
||||
return this.dataResult;
|
||||
}
|
||||
}
|
||||
|
@ -12,13 +12,13 @@ export class DefaultExecutor {
|
||||
await this.process.after();
|
||||
}
|
||||
|
||||
getResult(): any {
|
||||
return this.process.result();
|
||||
getOutput(): any {
|
||||
return this.process.output();
|
||||
}
|
||||
|
||||
static async bootstrap(process: ISkeletonProcess): Promise<any> {
|
||||
const executor = new DefaultExecutor(process);
|
||||
await executor.execute();
|
||||
return executor.getResult();
|
||||
return executor.getOutput();
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
export interface ISkeletonCRUDController {
|
||||
create();
|
||||
delete();
|
||||
create(body);
|
||||
delete(id);
|
||||
list();
|
||||
pagination();
|
||||
pagination(params: { page?: number; limit?: number });
|
||||
read(id);
|
||||
update();
|
||||
update(id, body);
|
||||
}
|
||||
|
@ -6,5 +6,5 @@ export interface ISkeletonProcess {
|
||||
end();
|
||||
after();
|
||||
|
||||
result();
|
||||
output();
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ export class DefaultProcess implements ISkeletonProcess {
|
||||
async end(): Promise<any> {}
|
||||
async after(): Promise<any> {}
|
||||
|
||||
result(): any {
|
||||
return 'Hello World';
|
||||
output(): any {
|
||||
return 'Not Implemented Yet!';
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,13 @@
|
||||
import { Delete, Get, Inject, Param, Patch, Post } from '@nestjs/common';
|
||||
import {
|
||||
Body,
|
||||
Delete,
|
||||
Get,
|
||||
Inject,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
Query,
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
CREATE_PROCESS,
|
||||
DELETE_PROCESS,
|
||||
@ -27,12 +36,12 @@ export class SkeletonCRUDController implements ISkeletonCRUDController {
|
||||
) {}
|
||||
|
||||
@Post()
|
||||
async create(): Promise<any> {
|
||||
async create(@Body() body): Promise<any> {
|
||||
return await DefaultExecutor.bootstrap(this.createProcess);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async delete() {
|
||||
async delete(@Param('id') id) {
|
||||
return await DefaultExecutor.bootstrap(this.deleteProcess);
|
||||
}
|
||||
|
||||
@ -42,7 +51,9 @@ export class SkeletonCRUDController implements ISkeletonCRUDController {
|
||||
}
|
||||
|
||||
@Get()
|
||||
async pagination() {
|
||||
async pagination(
|
||||
@Query() params: { page?: number; limit?: number } = { page: 1, limit: 10 },
|
||||
) {
|
||||
return await DefaultExecutor.bootstrap(this.paginationProcess);
|
||||
}
|
||||
|
||||
@ -52,7 +63,7 @@ export class SkeletonCRUDController implements ISkeletonCRUDController {
|
||||
}
|
||||
|
||||
@Patch()
|
||||
async update() {
|
||||
async update(@Param('id') id, @Body() body) {
|
||||
return await DefaultExecutor.bootstrap(this.updateProcess);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@aditama-labs/nest-autocrud",
|
||||
"version": "0.0.22",
|
||||
"version": "0.0.23",
|
||||
"description": "NestJS Auto CRUD Library",
|
||||
"author": "Supan Adit Pratama",
|
||||
"license": "MIT",
|
||||
|
0
scripts/unix/release.sh
Normal file → Executable file
0
scripts/unix/release.sh
Normal file → Executable file
@ -1,5 +1,5 @@
|
||||
import { SkeletonCRUDController } from '@aditama-labs/nest-autocrud/skeleton';
|
||||
import { Controller } from '@nestjs/common';
|
||||
|
||||
@Controller('hello')
|
||||
@Controller('example')
|
||||
export class AppController extends SkeletonCRUDController {}
|
||||
|
@ -2,11 +2,12 @@ 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';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
PrismaModule.forRoot({
|
||||
delegate: (prisma) => prisma.user,
|
||||
delegate: (prisma: PrismaClient) => prisma.user,
|
||||
}),
|
||||
],
|
||||
controllers: [AppController],
|
||||
|
@ -6,7 +6,7 @@ export class AppListProcess extends PrismaListProcess {
|
||||
super.process();
|
||||
}
|
||||
|
||||
result() {
|
||||
output() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user