Repository navigation
feat: Implement recruiting email templates (#19) - #25
Conversation
VidurShah
left a comment
There was a problem hiding this comment.
Thanks Aysel. The placeholder validation and the live preview are nice, and the shared rendering helpers are a good idea. A few things need changing before this can go in; details inline.
| }); | ||
|
|
||
| describe("Email template endpoints", () => { | ||
| it("GET returns the email templates", async () => { |
There was a problem hiding this comment.
This test fails on a fresh database (it fails in CI): it expects at least one template, but nothing seeds them. Could the test insert what it needs first? Also, the PUT tests change real rows and never clean up. Main's DB tests wrap each test in a transaction that rolls back (see semesters/members tests); could these follow that pattern?
| import { validate } from "../lib/validation"; | ||
| import { errorResponse } from "../lib/errors"; | ||
|
|
||
| export const emailTemplateRoutes = new Hono() |
There was a problem hiding this comment.
Per CONTRIBUTING, business rules belong in apps/api/src/services. Could the kind check, placeholder validation and upsert move into a services/email-templates.ts, with this route just calling it? For the :kind param, parsing with emailKindSchema.safeParse(...) would also replace the manual EMAIL_KINDS.some(...) check and the as EmailKind cast.
|
|
||
| body: text("body").notNull(), | ||
|
|
||
| // TODO(auth): Add foreign key to members once the members table exists. |
There was a problem hiding this comment.
The members table exists on main now, so this can become a real foreign key (.references(() => members.id, { onDelete: "set null" })). Also, updatedBy is never set anywhere. Fine to leave as TODO(auth) until sessions map to members, but the FK can go in now. Small one: pgEnum("email_kind", EMAIL_KINDS) would reuse the shared list instead of repeating it.
| }, | ||
| ]; | ||
|
|
||
| async function seedEmailTemplates() { |
There was a problem hiding this comment.
This is a separate script that nothing runs, so bun run db:seed won't create the templates. Could you fold it into src/db/seed.ts (same onConflictDoNothing pattern as positions)? Also, it never closes the DB connection, so the script may hang. seed.ts uses finally { await db.$client.end() }.
| return match; | ||
| } | ||
|
|
||
| return escapeHtml(vars[key] ?? ""); |
There was a problem hiding this comment.
This HTML-escapes every value, including in the subject, which is plain text, so a subject would show & instead of &. In the preview, React escapes again, so a value like O'Brien shows as O'Brien. Maybe add an escape option (on for the HTML body when sending, off for subjects and the preview)?
Migration regenerated as 0008 on top of main's 0001-0007. email_kind is now built from EMAIL_KINDS (moved to shared enums with the other enum lists), and updated_by gets its foreign key to members now that the table exists (TDD 3.1).
- routes/email-templates.ts imported src/db at the top, so the whole API
failed to start without DATABASE_URL; load it on first use
- PUT records email_template.update in the audit log (TDD 2.5) in the same
transaction as the edit, only when something changed
- seedEmailTemplates is exported and called from db/seed.ts
- The invite placeholder is {{inviteUrl}}, a link, instead of the raw token;
the default invite template now includes it
- Tests seed the defaults first and restore the invite template afterward,
so they pass on an empty database and don't leave edits behind; new tests
for the audit entry, the no-change case, seed idempotence, and that every
default uses only allowed placeholders
VidurShah
left a comment
There was a problem hiding this comment.
Reviewed and test-merged with the rest of this round; full CI passes.
Summary
Implements the recruiting email templates functionality for Issue #19.
Changes
Testing
Notes
Closes #19