Departments
Organizational units structuring the Renewa One team. Departments define team hierarchy, skill-level ownership, and are used for responsibility filtering in Document Obtaining and access scoping in RBAC Authorization.
Source Files
| Layer | Path |
|---|---|
| Schema | backend/src/db/schema.ts (line ~405) |
| Routes | backend/src/routes/admin/departments/ (department-crud.ts, members.ts) |
| Admin Page | frontend/src/pages/admin/TeamDepartments.tsx |
| Team Page | frontend/src/pages/internal/TeamPage.tsx |
| Filter Context | frontend/src/contexts/ResponsibilityFilterContext.tsx |
Database Tables
| Table | Purpose |
|---|---|
departments | Main entity — localized name, code, skill level, ownership flag |
user_departments | M2M join with Users (userId, departmentId, isPrimary) |
Key Fields
| Field | Type | Notes |
|---|---|---|
name | jsonb (LocalizedText) | Bilingual name {de, en} |
code | varchar(30) | Unique internal code (e.g., RENOVATION_MANAGEMENT, OPM_PRO, SALES) |
shortName | varchar(20) | Badge/UI label (e.g., SAM, FP, FD, EBO) |
skill | enum | pro or basic — skill level this department handles |
isOwner | boolean | Whether this is the “owner” department for its skill level |
description | jsonb (LocalizedText) | Bilingual description |
Skill-Level Ownership
Departments are categorized by the project skill level they handle:
| Skill | Owner Dept | Meaning |
|---|---|---|
pro | SAM Pro | Owns PRO-level projects (complex renovations) |
basic | SAL Basic | Owns BASIC-level projects (simpler renovations) |
The isOwner flag determines which department is the primary owner for projects at that skill level.
Relationships
Department 1──* User Departments ──* Users
Department -- used by --> Document Obtaining (responsibility filter)
Department -- used by --> RBAC Authorization (team lead scoping)
User-Department Membership
The user_departments join table supports:
- Multiple departments per user
isPrimaryflag to mark the user’s main department- Used by team leads to scope their admin access (see RBAC Authorization)
Frontend
- Admin page (
TeamDepartments.tsx) — CRUD for departments, member management - Team page (
TeamPage.tsx) — internal team directory grouped by department - Responsibility filter (
ResponsibilityFilterContext.tsx) — context provider that lets users filter views by department responsibility
Access Scoping
Team leads see only users in departments they manage. This is enforced in:
backend/src/routes/admin/users/user-crud.ts— filters user lists by managed departmentsbackend/src/middleware/rbac.ts—requireTeamLeadOrAdminmiddleware
Related Pages
Users | Document Obtaining | RBAC Authorization | Admin Dashboard | Database Architecture | Service Layer Pattern