Skip to content
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
41 changes: 29 additions & 12 deletions src/api/review-summation/review-summation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,13 @@ export class ReviewSummationService {
const skip = (page - 1) * perPage;
let orderBy;

const parseBooleanString = (value?: string): boolean | undefined => {
if (typeof value !== 'string') {

Choose a reason for hiding this comment

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

[⚠️ correctness]
The parseBooleanString function returns undefined for non-string inputs, which might not be the expected behavior if the input is null or undefined. Consider explicitly handling these cases to avoid potential issues in the calling code.

return undefined;
}
return value.toLowerCase() === 'true';
};

if (sortDto && sortDto.orderBy && sortDto.sortBy) {
orderBy = {
[sortDto.sortBy]: sortDto.orderBy.toLowerCase(),
Expand Down Expand Up @@ -700,6 +707,14 @@ export class ReviewSummationService {

// Build the where clause for review summations based on available filter parameters
const reviewSummationWhereClause: any = {};
const isPassingFilter = parseBooleanString(queryDto.isPassing);
const isFinalFilter = parseBooleanString(queryDto.isFinal);
const isProvisionalFilter = parseBooleanString(queryDto.isProvisional);
const isExampleFilter = parseBooleanString(queryDto.isExample);
const exampleOnly = parseBooleanString(queryDto.example) === true;
const provisionalOnly = parseBooleanString(queryDto.provisional) === true;
const systemOnly = parseBooleanString(queryDto.system) === true;

if (queryDto.submissionId) {
reviewSummationWhereClause.submissionId = queryDto.submissionId;
}
Expand All @@ -711,21 +726,23 @@ export class ReviewSummationService {
if (queryDto.scorecardId) {
reviewSummationWhereClause.scorecardId = queryDto.scorecardId;
}
if (queryDto.isPassing !== undefined) {
reviewSummationWhereClause.isPassing =
queryDto.isPassing.toLowerCase() === 'true';
if (isPassingFilter !== undefined) {
reviewSummationWhereClause.isPassing = isPassingFilter;
}
if (queryDto.isFinal !== undefined) {
reviewSummationWhereClause.isFinal =
queryDto.isFinal.toLowerCase() === 'true';
if (isFinalFilter !== undefined) {
reviewSummationWhereClause.isFinal = isFinalFilter;
} else if (systemOnly) {

Choose a reason for hiding this comment

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

[⚠️ correctness]
The logic for setting reviewSummationWhereClause.isFinal when systemOnly is true might lead to unintended behavior if isFinalFilter is explicitly set to false. Consider revisiting this logic to ensure it aligns with the intended functionality.

reviewSummationWhereClause.isFinal = true;
}
if (queryDto.isProvisional !== undefined) {
reviewSummationWhereClause.isProvisional =
queryDto.isProvisional.toLowerCase() === 'true';
if (isProvisionalFilter !== undefined) {
reviewSummationWhereClause.isProvisional = isProvisionalFilter;
} else if (provisionalOnly) {

Choose a reason for hiding this comment

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

[⚠️ correctness]
The logic for setting reviewSummationWhereClause.isProvisional when provisionalOnly is true might lead to unintended behavior if isProvisionalFilter is explicitly set to false. Consider revisiting this logic to ensure it aligns with the intended functionality.

reviewSummationWhereClause.isProvisional = true;
}
if (queryDto.isExample !== undefined) {
reviewSummationWhereClause.isExample =
queryDto.isExample.toLowerCase() === 'true';
if (isExampleFilter !== undefined) {
reviewSummationWhereClause.isExample = isExampleFilter;
} else if (exampleOnly) {
reviewSummationWhereClause.isExample = true;

Choose a reason for hiding this comment

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

[⚠️ correctness]
The logic for setting reviewSummationWhereClause.isExample when exampleOnly is true might lead to unintended behavior if isExampleFilter is explicitly set to false. Consider revisiting this logic to ensure it aligns with the intended functionality.

}

const submissionWhereClause: Record<string, unknown> = {};
Expand Down
27 changes: 27 additions & 0 deletions src/dto/reviewSummation.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,33 @@ export class ReviewSummationQueryDto {
@IsBooleanString()
isExample?: string;

@ApiProperty({
description:
'When true, only include review summations flagged as examples (isExample = true)',
required: false,
})
@IsOptional()
@IsBooleanString()
example?: string;

Choose a reason for hiding this comment

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

[⚠️ maintainability]
The example property appears to duplicate the functionality of the existing isExample property. Consider whether both are necessary or if one can be removed to avoid redundancy.


@ApiProperty({
description:
'When true, only include provisional review summations (isProvisional = true)',
required: false,
})
@IsOptional()
@IsBooleanString()
provisional?: string;

Choose a reason for hiding this comment

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

[⚠️ maintainability]
The provisional property seems to overlap with the existing isProvisional property. Evaluate if both are needed or if this introduces unnecessary complexity.


@ApiProperty({
description:
'When true, only include system (final) review summations (isFinal = true)',
required: false,
})
@IsOptional()
@IsBooleanString()
system?: string;

Choose a reason for hiding this comment

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

[⚠️ maintainability]
The system property may be redundant with the existing isFinal property. Consider consolidating these to simplify the DTO.


@ApiProperty({
description: 'The challenge id tied to the submission',
required: false,
Expand Down
Loading