Skip to content
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

Fixed Url rendering in PushTemplate to support undefined value #569

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading