From 0c86c9ed88895ed237307c584b9c415de7b1fb76 Mon Sep 17 00:00:00 2001 From: Supan Adit Pratama Date: Sat, 2 Nov 2024 21:39:59 +0700 Subject: [PATCH] feat: more specific fine grain controller --- README.md | 10 ----- libs/skeleton/src/skeleton-crud.controller.ts | 44 ++++++++++++++++++- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 2481e19..54ce60a 100644 --- a/README.md +++ b/README.md @@ -23,16 +23,6 @@ Nest Auto CRUD is a library that provides a set of modules, decorator, service, - Custom body mapping - Custom validation -### Tailored Controller Abstraction - -- Controller options for only read and update -- Controller options for only create and delete -- Controller options for only read -- Controller options for only update -- Controller options for only create -- Controller options for only delete -- Controller options for only read and create - ### Advanced Support - Generic support for Prisma ORM [#5273](https://github.com/prisma/prisma/issues/5273) diff --git a/libs/skeleton/src/skeleton-crud.controller.ts b/libs/skeleton/src/skeleton-crud.controller.ts index 0ef2cc5..a402164 100644 --- a/libs/skeleton/src/skeleton-crud.controller.ts +++ b/libs/skeleton/src/skeleton-crud.controller.ts @@ -35,7 +35,7 @@ import { ISkeletonUpdateController, } from './interfaces/controller/skeleton-crud.controller.interface'; -export class SkeletonReadController implements ISkeletonReadController { +export class SkeletonDetailController implements ISkeletonReadController { constructor( @Inject(READ_PROCESS) public readonly readProcess, @@ -71,6 +71,48 @@ export class SkeletonListController implements ISkeletonListController { } } +export class SkeletonCRController + implements ISkeletonCreateController, ISkeletonReadController +{ + constructor( + @Inject(READ_PROCESS) + public readonly readProcess, + @Inject(CREATE_PROCESS) + public readonly createProcess, + ) {} + + @Get(':id') + async read(@Param('id') identity) { + return await ReadExecutor.bootstrap(this.readProcess, identity); + } + + @Post() + async create(@Body() body) { + return await CreateExcutor.bootstrap(this.createProcess, body); + } +} + +export class SkeletonURController + implements ISkeletonUpdateController, ISkeletonReadController +{ + constructor( + @Inject(READ_PROCESS) + public readonly readProcess, + @Inject(UPDATE_PROCESS) + public readonly updateProcess, + ) {} + + @Get(':id') + async read(@Param('id') identity) { + return await ReadExecutor.bootstrap(this.readProcess, identity); + } + + @Patch(':id') + async update(@Param('id') identity, @Body() body) { + return await UpdateExecutor.bootstrap(this.updateProcess, identity, body); + } +} + export class SkeletonPaginationController implements ISkeletonPaginationController {