Warehouse Management
Relevant source files
The following files were used as context for generating this wiki page:
Warehouse Management is a core module of the Outmanage logistics system responsible for managing physical storage facilities, inventory association, and personnel assignments. It serves as the foundational entity for logistics operations, linking users and products to specific physical locations to ensure accurate tracking of outbound goods.
The module provides comprehensive CRUD (Create, Read, Update, Delete) capabilities, a robust audit logging system, and administrative tools for assigning users to specific warehouses. It integrates tightly with the Role-Based Access Control (RBAC) system to restrict access to sensitive inventory data based on user assignments.
Sources: CLAUDE.md:25-30, comprehensive-swagger-api.json:11-15
Architecture and Data Flow
The Warehouse Management system follows a standard controller-service-repository pattern using Express.js and Prisma ORM. Requests are validated via Joi schemas before being processed by the service layer, which handles transactional database operations and audit logging.
Component Relationship
The following diagram illustrates how Warehouses relate to other core entities in the system:
The diagram represents the primary relationships where a warehouse acts as a container for products and a management unit for users.
Sources: src/services/warehouseService.ts:35-50, src/schemas/warehouse.ts:5-15, comprehensive-swagger-api.json:240-260
Key Features
Warehouse Lifecycle Management
The system supports full lifecycle management of warehouse entities. Deletion is protected by business logic constraints: a warehouse cannot be deleted if it is currently assigned to users or contains associated products.
Sources: src/controllers/warehouseController.ts:245-275, src/services/warehouseService.ts:210-230
User Assignment
Administrators can assign or unassign users to specific warehouses. This assignment is critical for the system's security model, as it filters the data a user can see based on their physical location.
Sources: src/controllers/warehouseController.ts:285-320, src/services/warehouseService.ts:235-265
Audit Logging
Every modification to a warehouse (creation, update, or deletion) is captured by the warehouseLogService. Logs store both the old and new states of the data in JSON format, providing a complete audit trail.
Sources: src/services/warehouseLogService.ts:40-80, src/services/warehouseService.ts:145-160
API Reference
Data Models
| Field | Type | Description | Constraints |
|---|---|---|---|
id | UUID | Unique identifier | Primary Key |
code | String | Short unique code for the warehouse | 2-20 characters |
name | String | Descriptive name of the facility | 3-100 characters |
description | String | Additional details (Optional) | Max 500 characters |
createdAt | DateTime | Jakarta Time (+7) timestamp | Auto-generated |
Sources: src/schemas/warehouse.ts:7-35, comprehensive-swagger-api.json:240-265
Primary Endpoints
| Method | Endpoint | Description |
|---|---|---|
GET | /api/warehouses | Paginated list of warehouses with search |
POST | /api/warehouses | Create a new warehouse |
GET | /api/warehouses/{id} | Get detailed info including assigned users/products |
PUT | /api/warehouses/{id} | Update warehouse metadata |
POST | /api/warehouses/{id}/users | Assign a user to the warehouse |
DELETE | /api/warehouses/{id}/users/{userId} | Remove user assignment |
Sources: src/controllers/warehouseController.ts:15-30, comprehensive-swagger-api.json:480-550
Internal Logic: Timezone Handling
All warehouse operations enforce the Asia/Jakarta (GMT+7) timezone. When creating or updating records, the service layer manually adjusts UTC dates to Jakarta time before persisting to the database.
// src/services/warehouseService.ts:140-145
async createWarehouse(data: WarehouseCreateInput, performedById: string) {
return prisma.$transaction(async (tx) => {
const jakartaTime = new Date();
jakartaTime.setHours(jakartaTime.getHours() + 7);
const warehouse = await tx.warehouse.create({
data: {
...data,
createdAt: jakartaTime,
},
// ...
Sources: src/services/warehouseService.ts:140-145, CLAUDE.md:75-80
Deletion Workflow
The system implements a strict "Hard Delete" for warehouses, but only after safety checks are passed.
This flow ensures data integrity by preventing the removal of warehouses that still serve as parents to other active entities.
Sources: src/controllers/warehouseController.ts:245-275, src/services/warehouseService.ts:210-230
Conclusion
Warehouse Management provides the structural hierarchy necessary for Outmanage's outbound logistics. By maintaining strict relationships between warehouses, products, and users—and enforcing these through transactional services and comprehensive logging—the system ensures that inventory data remains organized and auditable across multiple physical locations.