-
Notifications
You must be signed in to change notification settings - Fork 6
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
||
@ApiTags('Scorecard') | ||
@ApiBearerAuth() | ||
|
@@ -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)', | ||
|
@@ -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[], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider checking if |
||
@Query('scorecardType') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that |
||
scorecardType?: $Enums.ScorecardType | $Enums.ScorecardType[], | ||
@Query('name') name?: string, | ||
@Query('page') page: number = 1, | ||
@Query('perPage') perPage: number = 10, | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The property name |
||
statusArray, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The property name |
||
}); | ||
return result; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,6 +147,8 @@ export class ScoreCardService { | |
perPage = 10, | ||
challengeTrack, | ||
challengeType, | ||
scorecardTypesArray, | ||
statusArray, | ||
name, | ||
} = query; | ||
const skip = (page - 1) * perPage; | ||
|
@@ -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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the commented-out |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { $Enums } from '@prisma/client'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider importing only the necessary enums from |
||
|
||
export enum ScorecardStatus { | ||
ACTIVE = 'ACTIVE', | ||
|
@@ -267,6 +268,8 @@ export class ScorecardQueryDto { | |
name?: string; | ||
page?: number; | ||
perPage?: number; | ||
statusArray?: $Enums.ScorecardStatus[]; | ||
scorecardTypesArray?: $Enums.ScorecardType[]; | ||
} | ||
|
||
export function mapScorecardRequestToDto(request: ScorecardRequestDto) { | ||
|
There was a problem hiding this comment.
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.