mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-16 20:59:26 +00:00
chore: update cardsOrderByEnum
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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<PaginatedCardsWithGrades> {
|
||||
if (!orderBy || orderBy === 'null') {
|
||||
orderBy = 'updated-desc'
|
||||
orderBy = CardsOrderBy['updated-desc']
|
||||
}
|
||||
try {
|
||||
const where = {
|
||||
|
||||
Reference in New Issue
Block a user