Backend Developer Assignment: OfficeLeave ManagementSystem
Technical Challenge ��
Project Overview
Build a Leave Management System where employees can apply forleave,requiring dual
approval from both Reporting Manager and HR Manager before confirmation.
This mirrors the standard workflow used in Indian IT companies.
System Requirements
Technology Stack(Preferred)
• Framework: NestJS with TypeScript
• Database: PostgreSQL with TypeORM
• Testing: Jestframework
• Authentication: JWT-based
Core Workflow
1. Employee applies forleave → Status: pending
2. Reporting Manager reviews and approves → Status: pending_hr
3. HR Manager reviews and approves → Status: approved
4. Any rejection at either stage → Status: rejected
Database Schema
Core Entities
LeaveRequest {
id: string (UUID)
employeeId: string
leaveType: enum // casual, sick, vacation, maternity
startDate: Date
endDate: Date
totalDays: number
reason: string
status: enum // pending, approved, rejected
appliedAt: Date
documents?: string // optional medical certificate
}
Employee {
id: string (UUID)
employeeCode: string // "EMP001"
name: string
email: string
department: string // "Engineering", "HR", "Finance"
role: enum // employee, reporting_manager, hr_manager, admin
reportingManagerId?: string
joinDate: Date
isActive: boolean
}
LeaveApproval {
id: string (UUID)
leaveRequestId: string
approverId: string
approverType: enum // reporting_manager, hr_manager
action: enum // approve, reject
comments: string
timestamp: Date
}
LeaveWorkflow {
id: string (UUID)
leaveRequestId: string
reportingManagerApproval: boolean
hrManagerApproval: boolean
currentStage: enum // pending_rm, pending_hr, completed
createdAt: Date
}
Required APIs
Employee Leave Management
• POST /leaves - Apply for new leave
• GET /leaves - Get my leave history
• GET /leaves/:id - Get specific leave details
• PUT /leaves/:id - Update leave (draft status only)
• DELETE /leaves/:id - Cancel leave request
Manager Approvals
• GET /approvals/pending - Getleaves pending my approval
• POST /leaves/:id/approve - Approve leave request
• POST /leaves/:id/reject - Reject with comments
• GET /leaves/:id/approval-history - View complete approvaltrail
Admin Features
• GET /admin/leave-summary - Department-wise statistics
• GET /admin/pending-approvals - All pending approvals across organization
Business Rules
Leave Validation
• Annual Quotas: Casual(12 days), Sick (10 days), Vacation (18 days)
• Notice Period: Minimum 1 day advance notice for casual leave
• Medical Certificate: Required for sick leave > 3 days
• Date Restrictions: Cannot apply for past dates or weekend-only periods
Approval Workflow
• Sequential Approval: Reporting Manager → HR Manager
• Self-Approval Prevention: Employee cannot approve their own leave
• Unique Approvers: Both approvers must be different people
• Audit Trail: Every approval/rejection action must be logged
Leave Balance Calculation
Each employee receives annual leave quotas that must be tracked and validated
against new applications. Sample Test Scenarios
Unit Tests (Focus Areas)
describe('LeaveApprovalService', () => {
describe('Approval Workflow', () => {
it('should require reporting manager approval first')
it('should advance to HR stage after RM approval')
it('should confirm leave only after both approvals')
it('should prevent self-approval')
it('should maintain complete audit trail')
})
describe('Business Validations', () => {
it('should validate leave balance before approval')
it('should prevent overlapping leave requests')
it('should check annual quota limits')
it('should handle weekend/holiday edge cases')
})
})
Integration Tests
describe('Complete Leave Flow', () => {
it('should complete: Apply → RM Approve → HR Approve → Confirmed') it('should
handle: Apply → RM Reject → End')
it('should handle: Apply → RM Approve → HR Reject → End') })
Sample Data
Test Users
// Managers
{
name: "Priya Sharma",
role: "reporting_manager",
department: "Engineering"
},
{
name: "Amit Gupta",
role: "hr_manager",
department: "HR"
}
// Employees
{
name: "Rohit Singh",
role: "employee",
reportingManagerId: "[priya-id]"
}
Sample Leave Requests
[
{
reason: "Sister's wedding in Jaipur",
leaveType: "casual",
startDate: "2024-12-15",
endDate: "2024-12-17",
totalDays: 3
},
{
reason: "Fever and medical consultation",
leaveType: "sick",
startDate: "2024-12-20",
endDate: "2024-12-20",
totalDays: 1
}
]
Expected Deliverables
• ✅ Complete NestJS project setup
• ✅ Database entities and migrations
• ✅ Basic authentication (JWT)
• ✅ Employee and leave CRUD operations
• ✅ Leave application workflow
• ✅ Two-stage approval system
• ✅ Leave balance calculations
• ✅ Audittrail implementation
• ✅ Comprehensive test coverage
• ✅ Admin reporting features
Key Implementation Features
1. Approval Workflow Example
// Reporting Manager Approval
POST /leaves/123/approve
{
"comments": "Approved for family function",
"approverType": "reporting_manager"
}
// Result: Status changes to pending_hr
// HR Manager Approval
POST /leaves/123/approve
{
"comments": "Leave balance verified, approved",
"approverType": "hr_manager"
}
// Result: Status changes to approved
2. Leave Balance Response
GET /employees/me/leave-balance
{
"casualLeave": { "total": 12, "used": 5, "remaining": 7 }, "sickLeave": { "total":
10, "used": 2, "remaining": 8 }, "vacationLeave": { "total": 18, "used": 10,
"remaining": 8 } }
3. Audit Trail Response
GET /leaves/123/approval-history
{
"leaveRequest": { /* leave details */ },
"approvals": [
{
"approver": "Priya Sharma (Reporting Manager)",
"action": "approved",
"comments": "Approved for family function",
"timestamp": "2024-12-01T10:30:00Z"
},
{
"approver": "Amit Gupta (HR Manager)",
"action": "approved",
"comments": "Leave balance sufficient",
"timestamp": "2024-12-01T14:15:00Z"
}
]
}
Environment Setup
Quick Start
# Create project
npm i -g @nestjs/cli
nest new leave-management-system
# Install dependencies
npm install @nestjs/typeorm typeorm mysql2 @nestjs/jwt bcrypt class-validator
class-transformer
# Development
npm run start:dev
Environment Configuration
DB_HOST=localhost
DB_PORT=3306
DB_USERNAME=root
DB_PASSWORD=password
DB_DATABASE=leave_management
JWT_SECRET=your-jwt-secret-key
Evaluation Criteria
• Architecture & Code Quality (40%): Clean NestJS patterns, TypeScript usage, error
handling • Business Logic Implementation (30%): Approval workflow, validations,
leave balance calculations • Testing Coverage (20%): Unittests, integration tests,
edge case handling • API Design (10%): RESTful conventions,response formats,
documentation
Bonus Features (If Time Permits)
• Email notifications for approval actions
• Department-wise leave analytics
• Advanced leave balance reporting
• Holiday calendar integration
Submission Requirements
1. Complete source code with clear commit history
2. Database migrations and seed data scripts
3. Test suite with good coverage of business logic
4. [Link] with setup and API documentation
5. Postman collection or API documentation
Focus: Clean code, complete workflow, good testing
Goal: Demonstrate backend development skills through a familiar, practical system