Skip to content

Commit

Permalink
fix(campaign): handle empty array stage description input
Browse files Browse the repository at this point in the history
  • Loading branch information
gary02 committed Aug 20, 2024
1 parent 2b0e15b commit 76ec46c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/mutations/campaign/putWritingChallenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ const resolver: GQLMutationResolvers['putWritingChallenge'] = async (
campaign.id,
stages.map((stage) => ({
name: stage.name[0].text,
description: stage.description ? stage.description[0].text : '',
description:
stage.description && stage.description.length > 0
? stage.description[0].text
: '',
period: stage.period
? [stage.period.start, stage.period.end]
: undefined,
Expand All @@ -191,7 +194,7 @@ const resolver: GQLMutationResolvers['putWritingChallenge'] = async (
text: trans.text,
})
}
if (stage.description) {
if (stage.description && stage.description.length > 0) {
for (const trans of stage.description) {
await translationService.updateOrCreateTranslation({
table: 'campaign_stage',
Expand Down
1 change: 1 addition & 0 deletions src/types/__test__/2/campaign.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ describe('create or update wrting challenges', () => {
const stages = [
{
name: translationsStageName1,
description: [],
period: {
start: new Date('2024-01-03'),
end: new Date('2024-01-04'),
Expand Down

0 comments on commit 76ec46c

Please sign in to comment.