Skip to content

fix(Filters): In search API #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ workflows:
- develop
- feat/ai-workflows
- feat/scorecards
- filters-fix
- 'build-prod':
context: org-global
filters:
Expand Down
25 changes: 25 additions & 0 deletions src/api/scorecard/scorecard.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import { ChallengeTrack } from 'src/shared/enums/challengeTrack.enum';
import { ScoreCardService } from './scorecard.service';
import { PaginationHeaderInterceptor } from 'src/interceptors/PaginationHeaderInterceptor';
import { $Enums } from '@prisma/client';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming $Enums to a more descriptive name that reflects its purpose or the specific enums being imported. This will improve code readability and maintainability.


@ApiTags('Scorecard')
@ApiBearerAuth()
Expand Down Expand Up @@ -152,6 +153,18 @@ export class ScorecardController {
example: 'Hackathon',
required: false,
})
@ApiQuery({
name: 'scorecardType',
description: 'The scorecard type to filter by',
example: 'SCREENING',
required: false,
})
@ApiQuery({
name: 'status',
description: 'The status to filter by',
example: 'ACTIVE',
required: false,
})
@ApiQuery({
name: 'name',
description: 'The challenge name to filter by (partial match)',
Expand Down Expand Up @@ -181,6 +194,9 @@ export class ScorecardController {
async searchScorecards(
@Query('challengeTrack') challengeTrack?: ChallengeTrack | ChallengeTrack[],
@Query('challengeType') challengeType?: string | string[],
@Query('status') status?: $Enums.ScorecardStatus | $Enums.ScorecardStatus[],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider checking if $Enums.ScorecardStatus is correctly imported and defined, as it is being used here for the status query parameter.

@Query('scorecardType')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that $Enums.ScorecardType is properly imported and defined, as it is being used for the scorecardType query parameter.

scorecardType?: $Enums.ScorecardType | $Enums.ScorecardType[],
@Query('name') name?: string,
@Query('page') page: number = 1,
@Query('perPage') perPage: number = 10,
Expand All @@ -195,12 +211,21 @@ export class ScorecardController {
: challengeType
? [challengeType]
: [];
const scorecardTypesArray = Array.isArray(scorecardType)
? scorecardType
: scorecardType
? [scorecardType]
: [];
const statusArray = Array.isArray(status) ? status : status ? [status] : [];

const result = await this.scorecardService.getScoreCards({
challengeTrack: challengeTrackArray,
challengeType: challengeTypeArray,
name,
page,
perPage,
scorecardTypesArray,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property name scorecardTypesArray should be passed as scorecardType to match the expected parameter name in the getScoreCards method, unless the method signature has been updated to expect scorecardTypesArray.

statusArray,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property name statusArray should be passed as status to match the expected parameter name in the getScoreCards method, unless the method signature has been updated to expect statusArray.

});
return result;
}
Expand Down
12 changes: 12 additions & 0 deletions src/api/scorecard/scorecard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ export class ScoreCardService {
perPage = 10,
challengeTrack,
challengeType,
scorecardTypesArray,
statusArray,
name,
} = query;
const skip = (page - 1) * perPage;
Expand All @@ -161,6 +163,16 @@ export class ScoreCardService {
in: challengeType,
},
}),
...(scorecardTypesArray?.length && {
type: {
in: scorecardTypesArray,
},
}),
...(statusArray?.length && {
status: {
in: statusArray,
},
}),
...(name && { name: { contains: name, mode: 'insensitive' } }),
};
const data = await this.prisma.scorecard.findMany({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the commented-out console.log statement. Leaving commented-out code can clutter the codebase and is generally not recommended unless it serves a specific purpose, such as documentation or a temporary workaround.

Expand Down
3 changes: 3 additions & 0 deletions src/dto/scorecard.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { $Enums } from '@prisma/client';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider importing only the necessary enums from @prisma/client to avoid importing unused code. This can help reduce the bundle size and improve performance.


export enum ScorecardStatus {
ACTIVE = 'ACTIVE',
Expand Down Expand Up @@ -267,6 +268,8 @@ export class ScorecardQueryDto {
name?: string;
page?: number;
perPage?: number;
statusArray?: $Enums.ScorecardStatus[];
scorecardTypesArray?: $Enums.ScorecardType[];
}

export function mapScorecardRequestToDto(request: ScorecardRequestDto) {
Expand Down