From f697747124c3510ad09657b725dbc284bd5694f5 Mon Sep 17 00:00:00 2001 From: andres Date: Wed, 12 Jun 2024 12:08:36 +0200 Subject: [PATCH] chore: update cardsOrderByEnum --- src/modules/cards/dto/get-all-cards.dto.ts | 30 +++++++++++++++++-- .../cards/infrastructure/cards.repository.ts | 4 +-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/modules/cards/dto/get-all-cards.dto.ts b/src/modules/cards/dto/get-all-cards.dto.ts index 9f14a1a..a8bf876 100644 --- a/src/modules/cards/dto/get-all-cards.dto.ts +++ b/src/modules/cards/dto/get-all-cards.dto.ts @@ -1,8 +1,23 @@ -import { Length } from 'class-validator' +import { ApiProperty } from '@nestjs/swagger' +import { IsEnum, IsOptional, Length } from 'class-validator' import { PaginationDto } from '../../../infrastructure/common/pagination/pagination.dto' import { IsOptionalOrEmptyString, IsOrderBy } from '../../../infrastructure/decorators' +export enum CardsOrderBy { + 'null' = 'null', + 'question-asc' = 'question-asc', + 'question-desc' = 'question-desc', + 'answer-asc' = 'answer-asc', + 'answer-desc' = 'answer-desc', + 'created-asc' = 'created-asc', + 'created-desc' = 'created-desc', + 'grade-asc' = 'grade-asc', + 'grade-desc' = 'grade-desc', + 'updated-asc' = 'updated-asc', + 'updated-desc' = 'updated-desc', +} + export class GetAllCardsInDeckDto extends PaginationDto { @IsOptionalOrEmptyString() @Length(1, 30) @@ -12,6 +27,17 @@ export class GetAllCardsInDeckDto extends PaginationDto { @Length(1, 30) answer?: string + /** A string that represents the name of the field to order by and the order direction. + * The format is: "field_name-order_direction". + * Available directions: "asc" and "desc". + * @example "grade-desc" + * */ @IsOrderBy() - orderBy?: string | null + @ApiProperty({ + enum: CardsOrderBy, + required: false, + }) + @IsOptional() + @IsEnum(CardsOrderBy, {}) + orderBy?: CardsOrderBy } diff --git a/src/modules/cards/infrastructure/cards.repository.ts b/src/modules/cards/infrastructure/cards.repository.ts index 08f5153..bd6e20b 100644 --- a/src/modules/cards/infrastructure/cards.repository.ts +++ b/src/modules/cards/infrastructure/cards.repository.ts @@ -7,7 +7,7 @@ import { } from '../../../infrastructure/common/helpers/get-order-by-object' import { Pagination } from '../../../infrastructure/common/pagination/pagination.service' import { PrismaService } from '../../../prisma.service' -import { CreateCardDto, GetAllCardsInDeckDto, UpdateCardDto } from '../dto' +import { CardsOrderBy, CreateCardDto, GetAllCardsInDeckDto, UpdateCardDto } from '../dto' import { CardWithGrades, PaginatedCardsWithGrades } from '../entities/cards.entity' @Injectable() @@ -52,7 +52,7 @@ export class CardsRepository { }: GetAllCardsInDeckDto ): Promise { if (!orderBy || orderBy === 'null') { - orderBy = 'updated-desc' + orderBy = CardsOrderBy['updated-desc'] } try { const where = {