-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(server): use event emitter instead of kafka * fix formatting * bump version to 0.3.3
- Loading branch information
1 parent
12f6e52
commit 2a20dd9
Showing
8 changed files
with
206 additions
and
49 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Joi from "joi"; | ||
|
||
const commonConfigSchema = { | ||
PORT: Joi.number().default(3000), | ||
PEZZO_CLOUD: Joi.boolean().default(false), | ||
PINO_PRETTIFY: Joi.boolean().default(false), | ||
DATABASE_URL: Joi.string().required(), | ||
SUPERTOKENS_CONNECTION_URI: Joi.string().required(), | ||
SUPERTOKENS_API_KEY: Joi.string().optional(), | ||
SUPERTOKENS_API_DOMAIN: Joi.string().default("http://localhost:3000"), | ||
SUPERTOKENS_WEBSITE_DOMAIN: Joi.string().default("http://localhost:4200"), | ||
INFLUXDB_URL: Joi.string().required(), | ||
INFLUXDB_TOKEN: Joi.string().required(), | ||
}; | ||
|
||
const cloudConfigSchema = { | ||
SENDGRID_API_KEY: Joi.string().required(), | ||
SEGMENT_KEY: Joi.string().required(), | ||
GOOGLE_OAUTH_CLIENT_ID: Joi.string().required(), | ||
GOOGLE_OAUTH_CLIENT_SECRET: Joi.string().required(), | ||
}; | ||
|
||
const isCloud = process.env.PEZZO_CLOUD === "true"; | ||
|
||
export const getConfigSchema = () => | ||
Joi.object({ | ||
...commonConfigSchema, | ||
...(isCloud ? cloudConfigSchema : {}), | ||
}); |
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,7 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { NotificationsService } from "./notifications.service"; | ||
|
||
@Module({ | ||
providers: [NotificationsService], | ||
}) | ||
export class NotificationsModule {} |
35 changes: 35 additions & 0 deletions
35
apps/server/src/app/notifications/notifications.service.ts
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,35 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { ConfigService } from "@nestjs/config"; | ||
import { OnEvent } from "@nestjs/event-emitter"; | ||
import { KafkaSchemas } from "@pezzo/kafka"; | ||
import sgMail, { MailDataRequired } from "@sendgrid/mail"; | ||
import { PinoLogger } from "../logger/pino-logger"; | ||
|
||
export const emailTemplates: Record<keyof KafkaSchemas, string> = { | ||
"org-invitation-created": "d-a36b6b8076b040ba89aff0dd5bf11936", | ||
}; | ||
|
||
@Injectable() | ||
export class NotificationsService { | ||
constructor(private config: ConfigService, private logger: PinoLogger) { | ||
sgMail.setApiKey(this.config.get("SENDGRID_API_KEY")); | ||
} | ||
|
||
@OnEvent("org-invitation-created") | ||
async sendOrgInvitationEmail(data: KafkaSchemas["org-invitation-created"]) { | ||
const templateId = emailTemplates["org-invitation-created"]; | ||
|
||
this.logger.info({ templateId, data }, "Sending org invitation email"); | ||
|
||
const mailData: MailDataRequired = { | ||
to: data.email, | ||
from: "Pezzo <[email protected]>", | ||
templateId, | ||
dynamicTemplateData: { | ||
...data, | ||
}, | ||
}; | ||
|
||
await sgMail.send(mailData); | ||
} | ||
} |
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 +1 @@ | ||
{"version":"0.3.1"} | ||
{"version":"0.3.3"} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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