diff --git a/sql/structure.sql b/sql/structure.sql index 2e5a65276105bd5ffe9018df265bd831294608e9..2ad4af0a1861cb87507661d6a587a9cb454a1fef 100755 --- a/sql/structure.sql +++ b/sql/structure.sql @@ -323,8 +323,10 @@ CREATE TABLE notifications_schedule days_of_week jsonb, start_time time, end_time time, - frequency int, + frequency INTEGER, frequency_mode character varying(16), + status character varying(20) NOT NULL DEFAULT 'READY', + last_execution timestamp without time zone, CONSTRAINT notifications_schedule_pkey PRIMARY KEY (id) ) WITH (OIDS=FALSE); diff --git a/src/app/notifications/controllers/NotificationsScheduleController.php b/src/app/notifications/controllers/NotificationsScheduleController.php index 8b1465d15457854e2330c9ada7ca3ac08843cad5..054593c3a3d437166a63c6bf9d0261f76bc9ecd9 100644 --- a/src/app/notifications/controllers/NotificationsScheduleController.php +++ b/src/app/notifications/controllers/NotificationsScheduleController.php @@ -33,7 +33,7 @@ class NotificationsScheduleController } $body = $request->getParsedBody(); - // label, type, months, daysOfMonth, daysOfWeek, startTime, endTime, frequency, frequencyMode + // label, type, months, daysOfMonth, daysOfWeek, startTime, (endTime, frequency, frequencyMode)? $err = NotificationsScheduleController::validateBody($body); if (!empty($err)) { @@ -81,16 +81,18 @@ class NotificationsScheduleController $notificationsSchedule = []; foreach ($rawNotificationsSchedule as $key => $value) { $notificationsSchedule[] = [ - 'id' => $value['id'], - 'label' => $value['label'], - 'type' => $value['type'], - 'months' => json_decode($value['months']), - 'daysOfMonth' => json_decode($value['days_of_month']), - 'daysOfWeek' => json_decode($value['days_of_week']), - 'startTime' => $value['start_time'], - 'endTime' => $value['end_time'], - 'frequency' => $value['frequency'], + 'id' => $value['id'], + 'label' => $value['label'], + 'type' => $value['type'], + 'months' => json_decode($value['months']), + 'daysOfMonth' => json_decode($value['days_of_month']), + 'daysOfWeek' => json_decode($value['days_of_week']), + 'startTime' => $value['start_time'], + 'endTime' => $value['end_time'], + 'frequency' => $value['frequency'], 'frequencyMode' => $value['frequency_mode'], + 'status' => $value['status'], + 'lastExecution' => $value['last_execution'], ]; } @@ -113,16 +115,18 @@ class NotificationsScheduleController } $notificationsScheduleItem = [ - 'id' => $rawNotificationsScheduleItem['id'], - 'label' => $rawNotificationsScheduleItem['label'], - 'type' => $rawNotificationsScheduleItem['type'], - 'months' => json_decode($rawNotificationsScheduleItem['months']), - 'daysOfMonth' => json_decode($rawNotificationsScheduleItem['days_of_month']), - 'daysOfWeek' => json_decode($rawNotificationsScheduleItem['days_of_week']), - 'startTime' => $rawNotificationsScheduleItem['start_time'], - 'endTime' => $rawNotificationsScheduleItem['end_time'], - 'frequency' => $rawNotificationsScheduleItem['frequency'], + 'id' => $rawNotificationsScheduleItem['id'], + 'label' => $rawNotificationsScheduleItem['label'], + 'type' => $rawNotificationsScheduleItem['type'], + 'months' => json_decode($rawNotificationsScheduleItem['months']), + 'daysOfMonth' => json_decode($rawNotificationsScheduleItem['days_of_month']), + 'daysOfWeek' => json_decode($rawNotificationsScheduleItem['days_of_week']), + 'startTime' => $rawNotificationsScheduleItem['start_time'], + 'endTime' => $rawNotificationsScheduleItem['end_time'], + 'frequency' => $rawNotificationsScheduleItem['frequency'], 'frequencyMode' => $rawNotificationsScheduleItem['frequency_mode'], + 'status' => $rawNotificationsScheduleItem['status'], + 'lastExecution' => $rawNotificationsScheduleItem['last_execution'], ]; return $response->withJson(['notificationsScheduleItem' => $notificationsScheduleItem]); @@ -159,15 +163,17 @@ class NotificationsScheduleController NotificationsScheduleModel::update([ 'set' => [ - 'label' => $body['label'], - 'type' => $body['type'], - 'months' => empty($body['months']) ? '[]' : json_encode($body['months']), - 'days_of_month' => empty($body['daysOfMonth']) ? '[]' : json_encode($body['daysOfMonth']), - 'days_of_week' => empty($body['daysOfWeek']) ? '[]' : json_encode($body['daysOfWeek']), - 'start_time' => $body['startTime'], - 'end_time' => $body['endTime'], - 'frequency' => $body['frequency'], + 'label' => $body['label'], + 'type' => $body['type'], + 'months' => empty($body['months']) ? '[]' : json_encode($body['months']), + 'days_of_month' => empty($body['daysOfMonth']) ? '[]' : json_encode($body['daysOfMonth']), + 'days_of_week' => empty($body['daysOfWeek']) ? '[]' : json_encode($body['daysOfWeek']), + 'start_time' => $body['startTime'], + 'end_time' => $body['endTime'], + 'frequency' => $body['frequency'], 'frequency_mode' => $body['frequencyMode'], + 'status' => $body['status'], + 'last_execution' => $body['lastExecution'], ], 'where' => ['id = ?'], 'data' => [$args['id']] @@ -228,12 +234,12 @@ class NotificationsScheduleController return "Body daysOfWeek must contain numbers from 1-7 or only '*'"; } elseif (!(Validator::equals(['*'])->validate($body['months']) xor Validator::equals(['*'])->validate($body['daysOfWeek']))) { return "One and only one of body months and daysOfWeek must be ['*']"; - } elseif (!Validator::stringType()->time('H:i')->validate($body['startTime'])) { - return 'Body startTime is not a valid time'; + } elseif (!Validator::stringType()->time('H:i:s')->validate($body['startTime'])) { + return 'Body startTime is not a valid time, expecting hh:mm:ss'; } if (!empty($body['frequency'])) { - if (!Validator::stringType()->time('H:i')->greaterThan($body['startTime'])->validate($body['endTime'])) { - return 'Body endTime is not a valid time or is before startTime'; + if (!Validator::stringType()->time('H:i:s')->greaterThan($body['startTime'])->validate($body['endTime'])) { + return 'Body endTime is not a valid time or is before startTime, expecting hh:mm:ss'; } elseif (!Validator::intType()->positive()->validate($body['frequency'])) { return 'Body frequency is not a number or is less than 0'; } elseif (!Validator::stringType()->in(NotificationsScheduleController::FREQUENCY_MODES)->validate($body['frequencyMode'])) { diff --git a/src/app/notifications/models/NotificationsScheduleModel.php b/src/app/notifications/models/NotificationsScheduleModel.php index 359d514105385b0ef833d2f0997ea3292d780435..303717d941297e57a18dd0c69ab3239c7e90606e 100644 --- a/src/app/notifications/models/NotificationsScheduleModel.php +++ b/src/app/notifications/models/NotificationsScheduleModel.php @@ -75,7 +75,7 @@ class NotificationsScheduleModel 'end_time' => $args['end_time'], 'frequency' => $args['frequency'], 'frequency_mode' => $args['frequency_mode'], - ] + ], ]); return $nextSequenceId;