-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added email module and upcoming event email, close #255
- Loading branch information
cuma.duran
committed
Jul 3, 2023
1 parent
ddd7f77
commit 318ec8c
Showing
14 changed files
with
2,906 additions
and
937 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/nest-cli", | ||
"collection": "@nestjs/schematics", | ||
"sourceRoot": "src" | ||
"sourceRoot": "src", | ||
"compilerOptions": { | ||
"assets": [ | ||
{ "include": "**/*.hbs","watchAssets": true } | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {UserEntity} from "@core/data/entities"; | ||
|
||
import {MAIL_TEMPLATES} from "../../../modules/providers/mail/models/enums"; | ||
|
||
export type Attachment = { | ||
filename: string; | ||
path: string; | ||
cid: string; | ||
} | ||
export type CodexMailOptions = { | ||
from?: string; | ||
subject: string; | ||
template: MAIL_TEMPLATES; | ||
context?: object; | ||
attachments?: Attachment[]; | ||
} | ||
export abstract class IMailService<T> { | ||
abstract send: (user: UserEntity, options?: CodexMailOptions) => Promise<T>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ export enum Status { | |
pending = 2, | ||
ongoing = 3, | ||
finished = 4, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import config from '@core/config/configuration'; | ||
import { Module } from '@nestjs/common'; | ||
import { MailerModule } from '@nestjs-modules/mailer'; | ||
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter'; | ||
import { join } from 'path'; | ||
|
||
import { MailService } from './mail.service'; | ||
|
||
@Module({ | ||
imports: [ | ||
MailerModule.forRoot({ | ||
transport: { | ||
host: config.mail.host, | ||
port: Number(config.mail.port) || 465, | ||
secure: Boolean(config.mail.secure) || true, | ||
auth: { | ||
user: config.mail.user, | ||
pass: config.mail.password, | ||
}, | ||
}, | ||
template: { | ||
dir: join(__dirname, 'templates'), | ||
adapter: new HandlebarsAdapter(), | ||
options: { | ||
strict: true, | ||
}, | ||
}, | ||
}), | ||
], | ||
providers: [MailService], | ||
exports: [MailService], | ||
}) | ||
export class MailModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import config from '@core/config/configuration'; | ||
import { UserEntity } from '@core/data/entities'; | ||
import {CodexMailOptions, IMailService} from "@core/data/services/mail.service"; | ||
import { Injectable } from '@nestjs/common'; | ||
import { MailerService } from '@nestjs-modules/mailer'; | ||
|
||
import { MAIL_DEFAULT_FROM, MAIL_DEFAULT_SUBJECT } from "./models/constants"; | ||
|
||
@Injectable() | ||
export class MailService implements IMailService<any> { | ||
constructor(private mailerService: MailerService) {} | ||
|
||
async send(user: UserEntity, options: CodexMailOptions) { | ||
try { | ||
if(Boolean(config.mail.isEnabled)){ | ||
await this.mailerService.sendMail({ | ||
to: user.email, | ||
from: options.from || MAIL_DEFAULT_FROM, | ||
subject: options.subject || MAIL_DEFAULT_SUBJECT, | ||
template: options.template, | ||
attachments:options.attachments ?? [], | ||
context: { | ||
name: user.name, | ||
discord: config.social.discord, | ||
email: config.social.email, | ||
...options?.context | ||
}, | ||
}); | ||
} | ||
} catch (e){ | ||
console.warn("Mail could not send: ", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import config from '@core/config/configuration'; | ||
export const MAIL_DEFAULT_FROM = ` "Codex Team" <${config.mail.address}>`; | ||
export const MAIL_DEFAULT_SUBJECT = "Noreply | Codex Team"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export enum MAIL_TEMPLATES { | ||
upcoming = "./upcoming-event", | ||
} |
Oops, something went wrong.