Repository navigation
Add admin notify --user for per-user emails - #461
Conversation
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR461Version: 🤖 Updated on each push. |
Code Review — PR #461 (admin notify --user)Reviewed: backend migration, broadcast service, admin routes, CLI command, api.ts, and test file. CriticalC1. Migration has no explicit transaction — risk of partial table rebuild The rebuild sequence is: C2. This is the first migration in the project to use ImportantI1. The current interface: export interface SingleUserLookupResult {
ok: boolean;
email?: string;
user_id?: number;
username?: string;
error?: SingleUserLookupError;
}TypeScript can't narrow export type SingleUserLookupResult =
| { ok: true; email: string; user_id: number; username: string }
| { ok: false; error: SingleUserLookupError; user_id?: number; username?: string };I2.
I3.
SuggestionsS1. Signup enforces S2. Both the per-user and the group paths call Nice-to-havesN1. The new schema tests are good and mock-free. The False positives (skipped)
|
|
Round-2 fix pass — addressed all 5 findings from the review.
Tests: |
Closes #381.
Summary
nemar admin notifylearns a new--user <username>flag for sendingtransactional emails to a single approved user.
--toand--useraremutually exclusive; exactly one must be supplied.
POST /admin/notifyaccepts an alternateuserpayload field; therequest schema's refinement enforces the same exclusivity at the API
boundary.
getBroadcastRecipientByUsername()returns astructured
{ ok, email, user_id, username, error }result so theroute maps clean error codes:
announcementsemail preference (these aredirect admin contact, not broadcasts).
recipient_grouprecordsuser:<username>for per-usersends so the group/transactional distinction is queryable later. A new
migration (
0021_broadcast_user_recipient.sql) rebuilds thebroadcast_emailstable so its CHECK constraint accepts both theexisting enum values (
all/admins/members) and the newuser:<username>form. Existing rows migrate verbatim.Notes / decisions
string[]ofemail addresses; the issue mentioned returning recipient objects with
{user_id, email, ...}, but the only consumer issendBroadcast(),which doesn't need the user_id. Per-user metadata is captured
upstream via the audit
recipient_group: user:<username>field, sothis keeps the existing API surface minimal.
--dry-runworks with--user: shows a single recipientand the
user:<username>label.Test plan
bun test test/broadcast.test.ts(1 pre-existing unrelatedfailure on the
osc.earthliteral, tracked in P1: 4 failing tests on dev — fix and add CI gate to prevent regression #452)bun run buildcd backend && bun run typecheck