Skip to content

Commit

Permalink
Support filtering scores by a prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
4Ply committed Jan 12, 2025
1 parent 0cf0542 commit 81b118e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/modules/score/score.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ export const createScores = catchAsync(async (req: Request, res: Response) => {
});

export const getScores = catchAsync(async (req: Request, res: Response) => {
const filter = pick(req.query, ['player']);
const filter = pick(req.query, ['player', 'prefixFilter']);
if (filter.prefixFilter) {
filter.key = new RegExp(`^${filter.prefixFilter}`);
delete(filter.prefixFilter);
}

const options: IOptions = pick(req.query, ['sortBy', 'limit', 'page', 'projectBy']);
const result = await scoreService.queryScores(filter, options);
res.send(result);
Expand Down
1 change: 1 addition & 0 deletions src/modules/score/score.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const createScores = {
export const getScores = {
query: Joi.object().keys({
player: Joi.string().required(),
prefixFilter: Joi.string(),

sortBy: Joi.string(),
projectBy: Joi.string(),
Expand Down
5 changes: 5 additions & 0 deletions src/routes/v1/score.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export default router;
* type: string
* description: project by query in the form of field:hide/include (ex. name:hide)
* - in: query
* name: prefixFilter
* schema:
* type: string
* description: filter by prefix
* - in: query
* name: limit
* schema:
* type: integer
Expand Down

0 comments on commit 81b118e

Please sign in to comment.