Skip to content

Commit f26626d

Browse files
committed
Add email template
1 parent f6b5314 commit f26626d

File tree

8 files changed

+601
-123
lines changed

8 files changed

+601
-123
lines changed

backend/user-service/config/redis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ const client = createClient({ url: REDIS_URI });
99

1010
client.on("error", (err) => console.log(`Error: ${err}`));
1111

12-
await client.connect();
12+
(async () => await client.connect())();
1313

1414
export default client;

backend/user-service/controller/user-controller.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { upload } from "../config/multer";
2525
import { uploadFileToFirebase } from "../utils/utils";
2626
import redisClient from "../config/redis";
2727
import crypto from "crypto";
28-
import { sendMail } from "../utils/mailer";
28+
import { sendAccVerificationMail } from "../utils/mailer";
2929
import { ACCOUNT_VERIFICATION_SUBJ } from "../utils/constants";
3030

3131
export async function createUser(
@@ -85,10 +85,12 @@ export async function createUser(
8585

8686
const emailToken = crypto.randomBytes(16).toString("hex");
8787
await redisClient.set(email, emailToken, { EX: 60 * 5 }); // expire in 5 minutes
88-
const emailText = `Hello ${username},\n\n
89-
Please click on the following link to verify your account:\n\nhttp://localhost:3001/api/users/verify-email/${email}/${emailToken}\n\n
90-
If you did not request this, please ignore this email.`;
91-
await sendMail(email, ACCOUNT_VERIFICATION_SUBJ, emailText);
88+
await sendAccVerificationMail(
89+
email,
90+
ACCOUNT_VERIFICATION_SUBJ,
91+
username,
92+
`http://localhost:3001/api/users/verify-email/${email}/${emailToken}`
93+
);
9294

9395
return res.status(201).json({
9496
message: `Created new user ${username} successfully`,

backend/user-service/jest.config.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
* https://jestjs.io/docs/configuration
44
*/
55

6-
import type { Config } from "jest";
6+
// import type { Config } from "jest";
7+
import type { JestConfigWithTsJest } from "ts-jest";
78

8-
const config: Config = {
9+
const config: JestConfigWithTsJest = {
910
// All imported modules in your tests should be mocked automatically
1011
// automock: false,
1112

@@ -52,6 +53,8 @@ const config: Config = {
5253
// Make calling deprecated APIs throw helpful error messages
5354
// errorOnDeprecated: false,
5455

56+
extensionsToTreatAsEsm: [".ts"],
57+
5558
// The default configuration for fake timers
5659
// fakeTimers: {
5760
// "enableGlobally": false
@@ -90,7 +93,9 @@ const config: Config = {
9093
// ],
9194

9295
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
93-
// moduleNameMapper: {},
96+
moduleNameMapper: {
97+
"^(\\.{1,2}/.*)\\.js$": "$1",
98+
},
9499

95100
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
96101
// modulePathIgnorePatterns: [],
@@ -175,7 +180,23 @@ const config: Config = {
175180
// testRunner: "jest-circus/runner",
176181

177182
// A map from regular expressions to paths to transformers
178-
// transform: undefined,
183+
transform: {
184+
"^.+\\.tsx?$": [
185+
"ts-jest",
186+
{
187+
diagnostics: {
188+
ignoreCodes: [1343],
189+
},
190+
astTransformers: {
191+
before: [
192+
{
193+
path: "node_modules/ts-jest-mock-import-meta", // or, alternatively, 'ts-jest-mock-import-meta' directly, without node_modules.
194+
},
195+
],
196+
},
197+
},
198+
],
199+
},
179200

180201
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
181202
// transformIgnorePatterns: [

0 commit comments

Comments
 (0)