wip: base process

This commit is contained in:
Supan Adit Pratama 2024-10-26 19:01:45 +07:00
parent 1a00f01d41
commit c6a4763d40
11 changed files with 157 additions and 57 deletions

View File

@ -1,10 +1,10 @@
import { Observable } from 'rxjs'; export interface ISkeletonProcess<T, R> {
initialization(): T;
before(): T;
begin(): T;
process(): T;
end(): T;
after(): T;
export interface SkeletonProcess { result(): R;
initialization(): Observable<void>;
before(): Observable<void>;
begin(): Observable<void>;
process(): Observable<void>;
end(): Observable<void>;
after(): Observable<void>;
} }

View File

@ -1 +1,13 @@
export class BatchDeleteProcess {} import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface';
export abstract class BatchDeleteProcess<T, R>
implements ISkeletonProcess<T, R>
{
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
abstract process(): T;
abstract end(): T;
abstract after(): T;
abstract result(): R;
}

View File

@ -1 +1,13 @@
export class BatchUpdateProcess {} import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface';
export abstract class BatchUpdateProcess<T, R>
implements ISkeletonProcess<T, R>
{
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
abstract process(): T;
abstract end(): T;
abstract after(): T;
abstract result(): R;
}

View File

@ -1,30 +1,11 @@
import { Observable, of } from 'rxjs'; import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
import { SkeletonProcess } from '../interfaces/skeleton-process.interface';
export class CreateProcess implements SkeletonProcess { export abstract class CreateProcess<T, R> implements ISkeletonProcess<T, R> {
constructor() {} abstract initialization(): T;
abstract before(): T;
initialization(): Observable<void> { abstract begin(): T;
return of(undefined); abstract process(): T;
} abstract end(): T;
abstract after(): T;
before(): Observable<void> { abstract result(): R;
return of(undefined);
}
begin(): Observable<void> {
return of(undefined);
}
process(): Observable<void> {
return of(undefined);
}
end(): Observable<void> {
return of(undefined);
}
after(): Observable<void> {
return of(undefined);
}
} }

View File

@ -1 +1,11 @@
export class DeleteProcess {} import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
export abstract class DeleteProcess<T, R> implements ISkeletonProcess<T, R> {
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
abstract process(): T;
abstract end(): T;
abstract after(): T;
abstract result(): R;
}

View File

@ -1 +1,11 @@
export class ListProcess {} import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
export abstract class ListProcess<T, R> implements ISkeletonProcess<T, R> {
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
abstract process(): T;
abstract end(): T;
abstract after(): T;
abstract result(): R;
}

View File

@ -1 +1,11 @@
export class PaginationProcess {} import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
export abstract class PaginationProcess<T, R> implements ISkeletonProcess<T, R> {
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
abstract process(): T;
abstract end(): T;
abstract after(): T;
abstract result(): R;
}

View File

@ -1 +1,13 @@
export class PartialBatchUpdateProcess {} import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface';
export abstract class PartialBatchUpdateProcess<T, R>
implements ISkeletonProcess<T, R>
{
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
abstract process(): T;
abstract end(): T;
abstract after(): T;
abstract result(): R;
}

View File

@ -1 +1,11 @@
export class ReadProcess {} import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
export abstract class ReadProcess<T, R> implements ISkeletonProcess<T, R> {
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
abstract process(): T;
abstract end(): T;
abstract after(): T;
abstract result(): R;
}

View File

@ -1 +1,11 @@
export class UpdateProcess {} import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
export abstract class UpdateProcess<T, R> implements ISkeletonProcess<T, R> {
abstract initialization(): T;
abstract before(): T;
abstract begin(): T;
abstract process(): T;
abstract end(): T;
abstract after(): T;
abstract result(): R;
}

View File

@ -1,57 +1,90 @@
import { Delete, Get, Param, Patch, Post, Put } from '@nestjs/common'; 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 { 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<T, E> export class SkeletonCRUDController<
implements ISkeletonCRUDController<T, E> T,
E,
CP extends CreateProcess<T, T>,
RSP extends ReadProcess<T, T>,
RPP extends PaginationProcess<T, IPaginationEntity<T>>,
REP extends ListProcess<T, T[]>,
UPP extends UpdateProcess<T, T>,
UBP extends PartialBatchUpdateProcess<T, T[]>,
UEP extends UpdateProcess<T, T>,
UEBP extends BatchUpdateProcess<T, T[]>,
DP extends DeleteProcess<T, T>,
DBP extends BatchDeleteProcess<T, T[]>,
> implements ISkeletonCRUDController<T, E>
{ {
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() @Post()
async create(): Promise<T> { async create(): Promise<T> {
throw new Error('Method not implemented.'); return this.createProcess.result();
} }
@Get(':id') @Get(':id')
async readSelected(@Param('id') id: E): Promise<T> { async readSelected(@Param('id') id: E): Promise<T> {
throw new Error('Method not implemented.'); return this.readProcess.result();
} }
@Get() @Get()
async readPagination(): Promise<IPaginationEntity<T>> { async readPagination(): Promise<IPaginationEntity<T>> {
throw new Error('Method not implemented.'); return this.readPaginationProcess.result();
} }
@Get('list') @Get('list')
async readEntire(): Promise<T[]> { async readEntire(): Promise<T[]> {
throw new Error('Method not implemented.'); return this.readEntireProcess.result();
} }
@Patch() @Patch()
async updatePartial(): Promise<T> { async updatePartial(): Promise<T> {
throw new Error('Method not implemented.'); return this.updatePartialProcess.result();
} }
@Patch('batch') @Patch('batch')
async updatePartialBatch(): Promise<T[]> { async updatePartialBatch(): Promise<T[]> {
throw new Error('Method not implemented.'); return this.updateBatchProcess.result();
} }
@Put() @Put()
async updateEntire(): Promise<T> { async updateEntire(): Promise<T> {
throw new Error('Method not implemented.'); return this.updateEntireProcess.result();
} }
@Put('batch') @Put('batch')
async updateEntireBatch(): Promise<T[]> { async updateEntireBatch(): Promise<T[]> {
throw new Error('Method not implemented.'); return this.updateEntireBatchProcess.result();
} }
@Delete() @Delete()
async deleteSelected(): Promise<T> { async deleteSelected(): Promise<T> {
throw new Error('Method not implemented.'); return this.deleteProcess.result();
} }
@Delete('batch') @Delete('batch')
async deleteBatch(): Promise<T[]> { async deleteBatch(): Promise<T[]> {
throw new Error('Method not implemented.'); return this.deleteBatchProcess.result();
} }
} }