-
Notifications
You must be signed in to change notification settings - Fork 0
Add in status normalization for SFDC usage #28
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 |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import { | |
| } from "./sfdc-reports.dto"; | ||
| import { SqlLoaderService } from "src/common/sql-loader.service"; | ||
| import { multiValueArrayFilter } from "src/common/filtering"; | ||
| import { normalizeChallengeStatus } from "./status-normalizer"; | ||
|
|
||
| @Injectable() | ||
| export class SfdcReportsService { | ||
|
|
@@ -96,7 +97,10 @@ export class SfdcReportsService { | |
|
|
||
| this.logger.debug("Mapped challenges to the final report format"); | ||
|
|
||
| return challenges; | ||
| return challenges.map((challenge) => ({ | ||
| ...challenge, | ||
| challengeStatus: normalizeChallengeStatus(challenge.challengeStatus), | ||
| })); | ||
| } | ||
|
|
||
| async getPaymentsReport(filters: PaymentsReportQueryDto) { | ||
|
|
@@ -122,7 +126,10 @@ export class SfdcReportsService { | |
|
|
||
| this.logger.debug("Mapped payments to the final report format"); | ||
|
|
||
| return payments; | ||
| return payments.map((payment) => ({ | ||
| ...payment, | ||
| challengeStatus: normalizeChallengeStatus(payment.challengeStatus), | ||
|
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. [ |
||
| })); | ||
| } | ||
|
|
||
| async getTaasJobsReport(filters: TaasJobsReportQueryDto) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| const CHALLENGE_STATUS_LABELS: Record<string, string> = { | ||
| NEW: "New", | ||
| DRAFT: "Draft", | ||
| APPROVED: "Approved", | ||
| ACTIVE: "Active", | ||
| COMPLETED: "Completed", | ||
| DELETED: "Deleted", | ||
| CANCELLED: "Cancelled", | ||
| CANCELLED_FAILED_REVIEW: "Cancelled - Failed Review", | ||
| CANCELLED_FAILED_SCREENING: "Cancelled - Failed Screening", | ||
| CANCELLED_ZERO_SUBMISSIONS: "Cancelled - Zero Submissions", | ||
| CANCELLED_WINNER_UNRESPONSIVE: "Cancelled - Winner Unresponsive", | ||
| CANCELLED_CLIENT_REQUEST: "Cancelled - Client Request", | ||
| CANCELLED_REQUIREMENTS_INFEASIBLE: "Cancelled - Requirements Infeasible", | ||
| CANCELLED_ZERO_REGISTRATIONS: "Cancelled - Zero Registrations", | ||
| CANCELLED_PAYMENT_FAILED: "Cancelled - Payment Failed", | ||
| }; | ||
|
|
||
| export const normalizeChallengeStatus = ( | ||
| status: string | null | undefined, | ||
| ): string | null | undefined => { | ||
| if (status === null || status === undefined) return status; | ||
|
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. [💡 |
||
| const trimmed = String(status).trim(); | ||
|
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. [💡 |
||
| if (!trimmed) return status; | ||
|
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. [ |
||
| const normalized = CHALLENGE_STATUS_LABELS[trimmed.toUpperCase()]; | ||
|
|
||
| return normalized ?? status; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ import { | |
| WesternUnionPaymentsReportQueryDto, | ||
| WesternUnionPaymentsReportResponse, | ||
| } from "../sfdc-reports.dto"; | ||
| import { normalizeChallengeStatus } from "../status-normalizer"; | ||
|
|
||
| export const mockChallengeData: ChallengesReportResponse[] = [ | ||
| { | ||
|
|
@@ -154,6 +155,18 @@ export const mockPaymentQueryDto: Record<string, PaymentsReportQueryDto> = { | |
| }, | ||
| }; | ||
|
|
||
| export const normalizedChallengeData = mockChallengeData.map((challenge) => ({ | ||
| ...challenge, | ||
| challengeStatus: normalizeChallengeStatus( | ||
| challenge.challengeStatus, | ||
| ) as string, | ||
| })); | ||
|
|
||
| export const normalizedPaymentData = mockPaymentData.map((payment) => ({ | ||
| ...payment, | ||
| challengeStatus: normalizeChallengeStatus(payment.challengeStatus) as string, | ||
|
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. [❗❗ |
||
| })); | ||
|
|
||
| export const mockBaFeesData: BaFeesReportResponse[] = [ | ||
| { | ||
| billingAccountId: "80001012", | ||
|
|
||
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.
[⚠️
correctness]Ensure that
normalizeChallengeStatushandles all possible values ofchallenge.challengeStatuscorrectly. If there are any unexpected values, consider adding a default case or error handling to avoid potential runtime issues.