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

LayerPath
Schemabackend/src/db/schema.ts (line ~405)
Routesbackend/src/routes/admin/departments/ (department-crud.ts, members.ts)
Admin Pagefrontend/src/pages/admin/TeamDepartments.tsx
Team Pagefrontend/src/pages/internal/TeamPage.tsx
Filter Contextfrontend/src/contexts/ResponsibilityFilterContext.tsx

Database Tables

TablePurpose
departmentsMain entity — localized name, code, skill level, ownership flag
user_departmentsM2M join with Users (userId, departmentId, isPrimary)

Key Fields

FieldTypeNotes
namejsonb (LocalizedText)Bilingual name {de, en}
codevarchar(30)Unique internal code (e.g., RENOVATION_MANAGEMENT, OPM_PRO, SALES)
shortNamevarchar(20)Badge/UI label (e.g., SAM, FP, FD, EBO)
skillenumpro or basic — skill level this department handles
isOwnerbooleanWhether this is the “owner” department for its skill level
descriptionjsonb (LocalizedText)Bilingual description

Skill-Level Ownership

Departments are categorized by the project skill level they handle:

SkillOwner DeptMeaning
proSAM ProOwns PRO-level projects (complex renovations)
basicSAL BasicOwns 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
  • isPrimary flag 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 departments
  • backend/src/middleware/rbac.tsrequireTeamLeadOrAdmin middleware

Users | Document Obtaining | RBAC Authorization | Admin Dashboard | Database Architecture | Service Layer Pattern