diff --git a/src/shared/presenter/interfaces/paginated-view-model.interface.ts b/src/shared/presenter/interfaces/paginated-view-model.interface.ts new file mode 100644 index 0000000..60d29f8 --- /dev/null +++ b/src/shared/presenter/interfaces/paginated-view-model.interface.ts @@ -0,0 +1,30 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { PaginatedEntities } from '@shared/infra/database/interfaces/paginated-entities.interface'; + +type ViewModelConstructor = { + new (entity: TEntity): TViewModel; +}; + +export class PaginatedViewModel { + constructor( + { page, totalPageCount, pageLimit, entities }: PaginatedEntities, + viewModel: ViewModelConstructor, + ) { + this.page = page; + this.totalPageCount = totalPageCount; + this.pageLimit = pageLimit; + this.items = entities.map((entity) => new viewModel(entity)); + } + + @ApiProperty() + page: number; + + @ApiProperty() + totalPageCount: number; + + @ApiProperty() + pageLimit: number; + + @ApiProperty() + items: TViewModel[]; +}