Skip to content

Engagements v4 #148

Merged
jmgasper merged 2 commits into
masterfrom
dev
Mar 25, 2026
Merged

Engagements v4 #148
jmgasper merged 2 commits into
masterfrom
dev

Conversation

@jmgasper

Copy link
Copy Markdown
Collaborator

payment.payment_status &&
payment.payment_status === PaymentStatus.CANCELLED
) {
if (payment.payment_status && payment.payment_status === 'CANCELLED') {

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 using the PaymentStatus.CANCELLED enum instead of the string 'CANCELLED' for consistency and to prevent potential typos or mismatches in the future.

return undefined;
}

const value = (attributes as Record<string, unknown>).hoursWorked;

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 type assertion (attributes as Record<string, unknown>) assumes that attributes is a plain object. Consider using a type guard to ensure this assumption is valid, which can improve type safety and prevent runtime errors.

}

const parsedValue = Number(value);
return Number.isFinite(parsedValue) && parsedValue > 0

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 check parsedValue > 0 excludes zero as a valid value. If zero is a valid input for hoursWorked, this condition should be adjusted. Otherwise, clarify why zero should be excluded.

description: item.description as string,
externalId: item.external_id as string,
attributes,
hoursWorked: this.getHoursWorked(item.attributes),

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 method getHoursWorked is called with item.attributes, but it's not clear if item.attributes is always defined or if getHoursWorked can handle undefined. Ensure getHoursWorked can handle undefined or provide a default value.

status: paymentItem.payment_status as PaymentStatus,
currency: paymentItem.currency as string,
releaseDate: paymentItem.release_date as Date,
category: item.category as string,

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 category field in the details object is set to item.category as string. This seems inconsistent with the category field at line 290, which uses (item.category ?? '') as WinningsCategory. Consider using a consistent approach for handling category to avoid potential type issues.

description: item.description as string,
externalId: item.external_id as string,
attributes,
hoursWorked: this.getHoursWorked(item.attributes),

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 method getHoursWorked is called with item.attributes, which is cast to an object. Ensure that getHoursWorked can handle cases where attributes might not have the expected structure or properties, as this could lead to runtime errors.

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

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 item.payment?.[0].date_paid ?? item.payment?.[0].updated_at ?? undefined for updatedAt assumes that item.payment is an array and that accessing the first element is safe. Consider checking if item.payment is non-empty before accessing the first element to avoid potential runtime errors.

});

if (existingFormAssociation) {
const dateFiled = existingFormAssociation.date_filed.toISOString();

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]
Converting date_filed to an ISO string before logging improves readability and consistency in log outputs. However, ensure that date_filed is always a valid Date object to avoid potential runtime errors. Consider adding a check or handling for cases where date_filed might be null or undefined.

* @returns The normalized attributes object, or `null` when empty.
*/
private buildWinningAttributes(
attributes: object | undefined,

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 adding a type guard to ensure attributes is not only an object but also not null, as typeof null is 'object'. This could prevent unexpected behavior if null is passed as attributes.

body.category === winnings_category.POINTS_AWARD ||
body.details.some((p) => p.currency === PrizeType.POINT)) &&
body.category === WinningsCategory.POINTS_AWARD ||
body.details.some((p) => String(p.currency) === 'POINT')) &&

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 conversion of p.currency to a string using String(p.currency) is repeated multiple times. Consider extracting this logic into a helper function or variable to improve maintainability and reduce the risk of errors if the conversion logic needs to change.

description: body.description,
external_id: body.externalId,
attributes: body.attributes,
attributes: this.buildWinningAttributes(

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 this.buildWinningAttributes handles cases where body.attributes or body.hoursWorked might be undefined or null. This could lead to unexpected behavior if not properly handled.

winnings.some(
(w) => w.type !== winnings_type.PAYMENT || w.currency !== PrizeType.USD,
(w) =>
String(w.type) !== winnings_type.PAYMENT ||

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]
Converting w.type and w.currency to strings using String() may mask potential issues if these values are not strings to begin with. Consider ensuring that w.type and w.currency are of the expected type before this comparison to avoid unexpected behavior.

Comment thread src/dto/winning.dto.ts
description: string;
externalId: string;
attributes: object;
hoursWorked?: number;

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 specifying a more detailed type for hoursWorked instead of number. If hoursWorked should only be a positive number or within a certain range, using a more specific type or validation could prevent incorrect data from being assigned.

Comment thread src/dto/winning.dto.ts
required: false,
})
@IsOptional()
@IsNumber()

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 using @IsPositive() instead of @Min(0.01) for hoursWorked. This will ensure that any positive number is valid, which might be more intuitive and flexible for future use cases.

@jmgasper
jmgasper merged commit 0ed0b02 into master Mar 25, 2026
5 of 7 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