46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { Authorized, JsonController, Post, QueryParam } from 'routing-controllers';
|
|
import { OpenAPI } from 'routing-controllers-openapi';
|
|
import { Mailer } from '../Mailer';
|
|
|
|
/**
|
|
* The mail controller handels all endpoints concerning Mail sending.
|
|
*/
|
|
@JsonController()
|
|
@Authorized()
|
|
@OpenAPI({ security: [{ "AuthToken": [] }] })
|
|
export class MailController {
|
|
private mailer: Mailer = new Mailer();
|
|
private initialized: boolean = false;
|
|
|
|
@Post('/reset')
|
|
@OpenAPI({ description: "Sends reset mails" })
|
|
async sendReset(@QueryParam("locale") locale: string) {
|
|
if (!this.initialized) {
|
|
await this.mailer.init();
|
|
this.initialized = true;
|
|
}
|
|
try {
|
|
this.mailer.sendResetMail("todo", "lelele", locale)
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
return;
|
|
}
|
|
|
|
@Post('/test')
|
|
@OpenAPI({ description: "Sends test mails" })
|
|
async sendTest(@QueryParam("locale") locale: string) {
|
|
if (!this.initialized) {
|
|
await this.mailer.init();
|
|
this.initialized = true;
|
|
}
|
|
try {
|
|
this.mailer.sendTestMail(locale)
|
|
} catch (error) {
|
|
console.log(error)
|
|
throw error;
|
|
}
|
|
return;
|
|
}
|
|
}
|