Skip to content

Commit

Permalink
Change default email transport config to smtp to Mailcatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
francisli committed Oct 11, 2024
1 parent cef0523 commit b6c443b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 31 deletions.
8 changes: 6 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ S3_USER_UPLOADS_ACCESS_KEY_ID=minioadmin
S3_USER_UPLOADS_SECRET_ACCESS_KEY=minioadmin
S3_USER_UPLOADS_BUCKET_NAME=compass-files

EMAIL=no.reply.project.compass@gmail.com
EMAIL_PASS=
EMAIL_SERVICE=smtp
EMAIL_AUTH_USER=
EMAIL_AUTH_PASS=
EMAIL_FROM=no-reply@compassiep.org
EMAIL_HOST=localhost
EMAIL_PORT=1025
19 changes: 13 additions & 6 deletions src/backend/lib/nodemailer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { createTransport } from "nodemailer";
import SMTPTransport from "nodemailer/lib/smtp-transport";
import { Env } from "./types";

export const getTransporter = (environment: Env) =>
createTransport({
service: "gmail",
export const getTransporter = (env: Env) => {
const options: SMTPTransport.Options = {
service: env.EMAIL_SERVICE,
auth: {
user: environment.EMAIL,
pass: environment.EMAIL_PASS,
user: env.EMAIL_AUTH_USER,
pass: env.EMAIL_AUTH_PASS,
},
});
};
if (env.EMAIL_SERVICE === "smtp") {
options.host = env.EMAIL_HOST;
options.port = parseInt(env.EMAIL_PORT, 10);
}
return createTransport(options);
};
8 changes: 6 additions & 2 deletions src/backend/lib/types/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export interface Env {
S3_USER_UPLOADS_ACCESS_KEY_ID: string;
S3_USER_UPLOADS_SECRET_ACCESS_KEY: string;
S3_USER_UPLOADS_BUCKET_NAME: string;
EMAIL: string;
EMAIL_PASS: string;
EMAIL_SERVICE: string;
EMAIL_AUTH_USER: string;
EMAIL_AUTH_PASS: string;
EMAIL_FROM: string;
EMAIL_HOST: string;
EMAIL_PORT: string;
}
28 changes: 14 additions & 14 deletions src/backend/routers/case_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const case_manager = router({
const studentData = await req.ctx.db
.selectFrom("iep")
.fullJoin("student", (join) =>
join.onRef("student.student_id", "=", "iep.student_id")
join.onRef("student.student_id", "=", "iep.student_id"),
)
.where("assigned_case_manager_id", "=", userId)
.select([
Expand Down Expand Up @@ -57,7 +57,7 @@ export const case_manager = router({
last_name: z.string(),
email: z.string().email(),
grade: z.number(),
})
}),
)
.mutation(async (req) => {
const { userId } = req.ctx.auth;
Expand All @@ -80,7 +80,7 @@ export const case_manager = router({
last_name: z.string(),
email: z.string().email(),
grade: z.number(),
})
}),
)
.mutation(async (req) => {
const { student_id, first_name, last_name, email, grade } = req.input;
Expand Down Expand Up @@ -119,7 +119,7 @@ export const case_manager = router({
.input(
z.object({
student_id: z.string(),
})
}),
)
.mutation(async (req) => {
const { student_id } = req.input;
Expand All @@ -139,7 +139,7 @@ export const case_manager = router({
.innerJoin(
"paras_assigned_to_case_manager",
"user.user_id",
"paras_assigned_to_case_manager.para_id"
"paras_assigned_to_case_manager.para_id",
)
.where("paras_assigned_to_case_manager.case_manager_id", "=", userId)
.selectAll()
Expand All @@ -158,22 +158,22 @@ export const case_manager = router({
first_name: z.string(),
last_name: z.string(),
email: z.string().email(),
})
}),
)
.mutation(async (req) => {
const para = await createPara(
req.input,
req.ctx.db,
req.ctx.auth.userId,
req.ctx.env.EMAIL,
req.ctx.env.EMAIL_FROM,
req.input.email,
req.ctx.env
req.ctx.env,
);

return await assignParaToCaseManager(
para?.user_id || "",
req.ctx.auth.userId,
req.ctx.db
req.ctx.db,
);
}),

Expand All @@ -184,13 +184,13 @@ export const case_manager = router({
.input(
z.object({
para_id: z.string(),
})
}),
)
.mutation(async (req) => {
await assignParaToCaseManager(
req.input.para_id,
req.ctx.auth.userId,
req.ctx.db
req.ctx.db,
);
return;
}),
Expand All @@ -202,7 +202,7 @@ export const case_manager = router({
first_name: z.string(),
last_name: z.string(),
email: z.string().email(),
})
}),
)
.mutation(async (req) => {
const { para_id, first_name, last_name, email } = req.input;
Expand All @@ -214,7 +214,7 @@ export const case_manager = router({
.innerJoin(
"paras_assigned_to_case_manager",
"user.user_id",
"paras_assigned_to_case_manager.para_id"
"paras_assigned_to_case_manager.para_id",
)
.where("paras_assigned_to_case_manager.case_manager_id", "=", userId)
.selectAll();
Expand All @@ -240,7 +240,7 @@ export const case_manager = router({
.input(
z.object({
para_id: z.string(),
})
}),
)
.mutation(async (req) => {
const { para_id } = req.input;
Expand Down
8 changes: 4 additions & 4 deletions src/backend/routers/para.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const para = router({
first_name: z.string(),
last_name: z.string(),
email: z.string().email(),
})
}),
)
.mutation(async (req) => {
const { email } = req.input;
Expand All @@ -49,9 +49,9 @@ export const para = router({
req.input,
req.ctx.db,
req.ctx.auth.session.user?.name ?? "",
req.ctx.env.EMAIL,
req.ctx.env.EMAIL_FROM,
email,
req.ctx.env
req.ctx.env,
);

return para;
Expand Down Expand Up @@ -90,7 +90,7 @@ export const para = router({
.where("trial_data.created_by_user_id", "=", userId)
.where("trial_data.submitted", "=", true)
.select(({ fn }) =>
fn.count("trial_data.trial_data_id").as("completed_trials")
fn.count("trial_data.trial_data_id").as("completed_trials"),
)
.as("completed_trials"),
])
Expand Down
10 changes: 7 additions & 3 deletions src/backend/tests/fixtures/get-test-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface GetTestServerOptions {

export const getTestServer = async (
t: ExecutionContext,
{ authenticateAs }: GetTestServerOptions = {}
{ authenticateAs }: GetTestServerOptions = {},
) => {
const [
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Expand All @@ -38,8 +38,12 @@ export const getTestServer = async (
S3_USER_UPLOADS_ACCESS_KEY_ID: minio.accessKey,
S3_USER_UPLOADS_SECRET_ACCESS_KEY: minio.secretKey,
S3_USER_UPLOADS_BUCKET_NAME: minio.bucket,
EMAIL: "example string",
EMAIL_PASS: "example string",
EMAIL_SERVICE: "example string",
EMAIL_FROM: "example string",
EMAIL_AUTH_USER: "example string",
EMAIL_AUTH_PASS: "example string",
EMAIL_HOST: "example string",
EMAIL_PORT: "example string",
};

// Use statically-built Next.js fixture (if multiple instances of the built-in next() dev server are running, they try to concurrently mutate the same files).
Expand Down

0 comments on commit b6c443b

Please sign in to comment.