From 74e12aeb81290821d75bd8613e1469158a067557 Mon Sep 17 00:00:00 2001 From: Bogsana Date: Mon, 11 Dec 2023 18:37:26 +0200 Subject: [PATCH 1/2] Update templates --- .../src/campaign-news/campaign-news.service.ts | 5 ++++- apps/api/src/campaign/campaign.service.ts | 17 ++++++++++++++--- .../marketing_templates/template.type.ts | 1 + .../src/notifications/notification-data.json | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/apps/api/src/campaign-news/campaign-news.service.ts b/apps/api/src/campaign-news/campaign-news.service.ts index a48d7a51b..1561d86f9 100644 --- a/apps/api/src/campaign-news/campaign-news.service.ts +++ b/apps/api/src/campaign-news/campaign-news.service.ts @@ -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, 'campaign.raised-amount': campaign.vaults?.map((vault) => vault.amount).reduce((a, b) => a + b, 0) || 0, 'campaign.start-date': campaign.startDate @@ -112,6 +112,9 @@ export class CampaignNewsService { : '', 'campaign.news-title': news.title, 'campaign.news-desc': news.slug, + 'campaign.link': ( + this.config.get('APP_URL') + `/campaigns/${campaign.slug}` + ).replace(/(http:\/\/|https:\/\/)/gi, ''), 'campaign.news-link': ( this.config.get('APP_URL') + `/campaigns/${campaign.slug}/news` ).replace(/(http:\/\/|https:\/\/)/gi, ''), diff --git a/apps/api/src/campaign/campaign.service.ts b/apps/api/src/campaign/campaign.service.ts index 3402d6adc..d51fafb89 100644 --- a/apps/api/src/campaign/campaign.service.ts +++ b/apps/api/src/campaign/campaign.service.ts @@ -11,6 +11,7 @@ import { CampaignNewsState, NotificationList, EmailType, + CampaignTypeCategory, } from '@prisma/client' import { BadRequestException, @@ -902,7 +903,7 @@ export class CampaignService { 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') @@ -942,6 +943,7 @@ export class CampaignService { 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}`) @@ -1020,7 +1022,15 @@ export class CampaignService { 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: { @@ -1038,7 +1048,8 @@ export class CampaignService { 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') : '', diff --git a/apps/api/src/notifications/marketing_templates/template.type.ts b/apps/api/src/notifications/marketing_templates/template.type.ts index 995f5f316..75a04f914 100644 --- a/apps/api/src/notifications/marketing_templates/template.type.ts +++ b/apps/api/src/notifications/marketing_templates/template.type.ts @@ -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 diff --git a/apps/api/src/notifications/notification-data.json b/apps/api/src/notifications/notification-data.json index 2a0d2c745..4d44e5baa 100644 --- a/apps/api/src/notifications/notification-data.json +++ b/apps/api/src/notifications/notification-data.json @@ -9,6 +9,6 @@ "subject": "100% от сумата е събрана" }, "new-campaign": { - "subject": "Нова камапания е активна в Podkrepi.bg" + "subject": "Нова кампания е активна в Podkrepi.bg" } } From 1f71f02d62c78efdae148404a00d82017bfed040 Mon Sep 17 00:00:00 2001 From: Bogsana Date: Tue, 12 Dec 2023 08:04:03 +0200 Subject: [PATCH 2/2] fix tests --- apps/api/src/campaign/campaign.service.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/api/src/campaign/campaign.service.spec.ts b/apps/api/src/campaign/campaign.service.spec.ts index 5e41195c5..01633a49b 100644 --- a/apps/api/src/campaign/campaign.service.spec.ts +++ b/apps/api/src/campaign/campaign.service.spec.ts @@ -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({ @@ -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()