Skip to content

Conversation

@jmgasper
Copy link
Collaborator

No description provided.

@jmgasper jmgasper merged commit ed2f18d into dev Jan 22, 2026
5 checks passed
const result = new ResponseDto<WinningDto[]>();

try {
const queryWhere = this.getWinningsQueryFilters(

Choose a reason for hiding this comment

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

[⚠️ maintainability]
The method getWinningsQueryFilters is called with several undefined parameters. Consider refactoring the method to handle optional parameters more explicitly, which can improve readability and maintainability.

],
});

const usersPayoutStatusMap = winnings?.length

Choose a reason for hiding this comment

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

[💡 performance]
The use of ?.length to check for array length is unnecessary. winnings.length is sufficient and more performant since winnings is already defined.

billingAccount: paymentItem.billing_account,
})),
createdAt: item.created_at as Date,
updatedAt: (item.payment?.[0].date_paid ??

Choose a reason for hiding this comment

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

[⚠️ correctness]
The use of optional chaining ?. with array indexing payment?.[0] can lead to unexpected results if payment is not an array. Ensure that payment is always an array or handle the case where it might not be.

paymentStatus: usersPayoutStatusMap[item.winner_id],
}));
} catch (error) {
this.logger.error('Getting winnings by external ID failed', error);

Choose a reason for hiding this comment

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

[💡 readability]
Consider using error.message instead of concatenating the entire error object to the message string. This will provide a cleaner and more informative error message.

): Promise<ResponseDto<WinningDto[]>> {
const result = await this.winningsRepo.getWinningsByExternalId(externalId);

result.status = ResponseStatusType.SUCCESS;

Choose a reason for hiding this comment

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

[❗❗ correctness]
The result.status is set to SUCCESS before checking for an error. This could lead to incorrect status reporting if an error exists. Consider setting the status to SUCCESS only if no error is present.


return {
...result,
data: result.data,

Choose a reason for hiding this comment

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

[⚠️ correctness]
The data field is directly assigned from result.data. Ensure that result.data is always defined and correctly formatted as WinningDto[] to prevent potential runtime errors.

@@ -1,8 +1,11 @@
export enum Role {
Administrator = 'Administrator',

Choose a reason for hiding this comment

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

[💡 readability]
Consider using a consistent naming convention for enum values. For example, PaymentAdmin uses camel case while Administrator uses title case. Consistency improves readability and maintainability.

@@ -1,8 +1,11 @@
export enum Role {
Administrator = 'Administrator',
PaymentAdmin = 'Payment Admin',

Choose a reason for hiding this comment

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

[💡 readability]
Consider using a consistent naming convention for enum values. For example, Payment Admin uses a space while Administrator does not. Consistency improves readability and maintainability.

};

Object.keys(auth0User).forEach((key) => {
if (key.match(/\/roles$/gi) || key === 'roles' || key === 'role') {

Choose a reason for hiding this comment

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

[⚠️ correctness]
The regular expression /\/roles$/gi is used to match keys ending with '/roles'. Consider whether the global flag g is necessary here, as it might lead to unexpected behavior if used in other contexts. Removing it could improve clarity and prevent potential issues.


Object.keys(auth0User).forEach((key) => {
if (key.match(/\/roles$/gi) || key === 'roles' || key === 'role') {
appendRoles(auth0User[key]);

Choose a reason for hiding this comment

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

[⚠️ maintainability]
The appendRoles function is defined within collectUserRoles and captures the roles array from its outer scope. Consider extracting appendRoles as a separate method to improve maintainability and testability.

}
if (typeof value === 'string' && value.trim()) {
value
.split(',')

Choose a reason for hiding this comment

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

[❗❗ correctness]
The method collectUserRoles is introduced but not shown in the diff. Ensure that it correctly implements the logic to extract roles from auth0User, as this is critical for the guard's functionality.

return roles;
}, []);
const userRoles = this.collectUserRoles(auth0User);
const normalizedUserRoles = new Set(

Choose a reason for hiding this comment

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

[⚠️ performance]
Using Set for normalizedUserRoles is a good choice for performance when checking membership with has(). Ensure that normalizeRole is a pure function and handles edge cases correctly.

const normalizedUserRoles = new Set(
userRoles.map((role) => this.normalizeRole(role)),
);
const normalizedRequiredRoles = requiredRoles.map((role) =>

Choose a reason for hiding this comment

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

[💡 performance]
Consider checking if requiredRoles is empty before mapping and normalizing, as this would avoid unnecessary computation when no roles are required.

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.

2 participants