Skip to content

[BE-04] Implement Departments module — CRUD with per-department asset counts #1063

Description

@yusuftomilola

Overview

The frontend Departments page (frontend/app/(dashboard)/departments/page.tsx) is fully built — create/edit/delete forms are done — but every call fails because there is no departments API. Departments are also a required relation on assets and users.

What to Build

A DepartmentsModule in backend/src/departments/ with:

Entity: id (uuid), name (unique), description (nullable), createdAt, updatedAt.

Method Path Description
GET /api/departments List all, each with assetCount
POST /api/departments Create { name, description? }
PATCH /api/departments/:id Update name/description
DELETE /api/departments/:id Delete (reject or block if assets are still assigned)

API Contract

frontend/lib/api/assets.tsgetDepartments() expects DepartmentWithCount[] ({ id, name, description, assetCount }), plus createDepartment, updateDepartment, deleteDepartment.

References

  • Prior implementation: git show f28e3f8~1 -- backend/src/ (departments logic lived under the deleted modules)
  • Blocked by [BE-01] (guards)

Acceptance Criteria

  • CRUD endpoints match the frontend client exactly
  • assetCount computed per department (0 until assets module lands)
  • Duplicate department name returns 409
  • Deleting a department with assigned assets returns 409 with a clear message
  • Protected with JwtAuthGuard

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions