diff --git a/src/modules/score/score.controller.ts b/src/modules/score/score.controller.ts index 3ba6542..7738d9c 100644 --- a/src/modules/score/score.controller.ts +++ b/src/modules/score/score.controller.ts @@ -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); diff --git a/src/modules/score/score.validation.ts b/src/modules/score/score.validation.ts index 7d9b4fb..9535d92 100644 --- a/src/modules/score/score.validation.ts +++ b/src/modules/score/score.validation.ts @@ -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(), diff --git a/src/routes/v1/score.route.ts b/src/routes/v1/score.route.ts index 09bbf01..dc55deb 100644 --- a/src/routes/v1/score.route.ts +++ b/src/routes/v1/score.route.ts @@ -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