MERGE_TEST_BUG_FIXES
This commit is contained in:
commit
641c62ea6f
@ -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");
|
||||
|
||||
|
||||
|
||||
|
||||
@ -5169,14 +5169,12 @@ class EmployeeRestController extends AdminController
|
||||
|
||||
try {
|
||||
//for inception upload
|
||||
if($type == 'EB'){
|
||||
if ($type == 'EB') {
|
||||
|
||||
$data['actions'] = ['addition' => 'Addition (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$data['actions'] = ['addition' => 'Adding New Assets', 'deletion' => 'Removing Assets', 'correction' => 'Correction of assets details'];
|
||||
}
|
||||
$data['actions'] = ['all' => 'All', 'addition' => 'Addition (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement'];
|
||||
} else {
|
||||
$data['actions'] = ['addition' => 'Adding New Assets', 'deletion' => 'Removing Assets', 'correction' => 'Correction of assets details'];
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => true,
|
||||
@ -5904,4 +5902,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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
namespace App\Filters;
|
||||
|
||||
use App\Helpers\JWTToken;
|
||||
use App\Filters\Cors;
|
||||
use CodeIgniter\Filters\FilterInterface;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
@ -18,6 +19,13 @@ use App\Models\LevelContactModel;
|
||||
|
||||
class AuthJWT implements FilterInterface
|
||||
{
|
||||
protected Cors $corsFilter;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->corsFilter = new Cors();
|
||||
}
|
||||
|
||||
// public function before(RequestInterface $request, $arguments = null)
|
||||
// {
|
||||
// $jwt = $request->getHeader('Authorization');
|
||||
@ -84,20 +92,20 @@ class AuthJWT implements FilterInterface
|
||||
$authHeader = $request->getHeaderLine('Authorization');
|
||||
|
||||
if (!$authHeader) {
|
||||
return $this->reject(403, 'Access Forbidden');
|
||||
return $this->reject($request, 403, 'Access Forbidden');
|
||||
}
|
||||
|
||||
$result = JWTToken::validateJWT($authHeader);
|
||||
|
||||
if ($result['status'] !== true) {
|
||||
return $this->reject(401, $result['message']);
|
||||
return $this->reject($request, 401, $result['message']);
|
||||
}
|
||||
|
||||
$decoded = $result['decoded'];
|
||||
$id = $decoded['id'] ?? null;
|
||||
|
||||
if (!$id) {
|
||||
return $this->reject(401, 'Invalid token payload');
|
||||
return $this->reject($request, 401, 'Invalid token payload');
|
||||
}
|
||||
|
||||
if (isset($decoded['emp_code'])) {
|
||||
@ -111,7 +119,7 @@ class AuthJWT implements FilterInterface
|
||||
|
||||
if (!$user || $user['token_time_out'] <= time()) {
|
||||
$model->update($id, ['token_time_out' => null]);
|
||||
return $this->reject(401, 'Token expired');
|
||||
return $this->reject($request, 401, 'Token expired');
|
||||
}
|
||||
|
||||
// Refresh sliding expiration
|
||||
@ -132,12 +140,20 @@ class AuthJWT implements FilterInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
private function reject(int $code, string $message)
|
||||
private function reject(RequestInterface $request, int $code, string $message): ResponseInterface
|
||||
{
|
||||
return service('response')
|
||||
->setStatusCode($code)
|
||||
->setJSON(['status' => $code, 'message' => $message])
|
||||
->send();
|
||||
$response = service('response');
|
||||
$response->setStatusCode($code);
|
||||
$response->setContentType('application/json');
|
||||
$response->setBody(json_encode([
|
||||
'status' => $code,
|
||||
'message' => $message,
|
||||
]));
|
||||
|
||||
// Early before-filter returns skip global Cors after(), so attach CORS here.
|
||||
$this->corsFilter->after($request, $response);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
180
send-mail-individual-employee-ecard-api.md
Normal file
180
send-mail-individual-employee-ecard-api.md
Normal file
@ -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 <token>` |
|
||||
|
||||
### Example Headers
|
||||
|
||||
```
|
||||
Content-Type: application/json
|
||||
App-Signature: <your_app_signature>
|
||||
Authorization: Bearer <jwt_token>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 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://<base_url>/employeeRest/sendMailForIndividualEmployeeEcard" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "App-Signature: <your_app_signature>" \
|
||||
-H "Authorization: Bearer <jwt_token>" \
|
||||
-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()`
|
||||
Loading…
Reference in New Issue
Block a user