Locales as enums
This commit is contained in:
		@@ -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"
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user