Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/http-proxy-middlew…
Browse files Browse the repository at this point in the history
…are-2.0.7
  • Loading branch information
sashko9807 authored Dec 9, 2024
2 parents ec9083d + 7973d42 commit 0176dde
Show file tree
Hide file tree
Showing 19 changed files with 380 additions and 28 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@
"extends": ["plugin:@nrwl/nx/typescript"],
"rules": {}
},
{
"files": ["*.spec.ts"],
"extends": ["plugin:@nrwl/nx/typescript"],
"rules": {
"no-restricted-syntax": [
"error",
{
"message": "Do you really need to write file to disk in a test?",
"selector": "[name=writeFileSync], [name=writeFile]"
}
]
}
},
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nrwl/nx/javascript"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"subject": "Създадена нова кампания"
"subject": "Потвърждение за получаване на заявка за дарителска кампания "
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
padding-right="25px"
padding-bottom="30px"
padding-top="50px">
Успешно създадохте кампания в Подкрепи.бг
Потвърждение за получаване на заявка за дарителска кампания
</mj-text>
</mj-column>
</mj-section>
Expand All @@ -25,7 +25,7 @@
font-family="open Sans Helvetica, Arial, sans-serif"
padding-left="25px"
padding-right="25px">
<span style="color: #feeb35"> Здравейте {{firstName}}, </span>
<span style="color: #feeb35"> Здравейте, {{firstName}}, </span>
<br /><br />
</mj-text>
<mj-text
Expand All @@ -35,11 +35,20 @@
font-family="open Sans Helvetica, Arial, sans-serif"
padding-left="25px"
padding-right="25px">
Вашата кампания е създадена успешно! Вижте я
Благодарим Ви, че подадохте заявка за кампания на платформата Подкрепи.бг!<br />Можете да
я прегледате
<a style="color: #feeb35" href="{{campaignApplicationLink}}" target="_blank">ТУК</a
>!<br /><br />
>.<br /><br />

Пожелаваме успешно набиране на средствата!
Искаме да Ви уверим, че заявката Ви е успешно получена и ще бъде разгледана от екипа ни в
най-кратък срок. Ако има нужда от допълнителна информация или уточнения, член на екип
„Кампании“ ще се свърже с Вас.<br /><br />

Междувременно, ако имате въпроси или желаете да предоставите допълнителни детайли за
кампанията, можете да се свържете с нас на следния имейл:
<a style="color: #feeb35" href="mailto:[email protected]" target="_blank"
>[email protected]</a
>. Благодарим Ви, че заедно правим добро!<br /><br />
</mj-text>
<mj-text
align="left"
Expand All @@ -48,7 +57,7 @@
font-family="open Sans Helvetica, Arial, sans-serif"
padding-left="25px"
padding-right="25px">
Поздрави, <br />
С уважение, <br />
Екипът на Подкрепи.бг
</mj-text>
</mj-column>
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/assets/templates/forgot-password.mjml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
font-family="open Sans Helvetica, Arial, sans-serif"
padding-left="25px"
padding-right="25px">
<span style="color: #feeb35"> Здравейте {{firstName}} {{lastName}}, </span>
<span style="color: #feeb35"> Здравейте, {{firstName}} {{lastName}}, </span>
<br /><br />
</mj-text>
<mj-text
Expand All @@ -25,7 +25,7 @@
font-family="open Sans Helvetica, Arial, sans-serif"
padding-left="25px"
padding-right="25px">
някой (може би Вие) е пуснал заявка за смяна на парола за достъп до Подкрепи.бг.<br /><br />
Някой (може би Вие) е пуснал заявка за смяна на паролата Ви за достъп до Подкрепи.бг.<br /><br />
Ако не сте пускали подобна заявка, не е необходимо да правите нищо.<br /><br />
Ако Вие сте поискали възстановяване на паролата, натиснете бутона „Нова парола“.<br /><br />
</mj-text>
Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/assets/templates/welcome.mjml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
font-family="open Sans Helvetica, Arial, sans-serif"
padding-left="25px"
padding-right="25px">
<span style="color: #feeb35"> Здравейте {{person.firstName}}, </span>
<span style="color: #feeb35"> Здравейте, {{person.firstName}}, </span>
<br /><br />
</mj-text>
<mj-text
Expand All @@ -44,9 +44,9 @@
<a style="color: #feeb35" href="https://discord.gg/3FBXDPjXEp" target="_blank"
>Discord сървъра</a
>, където се помещава нашият виртуален офис. Съветът ни е да прочетете внимателно какво
пише на началната страница в канал #започни-от-тук. <br /><br />
След това може да се включите в дискусиите и Ви чакаме на обща среща всяка сряда от 19:00
ч. в гласовия канал #обща-среща-сряда-19ч на сървъра. <br /><br />
пише на началната страница в канал <strong>#започни-от-тук</strong>. <br /><br />
След това може да се включите в дискусиите и Ви чакаме на обща среща <strong>всяка сряда от 19:00
ч.</strong> в гласовия канал <strong>#обща-среща-сряда-19ч</strong> на сървъра. <br /><br />
Още веднъж благодарим за готовността да помогнете за нашата кауза!
</mj-text>
<mj-text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ describe('CampaignApplicationService', () => {

const emailAdminData = {
campaignApplicationName: mockSingleCampaignApplication.campaignName,
campaignApplicationLink: `${process.env.APP_URL}/admin/campaigns/${mockSingleCampaignApplication.id}`,
campaignApplicationLink: `${process.env.APP_URL}/admin/campaigns/edit/${mockSingleCampaignApplication.id}`,
email: mockPerson.email as string,
firstName: mockPerson.firstName,
}

const emailOrganizerData = {
campaignApplicationName: mockSingleCampaignApplication.campaignName,
campaignApplicationLink: `${process.env.APP_URL}/campaign/applications/${mockSingleCampaignApplication.id}`,
campaignApplicationLink: `${process.env.APP_URL}/campaigns/application/${mockSingleCampaignApplication.id}`,
email: mockPerson.email as string,
firstName: mockPerson.firstName,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class CampaignApplicationService {
campaignApplicationName,
campaignApplicationLink: `${this.configService.get(
'APP_URL',
)}/admin/campaigns/${campaignApplicationId}`,
)}/admin/campaigns/edit/${campaignApplicationId}`,
email: person.email as string,
firstName: person.firstName,
}
Expand All @@ -119,7 +119,7 @@ export class CampaignApplicationService {
campaignApplicationName,
campaignApplicationLink: `${this.configService.get(
'APP_URL',
)}/campaign/applications/${campaignApplicationId}`,
)}/campaigns/application/${campaignApplicationId}`,
email: person.email as string,
firstName: person.firstName,
}
Expand Down
8 changes: 5 additions & 3 deletions apps/api/src/donations/donations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ export class DonationsService {
create: {
amount: paymentData.netAmount,
type: paymentData.type as DonationType,
person: paymentData.personId ? { connect: { email: paymentData.billingEmail } } : {},
person: paymentData.personId ? { connect: { id: paymentData.personId } } : {},
targetVault: targetVaultData,
},
},
Expand All @@ -928,7 +928,7 @@ export class DonationsService {
donation.amount,
tx,
)
this.notificationService.sendNotification('successfulDonation', donation)
this.notificationService.sendNotification('successfulDonation', donation.donations[0])
}

return donation
Expand Down Expand Up @@ -966,7 +966,9 @@ export class DonationsService {
},
include: { donations: true },
})
Logger.debug('Donation found by subscription: ', donation)
if (donation) {
Logger.debug('Donation found by subscription: ', donation)
}
}
return donation
}
Expand Down
27 changes: 27 additions & 0 deletions apps/api/src/email/readme.email.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Email Template Service

It gets the templates based on the name and the templates in the src/assets/templates.

## Testing with adapter

Why do we need the `template.service.spec-adapter.ts` when we have the `template.service.ts`?
It's looking in a hardcoded path which is correct when the app is built and deployed but incorrect when running the tests. Hence we extend the base class with this for the tests.

## Visualize the template before you ship the code

- temporarily add a line like `writeFileSync('./rendered-template.html', rendered.html)` to your test (careful to not )
- then open that with the browser i.e. `file:///C:/Users/gparl/Downloads/projects/podkrepi-bg-api/rendered-template.html` or on ubuntu under wsl `file://wsl.localhost/Ubuntu/home/gparlakov/projects/podkrepi-bg-api/rendered-template.html`
- remember to delete that `writeFileSync` line and the `rendered-template.html` before you ship

```ts
const t = new CreateCampaignApplicationOrganizerEmailDto({
firstName: 'test',
email: 'test@email',
campaignApplicationLink: 'link',
campaignApplicationName: 'campaignApplicationName',
})

const rendered = await s.getTemplate(t)

writeFileSync('./rendered-template.html', rendered.html)
```
46 changes: 46 additions & 0 deletions apps/api/src/email/template.service.spec-adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Logger } from '@nestjs/common'
import { readFile } from 'fs/promises'
import mjml from 'mjml'
import path from 'path'

import { EmailMetadata, TemplateType } from './template.interface'
import { TemplateService } from './template.service'

export class TemplateServiceSpecAdapter extends TemplateService {
/**
* Why do we need this when we have the template.service.ts?
* It's looking in a hardcoded path which is correct when the app is built and deployed but incorrect when running the tests.
* Hence we extend the base class with this for the tests.
*
* @param basePath where to look for the assets/templates/*.mjml files
*/
constructor(private basePath: string) {
super()
}

protected async getEmailTemplate(templateName: TemplateType): Promise<ReturnType<typeof mjml>> {
try {
const file = await readFile(
path.resolve(this.basePath, `./assets/templates/${templateName}.mjml`),
{ encoding: 'utf-8' },
)
return mjml(file)
} catch (error) {
Logger.error(`getEmailTemplate`, error)
throw error
}
}

protected async getEmailData(templateName: string): Promise<EmailMetadata> {
try {
const contents = await readFile(
path.resolve(this.basePath, `./assets/templates/${templateName}.json`),
{ encoding: 'utf-8' },
)
return JSON.parse(contents)
} catch (error) {
Logger.error(`getEmailData`, error)
throw error
}
}
}
Loading

0 comments on commit 0176dde

Please sign in to comment.