From 3ca746548ef73ecc974e5c4dcd6d391d206e6368 Mon Sep 17 00:00:00 2001 From: Supan Adit Pratama Date: Sat, 2 Nov 2024 01:22:14 +0700 Subject: [PATCH] feat: remove all promise for now to let user have flexibility --- .../interfaces/config-module-options.interface.ts | 2 +- libs/prisma/src/prisma.module.ts | 2 +- libs/prisma/src/processes/create.process.ts | 2 +- libs/prisma/src/processes/delete.process.ts | 4 ++-- libs/prisma/src/processes/list.process.ts | 2 +- libs/prisma/src/processes/pagination.process.ts | 2 +- libs/prisma/src/processes/read.process.ts | 2 +- libs/prisma/src/processes/update.process.ts | 6 +++--- libs/skeleton/src/executors/create.executor.ts | 2 +- libs/skeleton/src/executors/default.executor.ts | 2 +- libs/skeleton/src/executors/delete.executor.ts | 2 +- libs/skeleton/src/executors/list.executor.ts | 2 +- libs/skeleton/src/executors/pagination.executor.ts | 2 +- libs/skeleton/src/executors/read.executor.ts | 2 +- libs/skeleton/src/executors/update.executor.ts | 2 +- libs/skeleton/src/processes/default.process.ts | 13 +++++++------ libs/skeleton/src/skeleton-crud.controller.ts | 6 +++--- 17 files changed, 28 insertions(+), 27 deletions(-) diff --git a/libs/prisma/src/interfaces/config-module-options.interface.ts b/libs/prisma/src/interfaces/config-module-options.interface.ts index 1cd667f..7c8abba 100644 --- a/libs/prisma/src/interfaces/config-module-options.interface.ts +++ b/libs/prisma/src/interfaces/config-module-options.interface.ts @@ -9,7 +9,7 @@ import { import { PrismaListProcess } from '../processes/list.process'; export interface PrismaModuleOptions { - delegate: (prisma: PrismaService) => any; + delegate: (prisma: PrismaService) => unknown; processCreate?: typeof PrismaCreateProcess; processDelete?: typeof PrismaDeleteProcess; processList?: typeof PrismaListProcess; diff --git a/libs/prisma/src/prisma.module.ts b/libs/prisma/src/prisma.module.ts index cdf20f3..eae0def 100644 --- a/libs/prisma/src/prisma.module.ts +++ b/libs/prisma/src/prisma.module.ts @@ -34,7 +34,7 @@ import { PrismaListProcess } from './processes/list.process'; ], }) export class PrismaModule extends ConfigurableModuleClass { - private static autoPresetProvider(providers, option, key, preset): any { + private static autoPresetProvider(providers, option, key, preset) { if (option) { providers = [ ...providers, diff --git a/libs/prisma/src/processes/create.process.ts b/libs/prisma/src/processes/create.process.ts index 4640344..8c350ba 100644 --- a/libs/prisma/src/processes/create.process.ts +++ b/libs/prisma/src/processes/create.process.ts @@ -7,7 +7,7 @@ export class PrismaCreateProcess { public payload; - async process(): Promise { + async process() { this.result = await this.getDelegate().create({ data: this.payload, }); diff --git a/libs/prisma/src/processes/delete.process.ts b/libs/prisma/src/processes/delete.process.ts index 85acc0d..3b68fae 100644 --- a/libs/prisma/src/processes/delete.process.ts +++ b/libs/prisma/src/processes/delete.process.ts @@ -5,9 +5,9 @@ export class PrismaDeleteProcess extends PrismaProcess implements DeleteProcess { - public identity: any; + public identity; - async process(): Promise { + async process() { this.result = await this.getDelegate().delete({ where: { id: this.identity }, }); diff --git a/libs/prisma/src/processes/list.process.ts b/libs/prisma/src/processes/list.process.ts index f8dd62a..1ffe43f 100644 --- a/libs/prisma/src/processes/list.process.ts +++ b/libs/prisma/src/processes/list.process.ts @@ -2,7 +2,7 @@ import { ListProcess } from '@aditama-labs/nest-autocrud/skeleton'; import { PrismaProcess } from './prisma.process'; export class PrismaListProcess extends PrismaProcess implements ListProcess { - async process(): Promise { + async process() { this.result = await this.getDelegate().findMany(); } } diff --git a/libs/prisma/src/processes/pagination.process.ts b/libs/prisma/src/processes/pagination.process.ts index 8c0c32d..07cc670 100644 --- a/libs/prisma/src/processes/pagination.process.ts +++ b/libs/prisma/src/processes/pagination.process.ts @@ -8,7 +8,7 @@ export class PrismaPaginationProcess { params: IPaginationParam; - async process(): Promise { + async process() { const { page, limit } = this.params; const skip = (page - 1) * limit; diff --git a/libs/prisma/src/processes/read.process.ts b/libs/prisma/src/processes/read.process.ts index a7c4020..d1010b8 100644 --- a/libs/prisma/src/processes/read.process.ts +++ b/libs/prisma/src/processes/read.process.ts @@ -4,7 +4,7 @@ import { PrismaProcess } from './prisma.process'; export class PrismaReadProcess extends PrismaProcess implements ReadProcess { public identity; - async process(): Promise { + async process() { this.result = await this.getDelegate().findUnique({ where: { id: this.identity }, }); diff --git a/libs/prisma/src/processes/update.process.ts b/libs/prisma/src/processes/update.process.ts index ef5457b..14f9f28 100644 --- a/libs/prisma/src/processes/update.process.ts +++ b/libs/prisma/src/processes/update.process.ts @@ -5,10 +5,10 @@ export class PrismaUpdateProcess extends PrismaProcess implements UpdateProcess { - public identity: any; - public payload: any; + public identity; + public payload; - async process(): Promise { + async process() { this.result = await this.getDelegate().update({ data: this.payload, where: { id: this.identity }, diff --git a/libs/skeleton/src/executors/create.executor.ts b/libs/skeleton/src/executors/create.executor.ts index 611fe39..7e932a5 100644 --- a/libs/skeleton/src/executors/create.executor.ts +++ b/libs/skeleton/src/executors/create.executor.ts @@ -8,7 +8,7 @@ export class CreateExcutor extends DefaultExecutor { process.payload = data; } - static async bootstrap(process: CreateProcess, data): Promise { + static async bootstrap(process: CreateProcess, data) { const executor = new CreateExcutor(process, data); await executor.execute(); return executor.getOutput(); diff --git a/libs/skeleton/src/executors/default.executor.ts b/libs/skeleton/src/executors/default.executor.ts index 016d75a..016ac1e 100644 --- a/libs/skeleton/src/executors/default.executor.ts +++ b/libs/skeleton/src/executors/default.executor.ts @@ -12,7 +12,7 @@ export class DefaultExecutor { await this.process.after(); } - getOutput(): any { + getOutput() { return this.process.output(); } } diff --git a/libs/skeleton/src/executors/delete.executor.ts b/libs/skeleton/src/executors/delete.executor.ts index c7a7fda..5b2d084 100644 --- a/libs/skeleton/src/executors/delete.executor.ts +++ b/libs/skeleton/src/executors/delete.executor.ts @@ -9,7 +9,7 @@ export class DeleteExecutor extends DefaultExecutor { process.identity = id; } - static async bootstrap(process: DeleteProcess, id): Promise { + static async bootstrap(process: DeleteProcess, id) { const executor = new DeleteExecutor(process, id); await executor.execute(); return executor.getOutput(); diff --git a/libs/skeleton/src/executors/list.executor.ts b/libs/skeleton/src/executors/list.executor.ts index 6102540..f829274 100644 --- a/libs/skeleton/src/executors/list.executor.ts +++ b/libs/skeleton/src/executors/list.executor.ts @@ -6,7 +6,7 @@ export class ListExecutor extends DefaultExecutor { super(process); } - static async bootstrap(process: ListProcess): Promise { + static async bootstrap(process: ListProcess) { const executor = new ListExecutor(process); await executor.execute(); return executor.getOutput(); diff --git a/libs/skeleton/src/executors/pagination.executor.ts b/libs/skeleton/src/executors/pagination.executor.ts index fbde373..325f794 100644 --- a/libs/skeleton/src/executors/pagination.executor.ts +++ b/libs/skeleton/src/executors/pagination.executor.ts @@ -12,7 +12,7 @@ export class PaginationExecutor extends DefaultExecutor { static async bootstrap( process: PaginationProcess, params: PaginationParamDTO, - ): Promise { + ) { const executor = new PaginationExecutor(process, params); await executor.execute(); return executor.getOutput(); diff --git a/libs/skeleton/src/executors/read.executor.ts b/libs/skeleton/src/executors/read.executor.ts index beda8c9..19be374 100644 --- a/libs/skeleton/src/executors/read.executor.ts +++ b/libs/skeleton/src/executors/read.executor.ts @@ -8,7 +8,7 @@ export class ReadExecutor extends DefaultExecutor { process.identity = id; } - static async bootstrap(process: ReadProcess, id): Promise { + static async bootstrap(process: ReadProcess, id) { const executor = new ReadExecutor(process, id); await executor.execute(); return executor.getOutput(); diff --git a/libs/skeleton/src/executors/update.executor.ts b/libs/skeleton/src/executors/update.executor.ts index ce94f97..891b74c 100644 --- a/libs/skeleton/src/executors/update.executor.ts +++ b/libs/skeleton/src/executors/update.executor.ts @@ -10,7 +10,7 @@ export class UpdateExecutor extends DefaultExecutor { process.payload = data; } - static async bootstrap(process: UpdateProcess, id, data): Promise { + static async bootstrap(process: UpdateProcess, id, data) { const executor = new UpdateExecutor(process, id, data); await executor.execute(); return executor.getOutput(); diff --git a/libs/skeleton/src/processes/default.process.ts b/libs/skeleton/src/processes/default.process.ts index 075c676..ac96c55 100644 --- a/libs/skeleton/src/processes/default.process.ts +++ b/libs/skeleton/src/processes/default.process.ts @@ -3,12 +3,13 @@ import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; export class DefaultProcess implements ISkeletonProcess { protected result; - async initialization(): Promise {} - async before(): Promise {} - async begin(): Promise {} - async process(): Promise {} - async end(): Promise {} - async after(): Promise {} + // @TODO: Soon it will conver to abstract, for now I just set as regular class for simplicity and making developer optionally override it instead of force it + async initialization() {} + async before() {} + async begin() {} + async process() {} + async end() {} + async after() {} output() { return this.result; diff --git a/libs/skeleton/src/skeleton-crud.controller.ts b/libs/skeleton/src/skeleton-crud.controller.ts index 031b08a..f0469a7 100644 --- a/libs/skeleton/src/skeleton-crud.controller.ts +++ b/libs/skeleton/src/skeleton-crud.controller.ts @@ -45,7 +45,7 @@ export class SkeletonCRUDController implements ISkeletonCRUDController { ) {} @Post() - async create(@Body() body): Promise { + async create(@Body() body) { return await CreateExcutor.bootstrap(this.createProcess, body); } @@ -77,7 +77,7 @@ export class SkeletonCRUDController implements ISkeletonCRUDController { } // NOTES: -// - This method only works when return as `any` +// - This method only works when return as `any` or not define the type at all // - I know this is not recommended but.... is there any way to pass custom unique identifier ? // - Everyone still can use SkeletonCRUDController with no issue if don't want or don't like this approach, but... unique identifier must ID for sure and the type should either UUID, String or Number // - Correct me if I wrong. I already read the main repository of NestJS and they use Reflect for passing some metadata ( I know how to do it ) but... it still not possible for dynamic unique identifier @@ -89,7 +89,7 @@ export const CustomCRUDController = (options?: ControllerOption) => { class WrapperCRUDController extends SkeletonCRUDController { @Post() - async create(@Body() body): Promise { + async create(@Body() body) { return await super.create(body); }