Fixed validation on member affiliation endpoints

Fixed end_date validation condition for current one

Change-Id: I39adda4b6c9ddef754e0297ccae7bc02378cbd7e
This commit is contained in:
Sebastian Marcet 2018-09-18 11:03:31 -03:00
parent 20d96d7182
commit 8860cee7d8
3 changed files with 6 additions and 3 deletions

View File

@ -239,7 +239,7 @@ final class OAuth2MembersApiController extends OAuth2ProtectedController
$rules = [
'is_current' => 'required|boolean',
'start_date' => 'required|date_format:U|valid_epoch',
'end_date' => 'sometimes|date_format:U|after_or_null_epoch:start_date',
'end_date' => 'sometimes|after_or_null_epoch:start_date',
'organization_id' => 'required|integer',
'job_title' => 'sometimes|string|max:255'
];
@ -294,7 +294,7 @@ final class OAuth2MembersApiController extends OAuth2ProtectedController
$rules = [
'is_current' => 'sometimes|boolean',
'start_date' => 'sometimes|date_format:U|valid_epoch',
'end_date' => 'sometimes|date_format:U|after_or_null_epoch:start_date',
'end_date' => 'sometimes|after_or_null_epoch:start_date',
'organization_id' => 'sometimes|integer',
'job_title' => 'sometimes|string|max:255'
];

View File

@ -251,7 +251,9 @@ class AppServiceProvider extends ServiceProvider
if(is_null($value) || intval($value) == 0 ) return true;
if(isset($data[$parameters[0]])){
$compare_to = $data[$parameters[0]];
return intval($compare_to) < intval($value);
$parsed = date_parse_from_format('U', $value);
$valid = $parsed['error_count'] === 0 && $parsed['warning_count'] === 0;
return $valid && intval($compare_to) < intval($value);
}
return true;
});

View File

@ -173,6 +173,7 @@ final class OAuth2MembersApiTest extends ProtectedApiTest
'is_current' => true,
'start_date' => $start_datetime_unix,
'job_title' => 'test affiliation',
'end_date' => null,
'organization_id' => 1
];