mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
accompanying course: normalize the requestor entity
This commit is contained in:
parent
2343a4a334
commit
91ba08dfa1
@ -234,17 +234,20 @@ final class AccompanyingCourseApiController extends ApiController
|
||||
$requestor = null;
|
||||
$exceptions = [];
|
||||
|
||||
foreach ([Person::class, ThirdParty::class] as $class) {
|
||||
try {
|
||||
$requestor = $this->getSerializer()
|
||||
->deserialize($request->getContent(), $class, $_format, []);
|
||||
} catch (RuntimeException $e) {
|
||||
$exceptions[] = $e;
|
||||
try {
|
||||
$contentAsArray = json_decode($request->getContent(), true);
|
||||
$entityType = $contentAsArray['type'];
|
||||
if ($entityType === 'person') {
|
||||
$requestor = $this->getSerializer()->deserialize($request->getContent(), Person::class, $_format, []);
|
||||
} elseif ($entityType === 'thirdparty') {
|
||||
$requestor = $this->getSerializer()->deserialize($request->getContent(), ThirdParty::class, $_format, []);
|
||||
}
|
||||
} catch (RuntimeException $e) {
|
||||
$exceptions[] = $e;
|
||||
}
|
||||
|
||||
if (null === $requestor) {
|
||||
throw new BadRequestException('Could not find any person or requestor', 0, $exceptions[0]);
|
||||
throw new BadRequestException('Could not find any person or thirdparty', 0, null);
|
||||
}
|
||||
|
||||
$accompanyingPeriod->setRequestor($requestor);
|
||||
|
Loading…
x
Reference in New Issue
Block a user