Skip to content

Commit

Permalink
Merge branch 'master' into campaign-news-functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
igoychev authored Jun 17, 2023
2 parents d8938a5 + a7c100f commit 87b2904
Show file tree
Hide file tree
Showing 25 changed files with 763 additions and 109 deletions.
14 changes: 8 additions & 6 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ JWT_SECRET_KEY=VerySecretPrivateKey

## Iris Bank Imports ##
##########
IRIS_API_URL = https://developer.sandbox.irispay.bg/api/8
IRIS_AGENT_HASH =
IRIS_USER_HASH =
BANK_BIC = UNCRBGSF
PLATFORM_IBAN =
IMPORT_TRX_TASK_INTERVAL_MINUTES = 60
IRIS_API_URL=https://developer.sandbox.irispay.bg/api/8
IRIS_AGENT_HASH=
IRIS_USER_HASH=
BANK_BIC=UNCRBGSF
PLATFORM_IBAN=
IMPORT_TRX_TASK_INTERVAL_MINUTES=60
CHECK_IRIS_CONSENT_TASK_HOUR=10
BILLING_ADMIN_MAIL=[email protected]
15 changes: 9 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ JWT_SECRET_KEY=VerySecretPrivateKey

## Iris Bank Imports ##
##########
IRIS_API_URL = https://developer.sandbox.irispay.bg/api/8
IRIS_AGENT_HASH =
IRIS_USER_HASH =
BANK_BIC = UNCRBGSF
PLATFORM_IBAN =
IMPORT_TRX_TASK_INTERVAL_MINUTES = 60
IRIS_API_URL=https://developer.sandbox.irispay.bg/api/8
IRIS_AGENT_HASH=
IRIS_USER_HASH=
BANK_BIC=UNCRBGSF
PLATFORM_IBAN=
IMPORT_TRX_TASK_INTERVAL_MINUTES=60
#which hour of the day to run the check for consent
CHECK_IRIS_CONSENT_TASK_HOUR=10
BILLING_ADMIN_MAIL=[email protected]
2 changes: 1 addition & 1 deletion apps/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { ExportModule } from '../export/export.module'
import { JwtModule } from '@nestjs/jwt'
import { NotificationModule } from '../sockets/notifications/notification.module'
import { ScheduleModule } from '@nestjs/schedule'
import { TasksModule } from '../tasks//bank-import/tasks.module'
import { TasksModule } from '../tasks/tasks.module'
import { BankTransactionsModule } from '../bank-transactions/bank-transactions.module'
import { CampaignNewsModule } from '../campaign-news/campaign-news.module'
import { CampaignNewsFileModule } from '../campaign-news-file/campaign-news-file.module'
Expand Down
3 changes: 3 additions & 0 deletions apps/api/src/assets/templates/expiring-iris-consent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"subject": "Изтичащо съгласие за достъп до банкова информация"
}
72 changes: 72 additions & 0 deletions apps/api/src/assets/templates/expiring-iris-consent.mjml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<mjml>
<mj-body background-color="#ffffff" font-size="13px">
<mj-section
background-color="#009FE3"
vertical-align="top"
padding-bottom="0px"
padding-top="0">
<mj-column vertical-align="top" width="100%">
<mj-text
align="left"
color="#ffffff"
font-size="45px"
font-weight="bold"
font-family="open Sans Helvetica, Arial, sans-serif"
padding-left="25px"
padding-right="25px"
padding-bottom="30px"
padding-top="50px">
Засечени са неразпознати банкови дарения
</mj-text>
</mj-column>
</mj-section>
<mj-section background-color="#009fe3" padding-bottom="20px" padding-top="20px">
<mj-column vertical-align="middle" width="100%">
<mj-text
align="left"
color="#ffffff"
font-size="22px"
font-family="open Sans Helvetica, Arial, sans-serif"
padding-left="25px"
padding-right="25px">
<br /><br />
</mj-text>
<mj-text
align="left"
color="#ffffff"
font-size="15px"
font-family="open Sans Helvetica, Arial, sans-serif"
padding-left="25px"
padding-right="25px">
Остават <strong> {{daysToExpire}} дни </strong> до изтичането на разрешението за достъп до
банковата информация, необходимо за извличане на транзакциите в системата на Podkrepi.bg.
Дата на изтичане е <strong> {{expiresAt}} </strong>. Можете да подновите разрешението за
още 90 дни(максимален период) като кликнете на бутона:
</mj-text>

<mj-button
background-color="#feeb35"
font-family="Helvetica, Arial, sans-serif"
font-size="16px"
border-radius="30px"
color="#000000"
padding="15px 30px"
href="{{renewLink}}"
target="_blank">
Поднови банковото разрешение
</mj-button>

<mj-text
align="left"
color="#ffffff"
font-size="15px"
font-family="open Sans Helvetica, Arial, sans-serif"
padding-left="25px"
padding-right="25px">
Поздрави, <br />
Екипът на Подкрепи.бг
</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
3 changes: 3 additions & 0 deletions apps/api/src/assets/templates/unrecognized-donation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"subject": "Неразпознато банково дарение/я"
}
94 changes: 94 additions & 0 deletions apps/api/src/assets/templates/unrecognized-donation.mjml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<mjml>
<mj-body background-color="#ffffff" font-size="13px">
<mj-section
background-color="#009FE3"
vertical-align="top"
padding-bottom="0px"
padding-top="0">
<mj-column vertical-align="top" width="100%">
<mj-text
align="left"
color="#ffffff"
font-size="45px"
font-weight="bold"
font-family="open Sans Helvetica, Arial, sans-serif"
padding-left="25px"
padding-right="25px"
padding-bottom="30px"
padding-top="50px">
Засечени са неразпознати банкови дарения
</mj-text>
</mj-column>
</mj-section>
<mj-section background-color="#009fe3" padding-bottom="20px" padding-top="20px">
<mj-column vertical-align="middle" width="100%">
<mj-text
align="left"
color="#ffffff"
font-size="22px"
font-family="open Sans Helvetica, Arial, sans-serif"
padding-left="25px"
padding-right="25px">
<br /><br />
</mj-text>
<mj-text
align="left"
color="#ffffff"
font-size="15px"
font-family="open Sans Helvetica, Arial, sans-serif"
padding-left="25px"
padding-right="25px">
При последния извършен импорт на банкови дарения от {{ importDate}} бяха засечени
транзакции, чиито код на кампания не е бил разпознат или импортът е бил неуспешен:
</mj-text>

<mj-table color="#ffffff" width="100%">
<tr
style="border-bottom: 1px solid #ffffff"
align="left"
color="#ffffff"
font-size="15px"
font-family="open Sans Helvetica, Arial, sans-serif">
<th style="padding: 10px" width="16%">Транз. №</th>
<th style="padding: 10px" width="16%">Изпращач</th>
<th style="padding: 10px" width="16%">Сума</th>
<th style="padding: 10px" width="31%">Основание</th>
<th style="padding: 10px" width="16%">Статус</th>
</tr>
<mj-raw> {{#each transactions}} </mj-raw>
<tr style="border-bottom: 1px solid #ffffff">
<td style="padding: 10px">{{ id }}</td>
<td style="padding: 10px">{{ senderName }}</td>
<td style="padding: 10px">{{ amount }}</td>
<td style="padding: 10px; word-break: break-word">{{ description }}</td>
<td style="padding: 10px">{{ bankDonationStatus }}</td>
</tr>
<mj-raw> {{/each}} </mj-raw>
</mj-table>

<mj-button
background-color="#feeb35"
font-family="Helvetica, Arial, sans-serif"
font-size="16px"
border-radius="30px"
color="#000000"
padding="15px 30px"
href="{{link}}"
target="_blank">
Към Банкови Транзакции
</mj-button>

<mj-text
align="left"
color="#ffffff"
font-size="15px"
font-family="open Sans Helvetica, Arial, sans-serif"
padding-left="25px"
padding-right="25px">
Поздрави, <br />
Екипът на Подкрепи.бг
</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
4 changes: 3 additions & 1 deletion apps/api/src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ export default () => ({
bankBIC: process.env.BANK_BIC,
platformIBAN: process.env.PLATFORM_IBAN,
apiUrl: process.env.IRIS_API_URL,
consentEndPoint: process.env.IRIS_API_URL + '/consent',
getConsentEndPoint: process.env.IRIS_API_URL + '/consent',
checkConsentEndPoint: process.env.IRIS_API_URL + '/consents/{ibanID}',
banksEndPoint: process.env.IRIS_API_URL + '/banks?country=bulgaria',
ibansEndPoint: process.env.IRIS_API_URL + '/ibans',
transactionsEndPoint: process.env.IRIS_API_URL + '/transactions',
billingAdminEmail: process.env.BILLING_ADMIN_MAIL,
},
tasks: {
import_transactions: { interval: process.env.IMPORT_TRX_TASK_INTERVAL_MINUTES },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export class CreateBankTransactionDto {
type: BankTransactionType
@ApiProperty({ enum: BankDonationStatus })
bankDonationStatus?: BankDonationStatus
notified?: boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export class UpdateBankTransactionDto {
type?: BankTransactionType
@ApiProperty({ enum: BankDonationStatus })
bankDonationStatus?: BankDonationStatus
notified?: boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export class BankTransaction {
matchedRef: string | null
type: BankTransactionType
bankDonationStatus: BankDonationStatus | null
notified: boolean | null
}
26 changes: 22 additions & 4 deletions apps/api/src/donations/donations.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
Query,
Logger,
Res,
Inject,
forwardRef,
NotFoundException,
} from '@nestjs/common'
import { ApiQuery, ApiTags } from '@nestjs/swagger'
import { DonationStatus } from '@prisma/client'
Expand All @@ -28,11 +31,15 @@ import { CreatePaymentIntentDto } from './dto/create-payment-intent.dto'
import { DonationQueryDto } from '../common/dto/donation-query-dto'
import { CancelPaymentIntentDto } from './dto/cancel-payment-intent.dto'
import { DonationsApiQuery } from './queries/donations.apiquery'
import { PersonService } from '../person/person.service'

@ApiTags('donation')
@Controller('donation')
export class DonationsController {
constructor(private readonly donationsService: DonationsService) {}
constructor(
private readonly donationsService: DonationsService,
@Inject(forwardRef(() => PersonService)) private readonly personService: PersonService,
) {}

@Get('export-excel')
@DonationsApiQuery()
Expand Down Expand Up @@ -97,7 +104,9 @@ export class DonationsController {

@Get('user-donations')
async userDonations(@AuthenticatedUser() user: KeycloakTokenParsed) {
return await this.donationsService.getDonationsByUser(user.sub)
const person = await this.personService.findOneByKeycloakId(user.sub);
if(!person) throw new NotFoundException("User was not found");
return await this.donationsService.getDonationsByUser(user.sub, person.email)
}

@Get('money')
Expand Down Expand Up @@ -160,8 +169,17 @@ export class DonationsController {
}

@Get('user/:id')
userDonationById(@Param('id') id: string, @AuthenticatedUser() user: KeycloakTokenParsed) {
return this.donationsService.getUserDonationById(id, user.sub)
async userDonationById(@Param('id') id: string, @AuthenticatedUser() user: KeycloakTokenParsed) {
const person = await this.personService.findOneByKeycloakId(user.sub);
if(!person) throw new NotFoundException("User was not found");
const donation = await this.donationsService.getUserDonationById(id, user.sub, person.email)
return {
...donation,
person: {
firstName: person.firstName,
lastName: person.lastName
}
}
}

@Post('create-payment')
Expand Down
19 changes: 16 additions & 3 deletions apps/api/src/donations/donations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,17 @@ export class DonationsService {
async getUserDonationById(
id: string,
keycloakId: string,
email: string,
): Promise<(Donation & { person: Person | null }) | null> {
return await this.prisma.donation.findFirst({
where: { id, person: { keycloakId }, status: DonationStatus.succeeded },
where: {
id,
status: DonationStatus.succeeded,
OR:[
{billingEmail: email},
{person: { keycloakId }}
]
},
include: {
person: {
select: {
Expand Down Expand Up @@ -629,9 +637,14 @@ export class DonationsService {
}
}

async getDonationsByUser(keycloakId: string) {
async getDonationsByUser(keycloakId: string, email: string) {
const donations = await this.prisma.donation.findMany({
where: { person: { keycloakId } },
where: {
OR:[
{billingEmail: email},
{person: { keycloakId }},
]
} ,
orderBy: [{ createdAt: 'desc' }],
include: {
targetVault: {
Expand Down
19 changes: 19 additions & 0 deletions apps/api/src/email/template.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Prisma } from '@prisma/client'
import { CreatePersonDto } from '../person/dto/create-person.dto'
import { CreateInquiryDto } from '../support/dto/create-inquiry.dto'
import { CreateRequestDto } from '../support/dto/create-request.dto'
Expand All @@ -8,6 +9,8 @@ export enum TemplateType {
inquiryReceived = 'inquiry-received',
inquiryReceivedInternal = 'inquiry-received-internal',
forgotPass = 'forgot-password',
unrecognizedDonation = 'unrecognized-donation',
expiringIrisConsent = 'expiring-iris-consent',
}
export type TemplateTypeKeys = keyof typeof TemplateType
export type TemplateTypeValues = typeof TemplateType[TemplateTypeKeys]
Expand Down Expand Up @@ -54,3 +57,19 @@ export class InquiryReceivedEmailDto extends EmailTemplate<CreateInquiryDto> {
export class InquiryReceivedInternalEmailDto extends EmailTemplate<CreateInquiryDto> {
name = TemplateType.inquiryReceivedInternal
}

export class UnrecognizedDonationEmailDto extends EmailTemplate<{
transactions: Partial<Prisma.BankTransactionCreateManyInput>[]
importDate: string
link: string
}> {
name = TemplateType.unrecognizedDonation
}

export class ExpiringIrisConsentEmailDto extends EmailTemplate<{
daysToExpire: number
expiresAt: string
renewLink: string
}> {
name = TemplateType.expiringIrisConsent
}
Loading

0 comments on commit 87b2904

Please sign in to comment.