Skip to content

feat: add web FAQs schema and router#35

Open
BIA3IA wants to merge 7 commits into
mainfrom
bianca/faqs
Open

feat: add web FAQs schema and router#35
BIA3IA wants to merge 7 commits into
mainfrom
bianca/faqs

Conversation

@BIA3IA

@BIA3IA BIA3IA commented Jun 4, 2026

Copy link
Copy Markdown

No description provided.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: efe83103-5985-44c8-87dc-ed5522c9eb89

📥 Commits

Reviewing files that changed from the base of the PR and between b3243da and db961e8.

📒 Files selected for processing (1)
  • src/routers/web/faqs.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/routers/web/faqs.ts

Walkthrough

Adds migrations and Drizzle snapshots, TypeScript table schemas, tRPC CRUD routes, and router wiring to implement a bilingual (IT/EN) FAQ system with audit fields and cascade deletes.

Changes

FAQ Management Feature

Layer / File(s) Summary
Database schema migrations and snapshots
drizzle/0013_oval_dreaming_celestial.sql, drizzle/0014_remarkable_synch.sql, drizzle/meta/0013_snapshot.json, drizzle/meta/0014_snapshot.json, drizzle/meta/_journal.json
Creates web_faq_categories and web_faqs with identity PKs, audit timestamps, FKs to tg_permissions, and cascading category deletes; renames Italian fields to *_it and adds required English *_en columns; snapshots and journal record migration history.
TypeScript Drizzle ORM schema definitions
src/db/schema/web/faqs.ts, src/db/schema/web/index.ts
Adds faqCategories and faqs Drizzle table schemas with localized fields, creator/modifier FKs, shared time columns, and cascade category relationship; merges them into the web schema export.
FAQ CRUD API endpoints
src/routers/web/faqs.ts
New tRPC router with getAllFaqs (categories with nested FAQs), addFaqs/addFaqsCategory (insert), editFaqs/editFaqsCategory (update by id), and deleteFaqs/deleteFaqsCategory (delete by id); inputs validated with Zod and DB ops return rows or { error: "NOT_FOUND" }/{ error: null }.
Main application router integration
src/routers/web/index.ts, src/routers/index.ts
Composes webRouter exposing faqs and registers it on the main appRouter as the web sub-router, making endpoints available under web.faqs.*.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly summarizes the main change: adding FAQ schema and router with multilingual support and CRUD operations across database migrations, Drizzle schemas, and tRPC procedures.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@BIA3IA BIA3IA marked this pull request as draft June 4, 2026 14:45

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
src/routers/tg/groups.ts (1)

176-176: 💤 Low value

Consider using > 0 for cache invalidation defensively.

The === 1 check assumes telegramId uniqueness. While this is likely correct, using > 0 for invalidation would be more defensive against data anomalies, while still returning === 1 for the API contract.

♻️ Suggested defensive invalidation
 const rows = await DB.delete(GROUPS).where(eq(GROUPS.telegramId, input.telegramId)).returning()
-if (rows.length === 1) invalidateGroupsCache()
+if (rows.length > 0) invalidateGroupsCache()
 return rows.length === 1

Same pattern for setHide:

-if (rows.length === 1) invalidateGroupsCache()
+if (rows.length > 0) invalidateGroupsCache()
 return rows.length === 1

Also applies to: 193-193

🤖 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/tg/groups.ts` at line 176, The cache invalidation currently
checks for rows.length === 1 which assumes telegramId uniqueness; change the
condition to rows.length > 0 so any deleted/updated rows cause
invalidateGroupsCache() to run defensively; update both occurrences where
invalidateGroupsCache() is called after DB operations (the block with if
(rows.length === 1) invalidateGroupsCache() and the similar check in setHide) to
use > 0 while keeping the API contract that callers still expect a single-row
result where appropriate.
drizzle/0013_oval_dreaming_celestial.sql (1)

15-25: ⚡ Quick win

Index web_faqs.category_id to prevent FK/cascade scan bottlenecks.

category_id is constrained by FK, but it is not indexed. On larger datasets, category reads and category deletions with cascade can trigger slower scans.

💡 Suggested migration addition
 ALTER TABLE "web_faqs" ADD CONSTRAINT "web_faqs_modified_by_id_tg_permissions_user_id_fk" FOREIGN KEY ("modified_by_id") REFERENCES "public"."tg_permissions"("user_id") ON DELETE no action ON UPDATE no action;
+--> statement-breakpoint
+CREATE INDEX "web_faqs_category_id_idx" ON "web_faqs" ("category_id");
🤖 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 `@drizzle/0013_oval_dreaming_celestial.sql` around lines 15 - 25, Add an index
on web_faqs.category_id to avoid FK/cascade scan bottlenecks: create an index
(preferably concurrently in production) on the column referenced by the foreign
key (web_faqs.category_id) so operations involving the constraint
web_faqs_category_id_web_faq_categories_id_fk run efficiently; include the index
creation in the migration that introduces or follows the FK (name it clearly,
e.g., idx_web_faqs_category_id) and ensure the migration handles existence
checks if rerunnable.
🤖 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/faqs.ts`:
- Around line 12-27: The response schema for getAllFaqs currently omits category
and faq IDs; update the output Zod schemas used in getAllFaqs to include id
fields (e.g., add id: z.string() or z.number() as appropriate) on the category
object and on each faq object so edit/delete mutations can target records; apply
the same addition in both schema blocks referenced (the top-level categories
array and the nested faqs array) and keep nullable/optional types consistent
with your DB model.
- Around line 50-187: All mutating endpoints (addFaqs, addFaqsCategory,
editFaqs, editFaqsCategory, deleteFaqs, deleteFaqsCategory) are currently
public; add explicit auth/role checks at the start of each mutation to require
an authenticated user and appropriate role (e.g., admin or faq-manager) by
inspecting the request context (ctx.user or ctx.session) and fail fast with an
authorization error (throw TRPCError with code "UNAUTHORIZED" or return { error:
"UNAUTHORIZED" }). Also ensure createdBy/modifiedBy values come from ctx.user.id
(or validate they match) instead of trusting client input. Implement the checks
consistently in each mutation before performing DB operations.

---

Nitpick comments:
In `@drizzle/0013_oval_dreaming_celestial.sql`:
- Around line 15-25: Add an index on web_faqs.category_id to avoid FK/cascade
scan bottlenecks: create an index (preferably concurrently in production) on the
column referenced by the foreign key (web_faqs.category_id) so operations
involving the constraint web_faqs_category_id_web_faq_categories_id_fk run
efficiently; include the index creation in the migration that introduces or
follows the FK (name it clearly, e.g., idx_web_faqs_category_id) and ensure the
migration handles existence checks if rerunnable.

In `@src/routers/tg/groups.ts`:
- Line 176: The cache invalidation currently checks for rows.length === 1 which
assumes telegramId uniqueness; change the condition to rows.length > 0 so any
deleted/updated rows cause invalidateGroupsCache() to run defensively; update
both occurrences where invalidateGroupsCache() is called after DB operations
(the block with if (rows.length === 1) invalidateGroupsCache() and the similar
check in setHide) to use > 0 while keeping the API contract that callers still
expect a single-row result where appropriate.
🪄 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: 2702614c-ded4-4aad-b0d5-23d8785c3b87

📥 Commits

Reviewing files that changed from the base of the PR and between 07aa3c1 and 73f4f0b.

📒 Files selected for processing (11)
  • drizzle/0013_oval_dreaming_celestial.sql
  • drizzle/0014_remarkable_synch.sql
  • drizzle/meta/0013_snapshot.json
  • drizzle/meta/0014_snapshot.json
  • drizzle/meta/_journal.json
  • src/db/schema/web/faqs.ts
  • src/db/schema/web/index.ts
  • src/routers/index.ts
  • src/routers/tg/groups.ts
  • src/routers/web/faqs.ts
  • src/routers/web/index.ts

Comment thread src/routers/web/faqs.ts
Comment thread src/routers/web/faqs.ts
@BIA3IA BIA3IA marked this pull request as ready for review June 8, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant