-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(game-history): add limit and order to get game history endpoint (#…
…532)
- Loading branch information
1 parent
abdf8a1
commit 6bdb566
Showing
15 changed files
with
19,919 additions
and
19,694 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/modules/game/dto/get-game-history/get-game-history.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ApiProperty } from "@nestjs/swagger"; | ||
import { IsEnum, IsInt, IsOptional, Min } from "class-validator"; | ||
import { Type } from "class-transformer"; | ||
|
||
import { ApiSortOrder } from "@/shared/api/enums/api.enum"; | ||
|
||
class GetGameHistoryDto { | ||
@ApiProperty({ | ||
description: "Number of returned game's history records. `0` means no limit", | ||
minimum: 0, | ||
required: false, | ||
}) | ||
@IsOptional() | ||
@Type(() => Number) | ||
@IsInt() | ||
@Min(0) | ||
public limit: number = 0; | ||
|
||
@ApiProperty({ | ||
description: "Sorting order of returned game's history records by creation date. `asc` means from oldest to newest, `desc` means from newest to oldest", | ||
required: false, | ||
}) | ||
@IsOptional() | ||
@IsEnum(ApiSortOrder) | ||
public order: ApiSortOrder = ApiSortOrder.ASC; | ||
} | ||
|
||
export { GetGameHistoryDto }; |
14 changes: 14 additions & 0 deletions
14
src/modules/game/helpers/game-history/game-history-record.mapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { QueryOptions } from "mongoose"; | ||
|
||
import type { GetGameHistoryDto } from "@/modules/game/dto/get-game-history/get-game-history.dto"; | ||
|
||
import { getMongooseSortValueFromApiSortOrder } from "@/shared/mongoose/helpers/mongoose.helper"; | ||
|
||
function convertGetGameHistoryDtoToMongooseQueryOptions(getGameHistoryDto: GetGameHistoryDto): QueryOptions { | ||
return { | ||
limit: getGameHistoryDto.limit, | ||
sort: { createdAt: getMongooseSortValueFromApiSortOrder(getGameHistoryDto.order) }, | ||
}; | ||
} | ||
|
||
export { convertGetGameHistoryDtoToMongooseQueryOptions }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { ApiSortOrder } from "@/shared/api/enums/api.enum"; | ||
|
||
function getMongooseSortValueFromApiSortOrder(sortOrder: ApiSortOrder): number { | ||
return sortOrder === ApiSortOrder.ASC ? 1 : -1; | ||
} | ||
|
||
export { getMongooseSortValueFromApiSortOrder }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.