Department Master
Navigation Path
Company → Masters → Department Master
1. Department List Page
URL
/masters/department-master
Page Description
- Displays a list of all departments configured in the system
- Allows admins to manage organizational departments
- Provides actions to add, edit, and delete department records
List Table Columns
| Column Name | Description |
|---|---|
| S No | Serial number |
| Department Name | Name of the department |
| Description | Department description |
| Actions | Edit and Delete options |
Row Actions
| Action | Description |
|---|---|
| Edit | Opens Edit Department page with pre-filled data |
| Delete | Opens delete confirmation alert |
2. Add Department Page
Triggered From
Department List Page → Add Department button
Page Description
- Allows admins to create a new department
- Used for employee mapping, reporting, and organizational structure
Add Department – Fields
| Field Name | Type | Mandatory | Description |
|---|---|---|---|
| Department Name | Text Input | Yes | Enter department name |
| Description | Text Input | No | Enter department description |
Actions
| Action | Behavior |
|---|---|
| Save | Validates and saves the department |
| Reset | Clears all entered values |
| Cancel | Returns to Department List page |
Validation Rules
- Department Name is mandatory
- Duplicate department names are not allowed
3. Edit Department Page
Triggered From
Department List Page → Edit icon
Page Description
- Allows updating existing department details
- All fields are pre-filled with saved data
Editable Fields
| Field Name | Editable |
|---|---|
| Department Name | Yes |
| Description | Yes |
Actions
| Action | Behavior |
|---|---|
| Update | Saves changes |
| Cancel | Discards changes and navigates back |
4. Delete Department Confirmation Alert
Triggered From
Department List Page → Delete icon
Alert Content
- Confirmation message before deletion
Actions:
- Confirm / Yes → Deletes the department
- Cancel → Closes the alert without action
Delete Behavior
- Department is removed permanently after confirmation
- Deletion may be restricted if the department is mapped to employees or other records
Field Definitions, Usage, and Calculation Logic
This section provides a technical analysis of the Department Master's data structure and its role in organizational hierarchy.
1. Field Definitions
| Field Name | Data Type | Description | Example Value |
|---|---|---|---|
departmentName | String | Official name of the department (Required). | Human Resources |
companyId | ObjectId | Reference to the parent Company. | 60a8b... |
isDeleted | Object | Soft-delete state and audit metadata. | { status: false, ... } |
2. Field Usage & System Impact
| Category | Validation / Rule | System Behavior |
|---|---|---|
| Categorization | departmentName | Primary label for grouping employees in reports and organizational charts. |
| Integrity | Unique Index | A partial index ensures departmentName is unique for active records within a company. |
| Lifecycle | Soft-Delete | Ensures historical data (e.g., old payroll runs) keeps its reference to the department even after it's deactivated. |
3. Business & Calculation Logic
The Department Master operates as a foundational entity for organizational reporting.
A. Unique Identity Management
The system enforces department uniqueness using a MongoDB partial index:
- Scope: The uniqueness of
departmentNameis only evaluated whereisDeleted.statusisfalse. - Tenant Isolation: All operations are strictly partitioned by
companyId, allowing different tenants to have overlapping department names.
B. Bulk Import Engine
The allInOneDepartmentImport logic facilitates the mass upload of organizational structures:
- Mapping: It maps the Excel
descriptioncolumn directly todepartmentName. - Upsert Strategy: If a department with the same name exists (and is not deleted), it updates the existing record with any new metadata; otherwise, a new department is initialized.
- Error Handling: Missing descriptions or duplicate names in the import file are captured in an error log returned to the user, ensuring partial success for valid rows.
C. Relational Integrity
Departments are a mandatory reference in Designations, Units, and Employee Profiles. Deletion is logically restricted at the controller level if active employee records are still assigned to the department.
The Department Master module interacts with the following API endpoints:
Base URL
export const DEPARTMENT_URL = '/api/departmentMaster'
Endpoints
| Endpoint | Method | Description | Parameters/Body |
|---|---|---|---|
${DEPARTMENT_URL} | POST | Create a new department | Body: data |
${DEPARTMENT_URL} | GET | Get all departments | Query: page, limit |
${DEPARTMENT_URL}/:departmentId | GET | Get department by ID | Path: departmentId |
${DEPARTMENT_URL}/:departmentId | PATCH | Update an existing department | Path: departmentId, Body: body |
${DEPARTMENT_URL}/delete/:departmentId | PATCH | Delete a department | Path: departmentId |
RTK Query Hooks
The following hooks are available for frontend integration:
useCreateDepartmentMutationuseGetAllDepartmentsQueryuseGetDepartmentByIdQueryuseUpdateDepartmentMutationuseDeleteDepartmentMutation
End of Documentation