wip: default params

This commit is contained in:
Supan Adit Pratama 2024-10-30 21:38:19 +07:00
parent 37d5f6b746
commit 87f951fe08
15 changed files with 36 additions and 24 deletions

View File

@ -16,7 +16,7 @@ export class PrismaCreateProcess
this.dataResult = await this.getDelegate().create(this.dataInsert);
}
result() {
output() {
this.dataResult;
}
}

View File

@ -14,7 +14,7 @@ export class PrismaDeleteProcess
});
}
result() {
output() {
return this.dataResult;
}
}

View File

@ -8,7 +8,7 @@ export class PrismaListProcess extends PrismaProcess implements ListProcess {
this.data = await this.getDelegate().findMany();
}
result() {
output() {
return this.data;
}
}

View File

@ -11,7 +11,7 @@ export class PrismaReadProcess extends PrismaProcess implements CreateProcess {
});
}
result() {
output() {
return this.data;
}
}

View File

@ -16,7 +16,7 @@ export class PrismaUpdateProcess
});
}
result() {
output() {
return this.dataResult;
}
}

View File

@ -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();
}
}

View File

@ -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);
}

View File

@ -6,5 +6,5 @@ export interface ISkeletonProcess {
end();
after();
result();
output();
}

View File

@ -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!';
}
}

View File

@ -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);
}
}

View File

@ -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
View File

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

View File

@ -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],

View File

@ -6,7 +6,7 @@ export class AppListProcess extends PrismaListProcess {
super.process();
}
result() {
output() {
return [];
}
}