From 8718004f06324dad6859f664cf28deb6db4ac744 Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Fri, 26 Jun 2026 08:29:38 +0530 Subject: [PATCH] FEAT_E_CARD_MAIL_SEND_OPTION_FOR_HR --- app/Config/Routes.php | 1 + app/Controllers/EmployeeRestController.php | 26 +++ send-mail-individual-employee-ecard-api.md | 180 +++++++++++++++++++++ 3 files changed, 207 insertions(+) create mode 100644 send-mail-individual-employee-ecard-api.md diff --git a/app/Config/Routes.php b/app/Config/Routes.php index e9d2aea9..c16dd299 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -737,6 +737,7 @@ $routes->group("employeeRest", ["filter" => ['GlobalPostFileUploadGuard', 'ratel $routes->get("getFEContent", "EmployeeRestController::getFEContent"); $routes->get("getAdvertisementImage", "EmployeeRestController::getAdvertisementImage"); $routes->get("getEcardURL", "EmployeeRestController::getEcardURL"); + $routes->post("sendMailForIndividualEmployeeEcard", "EmployeeRestController::sendMailForIndividualEmployeeEcard"); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index b88825dd..bb1677bb 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -5904,4 +5904,30 @@ class EmployeeRestController extends AdminController ], 200); } + public function sendMailForIndividualEmployeeEcard() + { + $received_data = $this->request->getJSON(true) ?? []; + + $id = $received_data['emp_policy_id'] ?? null; + $client_policy_id = $received_data['client_policy_id'] ?? null; + + if (empty($id)) { + return $this->respond(['status' => false, 'code' => 404, 'message' => 'emp_policy_id is required'], 200); + } + + if (empty($client_policy_id)) { + return $this->respond(['status' => false, 'code' => 404, 'message' => 'client_policy_id is required'], 200); + } + + $ids[] = $id; + $empDataServiceController = new EmpDataServiceController(); + $result = $empDataServiceController->sendMailForDownloadingECard(['ids' => $ids, 'client_policy_id' => $client_policy_id], 1); + + if (isset($result['status']) && $result['status'] == true) { + return $this->respond(['status' => true, 'code' => 200, 'message' => 'Mail sent successfully', 'result' => $result], 200); + } + + return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to sent mail.', 'result' => $result], 200); + } + } diff --git a/send-mail-individual-employee-ecard-api.md b/send-mail-individual-employee-ecard-api.md new file mode 100644 index 00000000..1c961abe --- /dev/null +++ b/send-mail-individual-employee-ecard-api.md @@ -0,0 +1,180 @@ +# Send Individual Employee E-Card Mail API + +Sends the E-Card download mail to a single employee (Self relationship only). + +**Controller:** `EmployeeRestController::sendMailForIndividualEmployeeEcard` +**Method:** `POST` + +--- + +## Endpoint + +``` +POST /employeeRest/sendMailForIndividualEmployeeEcard +``` + +--- + +## Authentication + +**JWT token is required.** This endpoint is available only in the authenticated route group. + +| Filter | Description | +|--------|-------------| +| `GlobalPostFileUploadGuard` | POST upload guard | +| `ratelimit` | Rate limiting | +| `appSignature` | App signature validation | +| `authJWT` | JWT token validation | + +### Required Headers + +| Header | Required | Description | +|--------|----------|-------------| +| `Content-Type` | Yes | `application/json` | +| `App-Signature` | Yes | Must match server `APP_SIGNATURE` from `.env` | +| `Authorization` | Yes | JWT token in format `Bearer ` | + +### Example Headers + +``` +Content-Type: application/json +App-Signature: +Authorization: Bearer +``` + +--- + +## Request Body (JSON) + +| Parameter | Type | Required | Description | +|-----------|------|----------|-------------| +| `emp_policy_id` | integer | Yes | Employee policy ID (`employee_polices.id`) | +| `client_policy_id` | integer | Yes | Client policy ID | + +### Example Request + +```json +{ + "emp_policy_id": 12345, + "client_policy_id": 678 +} +``` + +### cURL Example + +```bash +curl -X POST "https:///employeeRest/sendMailForIndividualEmployeeEcard" \ + -H "Content-Type: application/json" \ + -H "App-Signature: " \ + -H "Authorization: Bearer " \ + -d '{ + "emp_policy_id": 12345, + "client_policy_id": 678 + }' +``` + +--- + +## Success Response + +**HTTP Status:** `200` + +```json +{ + "status": true, + "code": 200, + "message": "Mail sent successfully", + "result": {} +} +``` + +--- + +## Error Responses + +### Missing `emp_policy_id` + +**HTTP Status:** `200` + +```json +{ + "status": false, + "code": 404, + "message": "emp_policy_id is required" +} +``` + +### Missing `client_policy_id` + +**HTTP Status:** `200` + +```json +{ + "status": false, + "code": 404, + "message": "client_policy_id is required" +} +``` + +### Mail Send Failed + +**HTTP Status:** `200` + +```json +{ + "status": false, + "code": 404, + "message": "Failed to sent mail.", + "result": {} +} +``` + +### Missing / Invalid Token + +**HTTP Status:** `401` or `403` + +```json +{ + "status": 401, + "message": "Token is Invalid" +} +``` + +### Invalid App Signature + +**HTTP Status:** `403` + +```json +{ + "status": false, + "message": "Forbidden: Invalid App Signature" +} +``` + +--- + +## Notes + +- `emp_policy_id` is the **employee policy record ID**, not the employee master ID. +- Mail is sent only when E-Card notification is enabled for the client. +- Employee must be active with a valid corporate email and TPA ID. +- This API uses the same logic as `EmployeeController::send_mail_for_individual_employee_ecard`. + +--- + +## Route Registration + +Defined in `app/Config/Routes.php`: + +```php +$routes->group("employeeRest", ["filter" => ['GlobalPostFileUploadGuard', 'ratelimit', 'appSignature', 'authJWT']], function ($routes) { + $routes->post("sendMailForIndividualEmployeeEcard", "EmployeeRestController::sendMailForIndividualEmployeeEcard"); +}); +``` + +--- + +## Source + +Implementation: `app/Controllers/EmployeeRestController.php` → `sendMailForIndividualEmployeeEcard()` +Service: `app/Controllers/EmpDataServiceController.php` → `sendMailForDownloadingECard()`