Skip to content

Commit

Permalink
Force casting of send at value (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
pushchris authored Oct 18, 2024
1 parent 9f64b39 commit 4528f29
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/platform/src/campaigns/Campaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class Campaign extends Model {
tags?: string[]

send_in_user_timezone?: boolean
send_at?: string | Date
send_at?: string | Date | null

deleted_at?: Date

Expand Down
8 changes: 5 additions & 3 deletions apps/platform/src/campaigns/CampaignService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,18 @@ export const updateCampaign = async (id: number, projectId: number, { tags, ...p
}

const data: Partial<Campaign> = { ...params }
let send_at: Date | undefined | null = data.send_at ? new Date(data.send_at) : undefined

// If we are aborting, reset `send_at`
if (data.state === 'aborted') {
data.send_at = undefined
send_at = null
await abortCampaign(campaign)
}

// If we are rescheduling, abort sends so they are reset
if (data.send_at
if (send_at
&& campaign.send_at
&& data.send_at !== campaign.send_at) {
&& send_at !== campaign.send_at) {
data.state = 'pending'
await abortCampaign(campaign)
}
Expand All @@ -141,6 +142,7 @@ export const updateCampaign = async (id: number, projectId: number, { tags, ...p

await Campaign.update(qb => qb.where('id', id), {
...data,
send_at,
})

if (tags) {
Expand Down

0 comments on commit 4528f29

Please sign in to comment.