wip: working with type safety

This commit is contained in:
Supan Adit Pratama 2024-10-26 18:19:41 +07:00
parent 20aaf2a2d7
commit ce6cc37650
4 changed files with 66 additions and 30 deletions

View File

@ -0,0 +1,13 @@
export interface IPaginationEntity<T> {
// Data related
data: T[];
totalData: number;
// Page related
totalPage: number;
currentPage: number;
lastPage: number;
perPage: number;
nextPage: number | null;
previousPage: number | null;
}

View File

@ -1,12 +1,14 @@
export interface ISkeletonCRUDController {
create();
readSelected(id);
readPagination();
readEntire();
updatePartial();
updatePartialBatch();
updateEntire();
updateEntirePatch();
deleteSelected();
deleteBatch();
import { IPaginationEntity } from '@autocrud/skeleton/entities/pagination.entity';
export interface ISkeletonCRUDController<T> {
create(): Promise<T>;
readSelected(id): Promise<T>;
readPagination(): Promise<IPaginationEntity<T>>;
readEntire(): Promise<T[]>;
updatePartial(): Promise<T>;
updatePartialBatch(): Promise<T[]>;
updateEntire(): Promise<T>;
updateEntireBatch(): Promise<T[]>;
deleteSelected(): Promise<T>;
deleteBatch(): Promise<T[]>;
}

View File

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

View File

@ -1,34 +1,55 @@
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';
export class SkeletonCRUDController implements ISkeletonCRUDController {
export class SkeletonCRUDController<T> implements ISkeletonCRUDController<T> {
@Post()
create() {}
async create(): Promise<T> {
throw new Error('Method not implemented.');
}
@Get(':id')
readSelected(@Param('id') id) {}
async readSelected(@Param('id') id): Promise<T> {
throw new Error('Method not implemented.');
}
@Get()
readPagination() {}
async readPagination(): Promise<IPaginationEntity<T>> {
throw new Error('Method not implemented.');
}
@Get('list')
readEntire() {}
async readEntire(): Promise<T[]> {
throw new Error('Method not implemented.');
}
@Patch()
updatePartial() {}
async updatePartial(): Promise<T> {
throw new Error('Method not implemented.');
}
@Patch('batch')
updatePartialBatch() {}
async updatePartialBatch(): Promise<T[]> {
throw new Error('Method not implemented.');
}
@Put()
updateEntire() {}
async updateEntire(): Promise<T> {
throw new Error('Method not implemented.');
}
@Put('batch')
updateEntirePatch() {}
async updateEntireBatch(): Promise<T[]> {
throw new Error('Method not implemented.');
}
@Delete()
deleteSelected() {}
async deleteSelected(): Promise<T> {
throw new Error('Method not implemented.');
}
@Delete('batch')
deleteBatch() {}
async deleteBatch(): Promise<T[]> {
throw new Error('Method not implemented.');
}
}