wip: typesafety for id type

This commit is contained in:
Supan Adit Pratama 2024-10-26 18:21:21 +07:00
parent ce6cc37650
commit 6fa469f5d7
2 changed files with 6 additions and 4 deletions

View File

@ -1,8 +1,8 @@
import { IPaginationEntity } from '@autocrud/skeleton/entities/pagination.entity'; import { IPaginationEntity } from '@autocrud/skeleton/entities/pagination.entity';
export interface ISkeletonCRUDController<T> { export interface ISkeletonCRUDController<T, E> {
create(): Promise<T>; create(): Promise<T>;
readSelected(id): Promise<T>; readSelected(id: E): Promise<T>;
readPagination(): Promise<IPaginationEntity<T>>; readPagination(): Promise<IPaginationEntity<T>>;
readEntire(): Promise<T[]>; readEntire(): Promise<T[]>;
updatePartial(): Promise<T>; updatePartial(): Promise<T>;

View File

@ -2,14 +2,16 @@ import { Delete, Get, Param, Patch, Post, Put } from '@nestjs/common';
import { ISkeletonCRUDController } from './interfaces/controller/skeleton-crud.controller.interface'; import { ISkeletonCRUDController } from './interfaces/controller/skeleton-crud.controller.interface';
import { IPaginationEntity } from './entities/pagination.entity'; import { IPaginationEntity } from './entities/pagination.entity';
export class SkeletonCRUDController<T> implements ISkeletonCRUDController<T> { export class SkeletonCRUDController<T, E>
implements ISkeletonCRUDController<T, E>
{
@Post() @Post()
async create(): Promise<T> { async create(): Promise<T> {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
@Get(':id') @Get(':id')
async readSelected(@Param('id') id): Promise<T> { async readSelected(@Param('id') id: E): Promise<T> {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }