Skip to content

Commit 7016f07

Browse files
authored
Merge pull request #604 from topcoder-platform/issue-603
Issue #603: Self-service - Launching a bug hunt failing
2 parents 2d01cb9 + c3dcbc4 commit 7016f07

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src-ts/tools/work/work-lib/work-provider/work-functions/work-factory/work.factory.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,10 @@ function checkFormDataOptionEmpty(detail: any): boolean {
450450
)
451451
}
452452

453-
function findMetadata(challenge: Challenge, metadataName: ChallengeMetadataName): ChallengeMetadata | undefined {
453+
export function findMetadata(
454+
challenge: Challenge | CreateWorkRequest,
455+
metadataName: ChallengeMetadataName,
456+
): ChallengeMetadata | undefined {
454457
return challenge.metadata?.find((item: ChallengeMetadata) => item.name === metadataName)
455458
}
456459

src-ts/tools/work/work-lib/work-provider/work-functions/work.functions.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { PaymentMethodResult, Stripe, StripeCardNumberElement } from '@stripe/stripe-js'
22

33
import { FormCard, GenericDataObject, Page, textFormatMoneyLocaleString, UserProfile } from '../../../../../lib'
4+
import { isJsonString } from '../../../../../utils/string'
45
// this has to be imported directly from the file bc the order of operations
56
// that items are loaded in the barrel file this config is empty and throws an error
67
// eslint-disable-next-line ordered-imports/ordered-imports
@@ -17,6 +18,8 @@ import {
1718
import {
1819
ActivateWorkRequest,
1920
Challenge,
21+
ChallengeMetadata,
22+
ChallengeMetadataName,
2023
CreateWorkRequest,
2124
CustomerPayment,
2225
CustomerPaymentRequest,
@@ -41,11 +44,21 @@ import {
4144
WorkTypeConfig,
4245
WorkTypeConfigs,
4346
} from './work-store'
47+
import { findMetadata } from './work-factory/work.factory'
4448

4549
export async function createAsync(type: WorkType): Promise<Challenge> {
4650
const workConfig: WorkTypeConfig = WorkTypeConfigs[type]
4751
const body: CreateWorkRequest = workFactoryBuildCreateReqeuest(workConfig)
48-
return workStoreCreateAsync(body)
52+
const result: Challenge = await workStoreCreateAsync(body)
53+
54+
const intakeFormResponse: ChallengeMetadata | undefined
55+
= findMetadata(result, ChallengeMetadataName.intakeForm) || undefined
56+
if (!!intakeFormResponse?.value && !isJsonString(intakeFormResponse.value)) {
57+
const bodyIntakeForm: ChallengeMetadata | undefined = findMetadata(body, ChallengeMetadataName.intakeForm)
58+
intakeFormResponse.value = bodyIntakeForm?.value || '{}'
59+
}
60+
61+
return result
4962
}
5063

5164
export async function createCustomerPaymentAsync(

src-ts/utils/string.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export function isJsonString(str: string): boolean {
2+
try {
3+
JSON.parse(str)
4+
} catch (e) {
5+
return false
6+
}
7+
8+
return true
9+
}

0 commit comments

Comments
 (0)