setup and invite

This commit is contained in:
Julian Krauser 2024-08-25 13:36:19 +02:00
parent 03e0f90279
commit 7df7cf2697
23 changed files with 515 additions and 43 deletions

38
src/helpers/mailHelper.ts Normal file
View file

@ -0,0 +1,38 @@
import { Transporter, createTransport, TransportOptions } from "nodemailer";
export default class MailHelper {
private readonly transporter: Transporter;
constructor() {
this.transporter = createTransport({
host: process.env.MAIL_HOST,
port: Number(process.env.MAIL_PORT),
secure: (process.env.MAIL_SECURE as "true" | "false") == "true",
auth: {
user: process.env.MAIL_USERNAME,
pass: process.env.MAIL_PASSWORD,
},
} as TransportOptions);
}
/**
* @description send mail
* @param {string} target
* @param {string} subject
* @param {string} content
* @returns {Prmose<*>}
*/
async sendMail(target: string, subject: string, content: string): Promise<any> {
return new Promise((resolve, reject) => {
this.transporter
.sendMail({
from: `"${process.env.CLUB_NAME}" <${process.env.MAIL_USERNAME}>`,
to: target,
subject,
text: content,
})
.then((info) => resolve(info.messageId))
.catch((e) => reject(e));
});
}
}

View file

@ -0,0 +1,28 @@
import { Request, Response } from "express";
import BadRequestException from "../exceptions/badRequestException";
export default class ParamaterPassCheckHelper {
static requiredIncluded(testfor: Array<string>, obj: object) {
let result = testfor.every((key) => Object.keys(obj).includes(key));
if (!result) throw new BadRequestException(`not all required parameters included: ${testfor.join(",")}`);
}
static forbiddenIncluded(testfor: Array<string>, obj: object) {
let result = testfor.some((key) => Object.keys(obj).includes(key));
if (!result) throw new BadRequestException(`PPC: forbidden parameters included: ${testfor.join(",")}`);
}
static requiredIncludedMiddleware(testfor: Array<string>): (req: Request, res: Response, next: Function) => void {
return (req: Request, res: Response, next: Function) => {
this.requiredIncluded(testfor, req.body);
next();
};
}
static forbiddenIncludedMiddleware(testfor: Array<string>): (req: Request, res: Response, next: Function) => void {
return (req: Request, res: Response, next: Function) => {
this.requiredIncluded(testfor, req.body);
next();
};
}
}