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

Update Notification templates #583

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion apps/api/src/campaign-news/campaign-news.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class CampaignNewsService {
campaignid: campaign.id,
template_data: {
'campaign.name': campaign?.title,
'campaign.target-amount': campaign?.targetAmount || 0,
'campaign.target-amount': (campaign?.targetAmount && campaign?.targetAmount / 100) || 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somewhat difficult to read.
I wonder if there is a better way to get the campaign target.

'campaign.raised-amount':
campaign.vaults?.map((vault) => vault.amount).reduce((a, b) => a + b, 0) || 0,
'campaign.start-date': campaign.startDate
Expand All @@ -112,6 +112,9 @@ export class CampaignNewsService {
: '',
'campaign.news-title': news.title,
'campaign.news-desc': news.slug,
'campaign.link': (
this.config.get<string>('APP_URL') + `/campaigns/${campaign.slug}`
).replace(/(http:\/\/|https:\/\/)/gi, ''),
'campaign.news-link': (
this.config.get<string>('APP_URL') + `/campaigns/${campaign.slug}/news`
).replace(/(http:\/\/|https:\/\/)/gi, ''),
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/campaign/campaign.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ describe('CampaignService', () => {
expect(prismaMock.campaign.update).toHaveBeenCalledWith({
where: { id: mockCampaign.id },
data: updateData,
include: { campaignType: { select: { name: true, slug: true, category: true } } },
})
expect(service.createCampaignNotificationList).toHaveBeenCalledWith(updatedCampaign)
expect(marketing.createNewContactList).toHaveBeenCalledWith({
Expand Down Expand Up @@ -180,6 +181,7 @@ describe('CampaignService', () => {
expect(prismaMock.campaign.update).toHaveBeenCalledWith({
where: { id: campaignWithList.id },
data: updateData,
include: { campaignType: { select: { name: true, slug: true, category: true } } },
})
// Since notification list exists for this campaign
expect(service.createCampaignNotificationList).not.toHaveBeenCalled()
Expand Down
17 changes: 14 additions & 3 deletions apps/api/src/campaign/campaign.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
CampaignNewsState,
NotificationList,
EmailType,
CampaignTypeCategory,
} from '@prisma/client'
import {
BadRequestException,
Expand Down Expand Up @@ -41,7 +42,7 @@
NotificationService,
donationNotificationSelect,
} from '../sockets/notifications/notification.service'
import { DonationMetadata } from '../donations/dontation-metadata.interface'

Check warning on line 45 in apps/api/src/campaign/campaign.service.ts

View workflow job for this annotation

GitHub Actions / Run API tests

'DonationMetadata' is defined but never used
import { Expense } from '@prisma/client'
import { SendGridParams } from '../notifications/providers/notifications.sendgrid.types'
import * as NotificationData from '../notifications/notification-data.json'
Expand Down Expand Up @@ -887,7 +888,7 @@
campaignid: campaign.id,
template_data: {
'campaign.name': campaign?.title,
'campaign.target-amount': campaign?.targetAmount || 0,
'campaign.target-amount': (campaign?.targetAmount && campaign?.targetAmount / 100) || 0,
'campaign.raised-amount': raisedAmount,
'campaign.start-date': campaign.startDate
? DateTime.fromJSDate(campaign.startDate).toFormat('dd-MM-yyyy')
Expand Down Expand Up @@ -927,6 +928,7 @@
const updated = await this.prisma.campaign.update({
where: { id: id },
data: updateCampaignDto,
include: { campaignType: { select: { name: true, slug: true, category: true } } },
})

if (!updated) throw new NotFoundException(`Not found campaign with id: ${id}`)
Expand Down Expand Up @@ -1005,7 +1007,15 @@
return listId
}

async sendNewCampaignNotification(campaign: Campaign) {
async sendNewCampaignNotification(
campaign: Campaign & {
campaignType: {
slug: string
name: string
category: CampaignTypeCategory
}
},
) {
// Send notification for the new activated campaign
const template = await this.prisma.marketingTemplates.findFirst({
where: {
Expand All @@ -1023,7 +1033,8 @@
subject: NotificationData['new-campaign'].subject,
template_data: {
'campaign.name': campaign?.title,
'campaign.target-amount': campaign?.targetAmount || 0,
'campaign.type': campaign?.campaignType?.name,
'campaign.target-amount': (campaign?.targetAmount && campaign?.targetAmount / 100) || 0,
'campaign.start-date': campaign.startDate
? DateTime.fromJSDate(campaign.startDate).toFormat('dd-MM-yyyy')
: '',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Available fields for populating a marketing template
export type MarketingTemplateHTMLFields = {
'campaign.name'?: string
'campaign.type'?: string
'campaign.target-amount'?: number
'campaign.raised-amount'?: number
'campaign.start-date'?: string | Date
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/notifications/notification-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"subject": "100% от сумата е събрана"
},
"new-campaign": {
"subject": "Нова камапания е активна в Podkrepi.bg"
"subject": "Нова кампания е активна в Podkrepi.bg"
}
}
Loading