42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import {Options} from "nodemailer/lib/mailer";
|
|
import {ParsedUrlQueryInput} from "querystring";
|
|
|
|
import {QueryParams, QueryParamsRecord} from "../common/Routing.js";
|
|
import MailError from "./MailError.js";
|
|
import MailTemplate from "./MailTemplate.js";
|
|
|
|
export default class Mail {
|
|
private readonly options: Options = {};
|
|
|
|
public constructor(
|
|
private readonly template: MailTemplate,
|
|
private readonly data: QueryParamsRecord = {},
|
|
) {
|
|
this.options.subject = this.template.getSubject(data);
|
|
|
|
this.verifyData();
|
|
}
|
|
|
|
private verifyData() {
|
|
for (const forbiddenField of [
|
|
'to',
|
|
]) {
|
|
if (this.data[forbiddenField] !== undefined) {
|
|
throw new MailError(`Can't use reserved data.${forbiddenField}.`);
|
|
}
|
|
}
|
|
}
|
|
|
|
public getTemplate(): MailTemplate {
|
|
return this.template;
|
|
}
|
|
|
|
public getData(): QueryParamsRecord {
|
|
return {...this.data};
|
|
}
|
|
|
|
public getOptions(): Options {
|
|
return {...this.options};
|
|
}
|
|
}
|