feat: Add guides matricole schema and router#40
Conversation
WalkthroughChangesThe PR adds the Guides matricole
Sequence Diagram(s)sequenceDiagram
participant Client
participant guides_matricole_router
participant PostgreSQL
participant BlobStorage
Client->>guides_matricole_router: Submit guide FormData
guides_matricole_router->>PostgreSQL: Check version
guides_matricole_router->>BlobStorage: Upload PDF
BlobStorage-->>guides_matricole_router: Return file URL
guides_matricole_router->>PostgreSQL: Insert guide metadata
PostgreSQL-->>Client: Return inserted guide
Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
src/routers/web/guides_matricole.ts (1)
38-49: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd output schemas to mutations.
addGuidereturns either{ error: "DUPLICATE_VERSION" }or the full inserted row;deleteGuidereturns{ error: "NOT_FOUND" }or{ error: null }. Neither has an.output()schema, so clients lack type safety and the return shapes are inconsistent. Additionally, the raw insert exposes internal columns (created_by_id,modified_by_id, timestamps) to the client.Also applies to: 72-84
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/routers/web/guides_matricole.ts` around lines 38 - 49, Define explicit .output() schemas for addGuide and deleteGuide covering every success and error branch, then align their return values with those schemas; have addGuide map the inserted row to a client-safe shape that excludes internal columns such as created_by_id, modified_by_id, and timestamps, and preserve the documented DUPLICATE_VERSION, NOT_FOUND, and null-error responses.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/routers/web/guides_matricole.ts`:
- Around line 44-46: Remove createdBy from the client-controlled schema in
guideFormSchema.extend and derive it exclusively from the authenticated session
when constructing the guide record; update the related handler and validation
flow to use the session user identity rather than request FormData.
- Around line 53-56: Fix the TOCTOU race in the duplicate version handling of
the guide creation flow: remove reliance on the pre-insert check in the relevant
handler and catch the unique-constraint error from the INSERT, returning {
error: "DUPLICATE_VERSION" } and cleaning up the uploaded blob when it occurs.
Alternatively, make the duplicate check and insert atomic with a transaction,
ensuring constraint failures never surface as unhandled errors.
- Around line 38-49: Replace publicProcedure for addGuide and deleteGuide with
the project’s authenticated/admin-only procedure. Remove createdBy from the
input schema and derive it from the authenticated user context inside the
mutation handlers, using the existing auth/context symbols and preserving the
validated form fields.
- Around line 78-83: Update the deleteGuide mutation to delete the associated
Azure blob using the deleted row’s stored file value before or alongside
removing the database record. Add or use a blob-deletion helper in
src/azure/blob.ts, and invoke it from deleteGuide with the appropriate blob
identifier, while preserving the NOT_FOUND response when no row exists.
---
Nitpick comments:
In `@src/routers/web/guides_matricole.ts`:
- Around line 38-49: Define explicit .output() schemas for addGuide and
deleteGuide covering every success and error branch, then align their return
values with those schemas; have addGuide map the inserted row to a client-safe
shape that excludes internal columns such as created_by_id, modified_by_id, and
timestamps, and preserve the documented DUPLICATE_VERSION, NOT_FOUND, and
null-error responses.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e86ad082-50bb-4abf-8869-43eb1b904fc4
📒 Files selected for processing (7)
drizzle/0015_equal_the_spike.sqldrizzle/meta/0015_snapshot.jsondrizzle/meta/_journal.jsonsrc/db/schema/web/guides_matricole.tssrc/db/schema/web/index.tssrc/routers/web/guides_matricole.tssrc/routers/web/index.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/azure/blob.ts`:
- Around line 31-38: Wrap the body of deleteBlob in a try-catch, including URL
parsing, client creation, and deleteIfExists. Log the caught error with the blob
URL and relevant context, then return without rethrowing so deleteGuide can
complete successfully after the database row is removed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 87d54c5d-422d-45b8-8516-de49e6632765
📒 Files selected for processing (2)
src/azure/blob.tssrc/routers/web/guides_matricole.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/routers/web/guides_matricole.ts
Introduce a new schema and router for guides matricole.