From c6a4763d40b16a3454255518a0c5529bf50d28f8 Mon Sep 17 00:00:00 2001 From: Supan Adit Pratama Date: Sat, 26 Oct 2024 19:01:45 +0700 Subject: [PATCH] wip: base process --- .../interfaces/skeleton-process.interface.ts | 16 ++--- .../src/processes/batch/delete.process.ts | 14 ++++- .../src/processes/batch/update.process.ts | 14 ++++- libs/skeleton/src/processes/create.process.ts | 37 +++--------- libs/skeleton/src/processes/delete.process.ts | 12 +++- libs/skeleton/src/processes/list.process.ts | 12 +++- .../src/processes/pagination.process.ts | 12 +++- .../processes/partial/batch/update.process.ts | 14 ++++- libs/skeleton/src/processes/read.process.ts | 12 +++- libs/skeleton/src/processes/update.process.ts | 12 +++- libs/skeleton/src/skeleton-crud.controller.ts | 59 +++++++++++++++---- 11 files changed, 157 insertions(+), 57 deletions(-) diff --git a/libs/skeleton/src/interfaces/skeleton-process.interface.ts b/libs/skeleton/src/interfaces/skeleton-process.interface.ts index 6370de0..181f4bd 100644 --- a/libs/skeleton/src/interfaces/skeleton-process.interface.ts +++ b/libs/skeleton/src/interfaces/skeleton-process.interface.ts @@ -1,10 +1,10 @@ -import { Observable } from 'rxjs'; +export interface ISkeletonProcess { + initialization(): T; + before(): T; + begin(): T; + process(): T; + end(): T; + after(): T; -export interface SkeletonProcess { - initialization(): Observable; - before(): Observable; - begin(): Observable; - process(): Observable; - end(): Observable; - after(): Observable; + result(): R; } diff --git a/libs/skeleton/src/processes/batch/delete.process.ts b/libs/skeleton/src/processes/batch/delete.process.ts index 32c39f2..568ec81 100644 --- a/libs/skeleton/src/processes/batch/delete.process.ts +++ b/libs/skeleton/src/processes/batch/delete.process.ts @@ -1 +1,13 @@ -export class BatchDeleteProcess {} +import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface'; + +export abstract class BatchDeleteProcess + implements ISkeletonProcess +{ + abstract initialization(): T; + abstract before(): T; + abstract begin(): T; + abstract process(): T; + abstract end(): T; + abstract after(): T; + abstract result(): R; +} diff --git a/libs/skeleton/src/processes/batch/update.process.ts b/libs/skeleton/src/processes/batch/update.process.ts index b251550..6e1f0f6 100644 --- a/libs/skeleton/src/processes/batch/update.process.ts +++ b/libs/skeleton/src/processes/batch/update.process.ts @@ -1 +1,13 @@ -export class BatchUpdateProcess {} +import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface'; + +export abstract class BatchUpdateProcess + implements ISkeletonProcess +{ + abstract initialization(): T; + abstract before(): T; + abstract begin(): T; + abstract process(): T; + abstract end(): T; + abstract after(): T; + abstract result(): R; +} diff --git a/libs/skeleton/src/processes/create.process.ts b/libs/skeleton/src/processes/create.process.ts index df0e891..325a17c 100644 --- a/libs/skeleton/src/processes/create.process.ts +++ b/libs/skeleton/src/processes/create.process.ts @@ -1,30 +1,11 @@ -import { Observable, of } from 'rxjs'; -import { SkeletonProcess } from '../interfaces/skeleton-process.interface'; +import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; -export class CreateProcess implements SkeletonProcess { - constructor() {} - - initialization(): Observable { - return of(undefined); - } - - before(): Observable { - return of(undefined); - } - - begin(): Observable { - return of(undefined); - } - - process(): Observable { - return of(undefined); - } - - end(): Observable { - return of(undefined); - } - - after(): Observable { - return of(undefined); - } +export abstract class CreateProcess implements ISkeletonProcess { + abstract initialization(): T; + abstract before(): T; + abstract begin(): T; + abstract process(): T; + abstract end(): T; + abstract after(): T; + abstract result(): R; } diff --git a/libs/skeleton/src/processes/delete.process.ts b/libs/skeleton/src/processes/delete.process.ts index 1638463..cd4cd23 100644 --- a/libs/skeleton/src/processes/delete.process.ts +++ b/libs/skeleton/src/processes/delete.process.ts @@ -1 +1,11 @@ -export class DeleteProcess {} +import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; + +export abstract class DeleteProcess implements ISkeletonProcess { + abstract initialization(): T; + abstract before(): T; + abstract begin(): T; + abstract process(): T; + abstract end(): T; + abstract after(): T; + abstract result(): R; +} diff --git a/libs/skeleton/src/processes/list.process.ts b/libs/skeleton/src/processes/list.process.ts index cc508c3..fbdbe9b 100644 --- a/libs/skeleton/src/processes/list.process.ts +++ b/libs/skeleton/src/processes/list.process.ts @@ -1 +1,11 @@ -export class ListProcess {} +import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; + +export abstract class ListProcess implements ISkeletonProcess { + abstract initialization(): T; + abstract before(): T; + abstract begin(): T; + abstract process(): T; + abstract end(): T; + abstract after(): T; + abstract result(): R; +} diff --git a/libs/skeleton/src/processes/pagination.process.ts b/libs/skeleton/src/processes/pagination.process.ts index 155f496..4d19ebb 100644 --- a/libs/skeleton/src/processes/pagination.process.ts +++ b/libs/skeleton/src/processes/pagination.process.ts @@ -1 +1,11 @@ -export class PaginationProcess {} +import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; + +export abstract class PaginationProcess implements ISkeletonProcess { + abstract initialization(): T; + abstract before(): T; + abstract begin(): T; + abstract process(): T; + abstract end(): T; + abstract after(): T; + abstract result(): R; +} diff --git a/libs/skeleton/src/processes/partial/batch/update.process.ts b/libs/skeleton/src/processes/partial/batch/update.process.ts index 9040acd..0de9f99 100644 --- a/libs/skeleton/src/processes/partial/batch/update.process.ts +++ b/libs/skeleton/src/processes/partial/batch/update.process.ts @@ -1 +1,13 @@ -export class PartialBatchUpdateProcess {} +import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface'; + +export abstract class PartialBatchUpdateProcess + implements ISkeletonProcess +{ + abstract initialization(): T; + abstract before(): T; + abstract begin(): T; + abstract process(): T; + abstract end(): T; + abstract after(): T; + abstract result(): R; +} diff --git a/libs/skeleton/src/processes/read.process.ts b/libs/skeleton/src/processes/read.process.ts index 87bf2a9..9420d71 100644 --- a/libs/skeleton/src/processes/read.process.ts +++ b/libs/skeleton/src/processes/read.process.ts @@ -1 +1,11 @@ -export class ReadProcess {} +import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; + +export abstract class ReadProcess implements ISkeletonProcess { + abstract initialization(): T; + abstract before(): T; + abstract begin(): T; + abstract process(): T; + abstract end(): T; + abstract after(): T; + abstract result(): R; +} diff --git a/libs/skeleton/src/processes/update.process.ts b/libs/skeleton/src/processes/update.process.ts index 0084c1a..552c6c4 100644 --- a/libs/skeleton/src/processes/update.process.ts +++ b/libs/skeleton/src/processes/update.process.ts @@ -1 +1,11 @@ -export class UpdateProcess {} +import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; + +export abstract class UpdateProcess implements ISkeletonProcess { + abstract initialization(): T; + abstract before(): T; + abstract begin(): T; + abstract process(): T; + abstract end(): T; + abstract after(): T; + abstract result(): R; +} diff --git a/libs/skeleton/src/skeleton-crud.controller.ts b/libs/skeleton/src/skeleton-crud.controller.ts index 3e9be38..99615cc 100644 --- a/libs/skeleton/src/skeleton-crud.controller.ts +++ b/libs/skeleton/src/skeleton-crud.controller.ts @@ -1,57 +1,90 @@ import { Delete, Get, Param, Patch, Post, Put } from '@nestjs/common'; -import { ISkeletonCRUDController } from './interfaces/controller/skeleton-crud.controller.interface'; import { IPaginationEntity } from './entities/pagination.entity'; +import { ISkeletonCRUDController } from './interfaces/controller/skeleton-crud.controller.interface'; +import { BatchDeleteProcess } from './processes/batch/delete.process'; +import { BatchUpdateProcess } from './processes/batch/update.process'; +import { CreateProcess } from './processes/create.process'; +import { DeleteProcess } from './processes/delete.process'; +import { ListProcess } from './processes/list.process'; +import { PaginationProcess } from './processes/pagination.process'; +import { PartialBatchUpdateProcess } from './processes/partial/batch/update.process'; +import { ReadProcess } from './processes/read.process'; +import { UpdateProcess } from './processes/update.process'; -export class SkeletonCRUDController - implements ISkeletonCRUDController +export class SkeletonCRUDController< + T, + E, + CP extends CreateProcess, + RSP extends ReadProcess, + RPP extends PaginationProcess>, + REP extends ListProcess, + UPP extends UpdateProcess, + UBP extends PartialBatchUpdateProcess, + UEP extends UpdateProcess, + UEBP extends BatchUpdateProcess, + DP extends DeleteProcess, + DBP extends BatchDeleteProcess, +> implements ISkeletonCRUDController { + constructor( + private readonly createProcess: CP, + private readonly readProcess: RSP, + private readonly readPaginationProcess: RPP, + private readonly readEntireProcess: REP, + private readonly updatePartialProcess: UPP, + private readonly updateBatchProcess: UBP, + private readonly updateEntireProcess: UEP, + private readonly updateEntireBatchProcess: UEBP, + private readonly deleteProcess: DP, + private readonly deleteBatchProcess: DBP, + ) {} @Post() async create(): Promise { - throw new Error('Method not implemented.'); + return this.createProcess.result(); } @Get(':id') async readSelected(@Param('id') id: E): Promise { - throw new Error('Method not implemented.'); + return this.readProcess.result(); } @Get() async readPagination(): Promise> { - throw new Error('Method not implemented.'); + return this.readPaginationProcess.result(); } @Get('list') async readEntire(): Promise { - throw new Error('Method not implemented.'); + return this.readEntireProcess.result(); } @Patch() async updatePartial(): Promise { - throw new Error('Method not implemented.'); + return this.updatePartialProcess.result(); } @Patch('batch') async updatePartialBatch(): Promise { - throw new Error('Method not implemented.'); + return this.updateBatchProcess.result(); } @Put() async updateEntire(): Promise { - throw new Error('Method not implemented.'); + return this.updateEntireProcess.result(); } @Put('batch') async updateEntireBatch(): Promise { - throw new Error('Method not implemented.'); + return this.updateEntireBatchProcess.result(); } @Delete() async deleteSelected(): Promise { - throw new Error('Method not implemented.'); + return this.deleteProcess.result(); } @Delete('batch') async deleteBatch(): Promise { - throw new Error('Method not implemented.'); + return this.deleteBatchProcess.result(); } }