Locales as enums

This commit is contained in:
Nicolai Ort 2021-03-02 18:12:15 +01:00
parent 6e99ad5c1c
commit d450ecbf7c

View File

@ -14,34 +14,34 @@ export class MailController {
private initialized: boolean = false; private initialized: boolean = false;
@Post('/reset') @Post('/reset')
@OpenAPI({ description: "Sends reset mails" }) @OpenAPI({ description: "Sends reset mails", parameters: [{ in: "query", name: "locale", schema: { type: "string", enum: ["de", "en"] } }] })
async sendReset(@QueryParam("locale") locale: string) { async sendReset(@QueryParam("locale") locale: locales) {
if (!this.initialized) { if (!this.initialized) {
await this.mailer.init(); await this.mailer.init();
this.initialized = true; this.initialized = true;
} }
try { try {
this.mailer.sendResetMail("todo", "lelele", locale) this.mailer.sendResetMail("todo", "lelele", locale?.toString())
} catch (error) { } catch (error) {
throw error; throw error;
} }
return new SuccessResponse(); return new SuccessResponse(locale);
} }
@Post('/test') @Post('/test')
@OpenAPI({ description: "Sends test mails" }) @OpenAPI({ description: "Sends test mails", parameters: [{ in: "query", name: "locale", schema: { type: "string", enum: ["de", "en"] } }] })
async sendTest(@QueryParam("locale") locale: string) { async sendTest(@QueryParam("locale") locale: locales) {
if (!this.initialized) { if (!this.initialized) {
await this.mailer.init(); await this.mailer.init();
this.initialized = true; this.initialized = true;
} }
try { try {
this.mailer.sendTestMail(locale) this.mailer.sendTestMail(locale?.toString())
} catch (error) { } catch (error) {
console.log(error) console.log(error)
throw error; throw error;
} }
return new SuccessResponse(); return new SuccessResponse(locale);
} }
} }
@ -54,5 +54,17 @@ export class SuccessResponse {
success: boolean = true; success: boolean = true;
@IsString() @IsString()
message: "Sent!" message: string = "Sent!"
@IsString()
locale: locales;
constructor(locale?: locales) {
this.locale = locale || locales.en;
}
}
export enum locales {
de = "de",
en = "en"
} }