class AssignmentService {

	public void update(Employee employee) {
		List<Assignment> assignments = assignmentRepository.findByEmployeeId(employee.getId(), employee.getTenantId());
		employee.getAssignments().forEach((assignment) -> {
			if (needsInsert(assignment, assignments)) {
				assignmentRepository.insert(assignment, employee.getId());
				if (assignment.getHod() != null) {
					hodDepartmentRepository.save(assignment, employee.getTenantId());
				}
			} else if (needsUpdate(assignment, assignments)) {
				assignment.setTenantId(employee.getTenantId());
				assignmentRepository.update(assignment);
				if (!isEmpty(assignment.getHod())) {
					updateHod(assignment, employee.getTenantId());
				}
			}
		});
		deleteAssignmentsInDBThatAreNotInInput(employee.getAssignments(), assignments, employee.getId(),
				employee.getTenantId());
	}

}