Files
api/services/nginx/app/routes/departmentNotificationSmsRoute.php
T
Jepp9350 7b82be6c57 Implement vehicle subscription handling and department SMS feature
Added functionality to handle vehicle subscriptions in invoices, including validation and item visibility. Introduced department notification SMS capability with endpoints for creating, retrieving, and deleting SMS records. Enhanced invoice drafting logic to exclude items not flagged for inclusion in invoices.
2025-04-14 16:03:29 +02:00

131 lines
6.4 KiB
PHP

<?php
namespace routes;
use classes\authentication;
use classes\response;
use classes\router;
use objects\department_notification_sms_o;
use objects\logs_o;
use traits\route_t;
class departmentNotificationSmsRoute
{
use route_t;
public function run(): void
{
global /** @var response $response */
/** @var router $router */
$router, $response;
/** Department Notification SMS -> Get */
$this->get('/department/notification/sms', function () {
global $response;
self::requirePermission('department_notification_sms_get');
$user = (new authentication())->get_user();
if ($user) {
$department_notification_sms = new department_notification_sms_o();
$result = $department_notification_sms->listObjectsWithPaginationIfSet(
function ($tmp_object_array) {
return [
'department' => (int)$tmp_object_array['department'],
'label' => (string)$tmp_object_array['label'],
'phone_country_code' => (int)$tmp_object_array['phone_country_code'],
'phone_number' => (int)$tmp_object_array['phone_number'],
'created_at' => (string)$tmp_object_array['created_at'],
];
},
$department_notification_sms->forceRestrictFilters(
[
// This makes sure that the user can only see orders from the departments they explicitly have access to
'department' => $user->getGroup()->getDepartments(),
]
)
);
(new logs_o())->add('department_notification_sms', 'global', 0, $user->id, 'DEPARTMENT_NOTIFICATION_SMS_GET', 'Get department notification SMS');
$response->success($result);
} else {
(new logs_o())->add('department_notification_sms', 'global', 0, 0, 'DEPARTMENT_NOTIFICATION_SMS_GET', 'Get department notification SMS failed');
$response->error('Invalid session', 400);
}
},
[
'department_notification_sms_get' => 'List department notification SMS, in the departments the user has access to',
]
);
/** Department Notification SMS -> Add */
$this->post('/department/notification/sms', function () {
global $response;
self::requirePermission('department_notification_sms_add');
$user = (new authentication())->get_user();
if ($user) {
self::requireParameters([
'department',
'label',
'phone_country_code',
'phone_number',
]);
self::requireType(self::getParameter('department'), self::type_int());
self::requireMinValue((int)self::getParameter('department'), 1);
self::requireType(self::getParameter('label'), self::type_string());
self::requireType(self::getParameter('phone_country_code'), self::type_int());
self::requireMinValue((int)self::getParameter('phone_country_code'), 1);
self::requireType(self::getParameter('phone_number'), self::type_int());
self::requireMinValue((int)self::getParameter('phone_number'), 1);
self::requirePermission('department_notification_sms_add');
self::requireDepartmentAccess((int)self::getParameter('department'));
$department_notification_sms = new department_notification_sms_o();
$department_notification_sms->add(
(int)self::getParameter('department'),
[
'label' => (string)self::getParameter('label'),
'phone_country_code' => (int)self::getParameter('phone_country_code'),
'phone_number' => (int)self::getParameter('phone_number'),
]
);
(new logs_o())->add('department_notification_sms', 'global', 0, $user->id, 'DEPARTMENT_NOTIFICATION_SMS_ADD', 'Add department notification SMS');
$response->success('Department notification SMS added');
} else {
(new logs_o())->add('department_notification_sms', 'global', 0, 0, 'DEPARTMENT_NOTIFICATION_SMS_ADD', 'Add department notification SMS failed');
$response->error('Invalid session', 400);
}
},
[
'department_notification_sms_add' => 'Add a department notification SMS, in the departments the user has access to',
]
);
/** Department Notification SMS -> Delete */
$this->delete('/department/notification/sms', function () {
global $response;
self::requirePermission('department_notification_sms_delete');
$user = (new authentication())->get_user();
if ($user) {
self::requireParameters([
'id',
]);
self::requireType(self::getParameter('id'), self::type_int());
self::requireMinValue((int)self::getParameter('id'), 1);
self::requirePermission('department_notification_sms_delete');
$department_notification_sms = new department_notification_sms_o();
$department_notification_sms->select((int)self::getParameter('id'));
self::requireDepartmentAccess($department_notification_sms->department);
$department_notification_sms->delete();
(new logs_o())->add('department_notification_sms', 'global', 0, $user->id, 'DEPARTMENT_NOTIFICATION_SMS_DELETE', 'Delete department notification SMS');
$response->success('Department notification SMS deleted');
} else {
(new logs_o())->add('department_notification_sms', 'global', 0, 0, 'DEPARTMENT_NOTIFICATION_SMS_DELETE', 'Delete department notification SMS failed');
$response->error('Invalid session', 400);
}
},
[
'department_notification_sms_delete' => 'Delete a department notification SMS, in the departments the user has access to',
]
);
}
}