Skip to content
Snippets Groups Projects
Verified Commit 027c9b40 authored by Damien's avatar Damien
Browse files

FEAT #119 Reset default priority

parent 37d410b4
No related branches found
No related tags found
No related merge requests found
...@@ -38,10 +38,14 @@ class PriorityController ...@@ -38,10 +38,14 @@ class PriorityController
$check = $check && Validator::stringType()->notEmpty()->validate($data['color']); $check = $check && Validator::stringType()->notEmpty()->validate($data['color']);
$check = $check && (Validator::intVal()->notEmpty()->validate($data['delays']) || $data['delays'] == null); $check = $check && (Validator::intVal()->notEmpty()->validate($data['delays']) || $data['delays'] == null);
$check = $check && Validator::boolType()->validate($data['working_days']); $check = $check && Validator::boolType()->validate($data['working_days']);
$check = $check && Validator::boolType()->validate($data['default_priority']);
if (!$check) { if (!$check) {
return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); return $response->withStatus(400)->withJson(['errors' => 'Bad Request']);
} }
if ($data['default_priority']) {
PriorityModel::resetDefaultPriority();
}
$data['working_days'] = $data['working_days'] ? 'true' : 'false'; $data['working_days'] = $data['working_days'] ? 'true' : 'false';
$data['default_priority'] = $data['default_priority'] ? 'true' : 'false'; $data['default_priority'] = $data['default_priority'] ? 'true' : 'false';
...@@ -74,6 +78,9 @@ class PriorityController ...@@ -74,6 +78,9 @@ class PriorityController
return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); return $response->withStatus(400)->withJson(['errors' => 'Bad Request']);
} }
if ($data['default_priority']) {
PriorityModel::resetDefaultPriority();
}
$data['id'] = $aArgs['id']; $data['id'] = $aArgs['id'];
$data['working_days'] = empty($data['working_days']) ? 'false' : 'true'; $data['working_days'] = empty($data['working_days']) ? 'false' : 'true';
$data['default_priority'] = empty($data['default_priority']) ? 'false' : 'true'; $data['default_priority'] = empty($data['default_priority']) ? 'false' : 'true';
......
...@@ -96,6 +96,20 @@ abstract class PriorityModelAbstract ...@@ -96,6 +96,20 @@ abstract class PriorityModelAbstract
return true; return true;
} }
public static function resetDefaultPriority()
{
DatabaseModel::update([
'table' => 'priorities',
'set' => [
'default_priority' => 'false'
],
'where' => ['default_priority = ?'],
'data' => ['true']
]);
return true;
}
public static function delete(array $aArgs) public static function delete(array $aArgs)
{ {
ValidatorModel::notEmpty($aArgs, ['id']); ValidatorModel::notEmpty($aArgs, ['id']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment