Skip to content

Export optimization (PS-530)#144

Merged
jmgasper merged 2 commits into
masterfrom
dev
Feb 19, 2026
Merged

Export optimization (PS-530)#144
jmgasper merged 2 commits into
masterfrom
dev

Conversation

@jmgasper

Copy link
Copy Markdown
Collaborator

No description provided.

…o dev

# Conflicts:
#	src/api/admin/admin.controller.ts
#	src/api/admin/admin.service.ts
},
);

if (result.error || !result.data) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[⚠️ maintainability]
Consider logging the error details before throwing the InternalServerErrorException. This can help with debugging and monitoring by providing more context about the failure.


winnings.push(...result.data.winnings);

if (result.data.winnings.length < AdminController.EXPORT_BATCH_SIZE) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[⚠️ correctness]
The condition result.data.winnings.length < AdminController.EXPORT_BATCH_SIZE assumes that the API will always return a number of winnings equal to or less than the batch size. Ensure that this logic aligns with the API's behavior, especially if the API could return more winnings than requested due to pagination issues.

*/
async searchWinnings(
searchProps: WinningRequestDto,
options: SearchWinningsOptions = {},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[⚠️ maintainability]
The options parameter is introduced without any documentation or type definition. Consider defining a TypeScript interface for SearchWinningsOptions to ensure type safety and improve maintainability.

options: SearchWinningsOptions = {},
): Promise<ResponseDto<SearchWinningResult>> {
const result = new ResponseDto<SearchWinningResult>();
const includeCount = options.includeCount ?? true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[⚠️ correctness]
The default value for includeCount is set to true. Ensure that this default behavior is intentional and documented, as it may affect the logic where this function is called.

): Promise<ResponseDto<SearchWinningResult>> {
const result = new ResponseDto<SearchWinningResult>();
const includeCount = options.includeCount ?? true;
const includePayoutStatus = options.includePayoutStatus ?? true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[⚠️ correctness]
The default value for includePayoutStatus is set to true. Verify that this default aligns with the expected behavior of the function and is documented accordingly.

);

const winnings = await this.prisma.winnings.findMany({
const limit = searchProps.limit ?? 10;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[⚠️ correctness]
Consider validating searchProps.limit and searchProps.offset to ensure they are non-negative integers. This will prevent potential issues with pagination logic.

});

const count = await this.prisma.winnings.count({ where: queryWhere });
const [winnings, count] = includeCount

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[⚠️ correctness]
The use of Promise.all here is appropriate for parallelizing the fetching of winnings and count. However, ensure that both operations are independent and that the count operation does not depend on any side effects of the winningsPromise. If there is any dependency, this could lead to incorrect results.

const usersPayoutStatusMap = winnings?.length
? await this.getUsersPayoutStatusForWinnings(winnings)
: ({} as { [key: string]: payment_status });
const usersPayoutStatusMap: Record<string, unknown> =

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[💡 maintainability]
The type Record<string, unknown> for usersPayoutStatusMap is quite generic. If possible, specify a more precise type to improve type safety and maintainability.

paymentStatus: usersPayoutStatusMap[item.winner_id],
paymentStatus: usersPayoutStatusMap[
item.winner_id
] as WinningDto['paymentStatus'],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[⚠️ correctness]
Casting item.winner_id to WinningDto['paymentStatus'] may hide potential type mismatches. Ensure that usersPayoutStatusMap always returns a value compatible with WinningDto['paymentStatus'] to avoid runtime errors.

pageSize: searchProps.limit,
currentPage: Math.ceil(searchProps.offset / searchProps.limit) + 1,
totalItems,
totalPages: Math.ceil(totalItems / limit),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[❗❗ correctness]
Ensure that limit is never zero to prevent a division by zero error when calculating totalPages.

@jmgasper
jmgasper merged commit bda7ea2 into master Feb 19, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant