UNPKG

@wepublish/api

Version:
47 lines (46 loc) 1.51 kB
import { PrismaClient, User } from '@prisma/client'; import { MailContext } from './mail-context'; export declare enum mailLogType { SubscriptionFlow = 0, UserFlow = 1, SystemMail = 2 } export type MailControllerConfig = { daysAwayFromEnding?: number | null; externalMailTemplateId: string; recipient: User; isRetry?: boolean; periodicJobRunDate?: Date | null; optionalData: Record<string, any>; mailType: mailLogType; }; export declare class MailController { private readonly prismaService; private readonly mailContext; private readonly config; private readonly logger; constructor(prismaService: PrismaClient, mailContext: MailContext, config: MailControllerConfig); /** * Build a string uniquely identifying the email delivery * @returns the identification string */ private generateMailIdentifier; /** * Get the number of mails with the specified MailIdentifier. Any number > 0 * means the mail was already sent. * @returns number of mails with this identifier */ private checkIfMailIsSent; /** * Build the data for passing it to the mail templates * @returns a HashMap of configuration data */ private buildData; /** * Send an email using a specific template with the configured mail provider. * This method stores an entry in the MailLog table for referencing and * re-trying the delivery. * @returns void */ sendMail(): Promise<void>; }