Skip to content

Commit

Permalink
Fixed Url rendering in PushTemplate to support undefined value (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
PRZzz authored Dec 4, 2024
1 parent cf2c86e commit f05f099
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions apps/platform/src/render/Template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,30 @@ export class PushTemplate extends Template {
}

compile(variables: Variables): CompiledPush {
const { project, user, context } = variables
const custom = Object.keys(this.custom).reduce((body, key) => {
body[key] = Render(this.custom[key], variables)
return body
}, {} as Record<string, any>)

const url = this.compileUrl(variables)

return {
topic: this.topic,
title: Render(this.title, variables),
body: Render(this.body, variables),
custom: { ...custom, url },
}
}

compileUrl(variables: Variables) {
if (this.url === undefined) {
return undefined
}

const { project, user, context } = variables
const renderedUrl = Render(this.url, variables)
const url = project.link_wrap_push

return project.link_wrap_push
? paramsToEncodedLink({
userId: user.id,
campaignId: context.campaign_id,
Expand All @@ -202,13 +218,6 @@ export class PushTemplate extends Template {
path: 'c',
})
: renderedUrl

return {
topic: this.topic,
title: Render(this.title, variables),
body: Render(this.body, variables),
custom: { ...custom, url },
}
}

validate() {
Expand Down

0 comments on commit f05f099

Please sign in to comment.