-
Notifications
You must be signed in to change notification settings - Fork 579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OHRM5X-1959: Develop ClaimRequest getAll API #1656
Changes from all commits
00ce9da
224ddc6
12b8b5f
2b0f524
8300436
23c0f29
2835cf8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -23,10 +23,14 @@ | |||||
use Exception; | ||||||
use OpenApi\Annotations as OA; | ||||||
use OrangeHRM\Claim\Api\Model\ClaimRequestModel; | ||||||
use OrangeHRM\Claim\Api\Model\EmployeeClaimRequestModel; | ||||||
use OrangeHRM\Claim\Dto\ClaimRequestSearchFilterParams; | ||||||
use OrangeHRM\Claim\Dto\EmployeeClaimRequestSearchFilterParams; | ||||||
use OrangeHRM\Claim\Traits\Service\ClaimServiceTrait; | ||||||
use OrangeHRM\Core\Api\CommonParams; | ||||||
use OrangeHRM\Core\Api\V2\CrudEndpoint; | ||||||
use OrangeHRM\Core\Api\V2\Endpoint; | ||||||
use OrangeHRM\Core\Api\V2\EndpointCollectionResult; | ||||||
use OrangeHRM\Core\Api\V2\EndpointResourceResult; | ||||||
use OrangeHRM\Core\Api\V2\EndpointResult; | ||||||
use OrangeHRM\Core\Api\V2\Exception\BadRequestException; | ||||||
|
@@ -47,6 +51,7 @@ | |||||
use OrangeHRM\Entity\Employee; | ||||||
use OrangeHRM\Entity\WorkflowStateMachine; | ||||||
use OrangeHRM\ORM\Exception\TransactionException; | ||||||
use OrangeHRM\Pim\Traits\Service\EmployeeServiceTrait; | ||||||
|
||||||
class EmployeeClaimRequestAPI extends Endpoint implements CrudEndpoint | ||||||
{ | ||||||
|
@@ -56,13 +61,19 @@ class EmployeeClaimRequestAPI extends Endpoint implements CrudEndpoint | |||||
use AuthUserTrait; | ||||||
use NormalizerServiceTrait; | ||||||
use UserRoleManagerTrait; | ||||||
use EmployeeServiceTrait; | ||||||
|
||||||
public const PARAMETER_CLAIM_EVENT_ID = 'claimEventId'; | ||||||
public const PARAMETER_CURRENCY_ID = 'currencyId'; | ||||||
public const PARAMETER_REMARKS = 'remarks'; | ||||||
public const REMARKS_MAX_LENGTH = 1000; | ||||||
public const PARAMETER_ALLOWED_ACTIONS = 'allowedActions'; | ||||||
public const PARAMETER_EMPLOYEE_NUMBER = 'empNumber'; | ||||||
public const PARAMETER_REFERENCE_ID = 'referenceId'; | ||||||
public const PARAMETER_EVENT_ID = 'eventId'; | ||||||
public const PARAMETER_STATUS = 'status'; | ||||||
public const PARAMETER_FROM_DATE = 'fromDate'; | ||||||
public const PARAMETER_TO_DATE = 'toDate'; | ||||||
public const ACTIONABLE_STATES_MAP = [ | ||||||
WorkflowStateMachine::CLAIM_ACTION_SUBMIT => 'SUBMIT', | ||||||
WorkflowStateMachine::CLAIM_ACTION_APPROVE => 'APPROVE', | ||||||
Comment on lines
66
to
79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. public const PARAMETER_CLAIM_EVENT_ID = 'claimEventId';
public const PARAMETER_CURRENCY_ID = 'currencyId';
public const PARAMETER_REMARKS = 'remarks';
public const PARAMETER_ALLOWED_ACTIONS = 'allowedActions';
public const PARAMETER_EMPLOYEE_NUMBER = 'empNumber';
public const PARAMETER_REFERENCE_ID = 'referenceId';
public const PARAMETER_EVENT_ID = 'eventId';
public const PARAMETER_STATUS = 'status';
public const PARAMETER_FROM_DATE = 'fromDate';
public const PARAMETER_TO_DATE = 'toDate';
public const REMARKS_MAX_LENGTH = 1000;
public const ACTIONABLE_STATES_MAP = [
WorkflowStateMachine::CLAIM_ACTION_SUBMIT => 'SUBMIT',
WorkflowStateMachine::CLAIM_ACTION_APPROVE => 'APPROVE',
WorkflowStateMachine::CLAIM_ACTION_PAY => 'PAY',
WorkflowStateMachine::CLAIM_ACTION_CANCEL => 'CANCEL',
WorkflowStateMachine::CLAIM_ACTION_REJECT => 'REJECT'
]; prefer if you can organize |
||||||
|
@@ -220,19 +231,237 @@ protected function setClaimRequest(ClaimRequest $claimRequest, int $empNumber): | |||||
} | ||||||
|
||||||
/** | ||||||
* @OA\Get( | ||||||
* path="/api/v2/claim/employees/requests", | ||||||
* tags={"Claim/Requests"}, | ||||||
* @OA\Parameter( | ||||||
* name="sortField", | ||||||
* in="query", | ||||||
* required=false, | ||||||
* @OA\Schema(type="string", enum=EmployeeClaimRequestSearchFilterParams::ALLOWED_SORT_FIELDS) | ||||||
DulsaraNethmin marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
* ), | ||||||
* @OA\Parameter( | ||||||
* name="referenceId", | ||||||
* in="query", | ||||||
* required=false, | ||||||
* @OA\Schema(type="string") | ||||||
* ), | ||||||
* @OA\Parameter( | ||||||
* name="status", | ||||||
* in="query", | ||||||
* required=false, | ||||||
* @OA\Schema(type="string", enum={"INITIATED", "SUBMITTED", "APPROVED", "REJECTED", "CANCELLED", "PAID"}) | ||||||
* ), | ||||||
* @OA\Parameter( | ||||||
* name="eventId", | ||||||
* in="query", | ||||||
* required=false, | ||||||
* @OA\Schema(type="integer") | ||||||
* ), | ||||||
* @OA\Parameter( | ||||||
* name="empNumber", | ||||||
* in="query", | ||||||
* required=false, | ||||||
* @OA\Schema(type="integer") | ||||||
* ), | ||||||
* @OA\Parameter( | ||||||
* name="fromDate", | ||||||
* in="query", | ||||||
* required=false, | ||||||
* @OA\Schema(type="DateTime") | ||||||
* ), | ||||||
* @OA\Parameter( | ||||||
* name="toDate", | ||||||
* in="query", | ||||||
* required=false, | ||||||
* @OA\Schema(type="DateTime") | ||||||
* ), | ||||||
* @OA\Parameter(ref="#/components/parameters/sortOrder"), | ||||||
* @OA\Parameter(ref="#/components/parameters/limit"), | ||||||
* @OA\Parameter(ref="#/components/parameters/offset"), | ||||||
* @OA\Response( | ||||||
* response="200", | ||||||
* description="Success", | ||||||
* @OA\JsonContent( | ||||||
* @OA\Property( | ||||||
* property="data", | ||||||
* type="array", | ||||||
* @OA\Items(ref="#/components/schemas/Claim-EmployeeClaimRequestModel") | ||||||
* ), | ||||||
* @OA\Property( | ||||||
* property="meta", | ||||||
* type="object", | ||||||
* @OA\Property(property="total", type="integer") | ||||||
* ) | ||||||
* ) | ||||||
* ) | ||||||
* ) | ||||||
* @inheritDoc | ||||||
*/ | ||||||
public function getAll(): EndpointResult | ||||||
{ | ||||||
throw $this->getNotImplementedException(); | ||||||
$employeeClaimRequestSearchFilterParams = $this->getClaimRequestSearchFilterParams(); | ||||||
|
||||||
$this->setSortingAndPaginationParams($employeeClaimRequestSearchFilterParams); | ||||||
$this->getCommonFilterParams($employeeClaimRequestSearchFilterParams); | ||||||
$this->setEmpNumbers($employeeClaimRequestSearchFilterParams); | ||||||
|
||||||
$claimRequests = $this->getClaimService()->getClaimDao() | ||||||
->getClaimRequestList($employeeClaimRequestSearchFilterParams); | ||||||
|
||||||
$count = $this->getClaimService()->getClaimDao() | ||||||
->getClaimRequestCount($employeeClaimRequestSearchFilterParams); | ||||||
|
||||||
return $this->getEndPointCollectionResult($claimRequests, $count); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @return ClaimRequestSearchFilterParams | ||||||
*/ | ||||||
protected function getClaimRequestSearchFilterParams(): ClaimRequestSearchFilterParams | ||||||
{ | ||||||
return new EmployeeClaimRequestSearchFilterParams(); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @param array $claimRequests | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
🤔 |
||||||
* @param int $count | ||||||
* @return EndpointCollectionResult | ||||||
*/ | ||||||
protected function getEndPointCollectionResult(array $claimRequests, int $count): EndpointCollectionResult | ||||||
{ | ||||||
return new EndpointCollectionResult( | ||||||
EmployeeClaimRequestModel::class, | ||||||
$claimRequests, | ||||||
new ParameterBag([CommonParams::PARAMETER_TOTAL => $count]) | ||||||
); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @param ClaimRequestSearchFilterParams $claimRequestSearchFilterParams | ||||||
*/ | ||||||
protected function setEmpNumbers(ClaimRequestSearchFilterParams $claimRequestSearchFilterParams): void | ||||||
{ | ||||||
$empNumber = $this->getRequestParams()->getIntOrNull( | ||||||
RequestParams::PARAM_TYPE_QUERY, | ||||||
self::PARAMETER_EMPLOYEE_NUMBER | ||||||
); | ||||||
|
||||||
if (!is_null($empNumber)) { | ||||||
DulsaraNethmin marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
if (!$this->getEmployeeService()->getEmployeeDao()->getEmployeeByEmpNumber($empNumber) instanceof Employee) { | ||||||
throw $this->getRecordNotFoundException(); | ||||||
} | ||||||
if (!$this->isSelfByEmpNumber($empNumber)) { | ||||||
throw $this->getForbiddenException(); | ||||||
} | ||||||
Comment on lines
+354
to
+356
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bit confusing |
||||||
if (!$this->getUserRoleManagerHelper()->isEmployeeAccessible($empNumber)) { | ||||||
throw $this->getForbiddenException(); | ||||||
} | ||||||
$claimRequestSearchFilterParams->setEmpNumbers([$empNumber]); | ||||||
} else { | ||||||
$empNumbers = $this->getUserRoleManager()->getAccessibleEntityIds(Employee::class); | ||||||
$claimRequestSearchFilterParams->setEmpNumbers($empNumbers); | ||||||
} | ||||||
} | ||||||
|
||||||
/** | ||||||
* @param ClaimRequestSearchFilterParams $claimRequestSearchFilterParams | ||||||
*/ | ||||||
private function getCommonFilterParams(ClaimRequestSearchFilterParams $claimRequestSearchFilterParams): void | ||||||
{ | ||||||
$claimRequestSearchFilterParams->setReferenceId( | ||||||
$this->getRequestParams()->getStringOrNull( | ||||||
RequestParams::PARAM_TYPE_QUERY, | ||||||
self::PARAMETER_REFERENCE_ID | ||||||
) | ||||||
); | ||||||
$claimRequestSearchFilterParams->setEventId( | ||||||
$this->getRequestParams()->getIntOrNull( | ||||||
RequestParams::PARAM_TYPE_QUERY, | ||||||
self::PARAMETER_EVENT_ID | ||||||
) | ||||||
); | ||||||
$claimRequestSearchFilterParams->setStatus( | ||||||
$this->getRequestParams()->getStringOrNull( | ||||||
RequestParams::PARAM_TYPE_QUERY, | ||||||
self::PARAMETER_STATUS | ||||||
) | ||||||
); | ||||||
$claimRequestSearchFilterParams->setFromDate( | ||||||
$this->getRequestParams()->getDateTimeOrNull( | ||||||
RequestParams::PARAM_TYPE_QUERY, | ||||||
self::PARAMETER_FROM_DATE | ||||||
) | ||||||
); | ||||||
$claimRequestSearchFilterParams->setToDate( | ||||||
$this->getRequestParams()->getDateTimeOrNull( | ||||||
RequestParams::PARAM_TYPE_QUERY, | ||||||
self::PARAMETER_TO_DATE | ||||||
) | ||||||
); | ||||||
Comment on lines
+390
to
+401
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any idea to validate toDate > fromDate |
||||||
} | ||||||
|
||||||
/** | ||||||
* @return ParamRuleCollection | ||||||
*/ | ||||||
protected function getCommonParamRuleCollectionGetAll(): ParamRuleCollection | ||||||
{ | ||||||
return new ParamRuleCollection( | ||||||
$this->getValidationDecorator()->notRequiredParamRule( | ||||||
new ParamRule( | ||||||
self::PARAMETER_REFERENCE_ID, | ||||||
new Rule(Rules::STRING_TYPE) | ||||||
) | ||||||
), | ||||||
$this->getValidationDecorator()->notRequiredParamRule( | ||||||
new ParamRule( | ||||||
self::PARAMETER_EVENT_ID, | ||||||
new Rule(Rules::POSITIVE) | ||||||
) | ||||||
), | ||||||
$this->getValidationDecorator()->notRequiredParamRule( | ||||||
new ParamRule( | ||||||
self::PARAMETER_STATUS, | ||||||
new Rule(Rules::STRING_TYPE) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
) | ||||||
), | ||||||
$this->getValidationDecorator()->notRequiredParamRule( | ||||||
new ParamRule( | ||||||
self::PARAMETER_FROM_DATE, | ||||||
new Rule(Rules::DATE_TIME) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
) | ||||||
), | ||||||
$this->getValidationDecorator()->notRequiredParamRule( | ||||||
new ParamRule( | ||||||
self::PARAMETER_TO_DATE, | ||||||
new Rule(Rules::DATE_TIME) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
) | ||||||
) | ||||||
); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @inheritDoc | ||||||
*/ | ||||||
public function getValidationRuleForGetAll(): ParamRuleCollection | ||||||
{ | ||||||
throw $this->getNotImplementedException(); | ||||||
$paramRuleCollection = $this->getCommonParamRuleCollectionGetAll(); | ||||||
$paramRuleCollection->addParamValidation( | ||||||
$this->getValidationDecorator()->notRequiredParamRule( | ||||||
new ParamRule( | ||||||
self::PARAMETER_EMPLOYEE_NUMBER, | ||||||
new Rule(Rules::POSITIVE) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
🤔 |
||||||
) | ||||||
) | ||||||
); | ||||||
$sortFieldParamRules = $this->getSortingAndPaginationParamsRules( | ||||||
EmployeeClaimRequestSearchFilterParams::ALLOWED_SORT_FIELDS | ||||||
); | ||||||
foreach ($sortFieldParamRules as $sortFieldParamRule) { | ||||||
$paramRuleCollection->addParamValidation($sortFieldParamRule); | ||||||
} | ||||||
|
||||||
return $paramRuleCollection; | ||||||
} | ||||||
|
||||||
/** | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can use from common params