Locales as enums

This commit is contained in:
Nicolai Ort 2021-03-02 18:12:15 +01:00
parent 6e99ad5c1c
commit d450ecbf7c
1 changed files with 21 additions and 9 deletions

View File

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