Skip to content

Commit

Permalink
chore: Improve TS definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
sashko9807 committed Jun 19, 2024
1 parent 5848f97 commit 3ab25f8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/api/src/notifications/dto/massmail.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiProperty } from '@nestjs/swagger'
import { Expose } from 'class-transformer'
import { IsDate, IsDateString, IsNumber, IsOptional, IsString } from 'class-validator'
import { IsDateString, IsNumber, IsOptional, IsString } from 'class-validator'

export class MassMailDto {
@ApiProperty()
Expand Down
4 changes: 1 addition & 3 deletions apps/api/src/notifications/notifications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import { CampaignService } from '../campaign/campaign.service'
import { KeycloakTokenParsed } from '../auth/keycloak'
import { MassMailDto } from './dto/massmail.dto'
import { randomUUID } from 'crypto'
import { MailDataRequired } from '@sendgrid/mail'
import { PersonalizationData } from '@sendgrid/helpers/classes/personalization'
import { mapChunk } from '../common/mapChunk'

type UnregisteredInsert = {
Expand Down Expand Up @@ -570,7 +568,7 @@ export class MarketingNotificationsService {
})
}
async sendConsentMail(data: MassMailDto) {
const contacts = await this.marketingNotificationsProvider.getContactsFromList(data.listId)
const contacts = await this.marketingNotificationsProvider.getContactsFromList(data)

const sendList: ContactsMap = new Map()
const emailList = contacts.map((contact: ContactsResponse) => contact.email)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import sgClient from '@sendgrid/client'
import sgMail from '@sendgrid/mail'
import { NotificationsProviderInterface } from './notifications.interface.providers'
import {
ContactsFromListParams,
ContactsResponse,
SendGridExportStatusResponse,
SendGridParams,
Expand Down Expand Up @@ -81,7 +82,7 @@ export class SendGridNotificationsProvider
return response.body as SendGridExportStatusResponse
}

async getContactsFromList(listId: string) {
async getContactsFromList({ listId }: ContactsFromListParams) {
const SENDGRID_EXPORT_TIMEOUT = 10000
const RETRY_LIMIT = 5
let numOfRetries = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type SendGridParams = {
RemoveFromUnsubscribedParams: RemoveFromUnsubscribedParams
AddToUnsubscribedParams: AddToUnsubscribedParams
SendNotificationParams: SendNotificationParams
GetContactsFromListParam: any
GetContactsFromListParam: ContactsFromListParams

// Responses
CreateListRes: string
Expand All @@ -23,12 +23,15 @@ export type SendGridParams = {
RemoveFromUnsubscribedRes: unknown
AddToUnsubscribedRes: unknown
SendNotificationRes: unknown
GetContactsFromListRes: any
GetContactsFromListRes: ContactsResponse[]

// Implementation specific
ContactData: ContactData
}

export type ContactsFromListParams = {
listId: string
}
type ContactData = {
email: string
first_name?: string
Expand Down

0 comments on commit 3ab25f8

Please sign in to comment.