Skip to content

Commit

Permalink
feat(shared): adding paginated view mmodel interface
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardodimarchi committed Oct 13, 2023
1 parent a1a7b90 commit 1d5cd88
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/shared/presenter/interfaces/paginated-view-model.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ApiProperty } from '@nestjs/swagger';
import { PaginatedEntities } from '@shared/infra/database/interfaces/paginated-entities.interface';

type ViewModelConstructor<TEntity, TViewModel> = {
new (entity: TEntity): TViewModel;
};

export class PaginatedViewModel<TEntity, TViewModel> {
constructor(
{ page, totalPageCount, pageLimit, entities }: PaginatedEntities<TEntity>,
viewModel: ViewModelConstructor<TEntity, TViewModel>,
) {
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[];
}

0 comments on commit 1d5cd88

Please sign in to comment.