mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +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;
|
$requestor = null;
|
||||||
$exceptions = [];
|
$exceptions = [];
|
||||||
|
|
||||||
foreach ([Person::class, ThirdParty::class] as $class) {
|
try {
|
||||||
try {
|
$contentAsArray = json_decode($request->getContent(), true);
|
||||||
$requestor = $this->getSerializer()
|
$entityType = $contentAsArray['type'];
|
||||||
->deserialize($request->getContent(), $class, $_format, []);
|
if ($entityType === 'person') {
|
||||||
} catch (RuntimeException $e) {
|
$requestor = $this->getSerializer()->deserialize($request->getContent(), Person::class, $_format, []);
|
||||||
$exceptions[] = $e;
|
} elseif ($entityType === 'thirdparty') {
|
||||||
|
$requestor = $this->getSerializer()->deserialize($request->getContent(), ThirdParty::class, $_format, []);
|
||||||
}
|
}
|
||||||
|
} catch (RuntimeException $e) {
|
||||||
|
$exceptions[] = $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $requestor) {
|
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);
|
$accompanyingPeriod->setRequestor($requestor);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user