Skip to content

Add categories admin CRUD endpoints#600

Merged
Perdolique merged 1 commit into
masterfrom
next-iteration
Apr 6, 2026
Merged

Add categories admin CRUD endpoints#600
Perdolique merged 1 commit into
masterfrom
next-iteration

Conversation

@Perdolique
Copy link
Copy Markdown
Owner

Summary

Added complete admin category management API 💪😎 with proper validation patterns and FK safety:

New categories admin endpoints 🆕

  • POST /api/equipment/categories — create new categories with slug validation
  • PATCH /api/equipment/categories/[id] — update category metadata and slug
  • DELETE /api/equipment/categories/[id] — remove categories (protected by FK RESTRICT)
  • 308 test cases for category CRUD operations covering success paths, validation errors, FK restrictions, and admin authorization

Refactored shared validation 🔧

  • Extracted reusable validation schemas for brands, groups, and categories into server/utils/validation/schemas.ts
  • Migrated brands and groups endpoints to use shared patterns (removed 400+ lines of duplicate validation code 🎉)
  • Base record types (brandBaseRecord, groupBaseRecord, categoryBaseRecord) for consistent API responses
  • 170 new validation schema tests — guards against regressions in slug format, length limits, and request structure

Database safety improvements 🛡️

  • Migration adds RESTRICT foreign keys from equipment_itemsbrands and equipment_itemsequipment_categories
  • Cannot delete brands or categories that are still referenced by catalog items 🚫
  • Prevents silent data loss when deleting reference data (brands/categories stay in DB until orphaned)

Documentation updates 📚

  • Updated AGENTS.md with new API conventions and FK behavior
  • Moved categories work to plan/completed.md
  • Created plan/tech-debt.md for intentional follow-up work (FK error mapping, shared length limits finish, OAuth tests)

Motivation

Categories are the third admin entity after brands and groups 🏗️. This iteration completes the reference data CRUD foundation before moving to item management. The validation refactor was necessary because brands/groups/categories share 90% of their validation logic (slug format, name length, description) — extracting shared schemas eliminated duplication and makes future changes easier to maintain 🧹.

The RESTRICT FK constraints protect the catalog data model 🔒 — without them, deleting a brand or category could silently remove all items in that category from user inventories. The FK blocks destructive deletes at the database level, forcing a safe cleanup workflow (reassign items first, then delete reference data).

Testing notes

All endpoints covered by Vitest unit tests 🧪. No E2E changes required — admin UI iteration comes later. Run validation:

pnpm run test:unit:ci
pnpm run test:typecheck  
pnpm run lint:oxlint

Known tech debt

Documented in plan/tech-debt.md 📝:

  • FK violation errors currently return 500 instead of 409 Conflict with a clear "in use" message
  • A few hardcoded varchar lengths in schema still need migration to shared limits
  • createOAuthUser() lacks direct unit coverage (next OAuth iteration)

None of these block the current iteration from shipping 🚀. The delete endpoints work correctly (FK blocks the delete), they just return a generic error code until the error mapping iteration.

- ✨ Create, update, and delete category endpoints
- ✅ Add comprehensive test coverage for categories API
- 🗃️ Add database migration for equipment_categories
- ♻️ Refactor brands and groups to use shared validation patterns
- 🔧 Extract base record types for API consistency
- 📚 Update AGENTS.md and plan documentation
- ✅ Add validation schema tests
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 6, 2026

🎉 Deployed to Cloudflare!

@Perdolique Perdolique marked this pull request as ready for review April 6, 2026 19:36
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements full CRUD operations for equipment categories and refactors the existing brand and group admin endpoints to utilize database transactions. This ensures atomicity between data mutations and contribution logging. The database schema has been updated to use 'restrict' on foreign keys for brands and categories to prevent accidental cascading deletes, and a new canonical slug validation has been introduced for reference data. Documentation and technical debt tracking have also been updated to reflect these changes. Feedback was provided regarding the removal of several security and validation tests in the groups test suite, which should be restored to maintain coverage for authentication and input validation.

Comment thread server/api/equipment/groups/__tests__/update-delete.test.ts
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 72cdde4eff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/utils/validation/schemas.ts
@Perdolique Perdolique merged commit 25f2ef2 into master Apr 6, 2026
11 checks passed
@Perdolique Perdolique deleted the next-iteration branch April 6, 2026 19:47
@Perdolique Perdolique self-assigned this Apr 6, 2026
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