Fix market card save validation
This commit is contained in:
1 parent
6a12a43114
commit
28784ed6ac
1 file changed
+22
-12
@@ -33,12 +33,13 @@ if ($requestMethod === 'POST') {
|
||||
echo json_encode(['ok' => false, 'error' => 'Ungültige Anfrage']);
|
||||
exit;
|
||||
}
|
||||
$scope = (string) ($payload['scope'] ?? '');
|
||||
$id = market_management_require_positive_id($payload['id'] ?? null, 'id');
|
||||
$fields = is_array($payload['fields'] ?? null) ? $payload['fields'] : [];
|
||||
if ($scope === 'day') {
|
||||
market_management_update_day($pdo, $id, $fields);
|
||||
} elseif (in_array($scope, ['occurrence', 'status', 'overview', 'participation', 'infrastructure', 'travel', 'notes'], true)) {
|
||||
try {
|
||||
$scope = (string) ($payload['scope'] ?? '');
|
||||
$id = market_management_require_positive_id($payload['id'] ?? null, 'id');
|
||||
$fields = is_array($payload['fields'] ?? null) ? $payload['fields'] : [];
|
||||
if ($scope === 'day') {
|
||||
market_management_update_day($pdo, $id, $fields);
|
||||
} elseif (in_array($scope, ['occurrence', 'status', 'overview', 'participation', 'infrastructure', 'travel', 'notes'], true)) {
|
||||
$marketFields = [];
|
||||
foreach (['market_name', 'category_id', 'website_url'] as $marketField) {
|
||||
if (array_key_exists($marketField, $fields)) {
|
||||
@@ -61,13 +62,17 @@ if ($requestMethod === 'POST') {
|
||||
market_management_update_market($pdo, (int) ($existingOccurrence['market_definition_id'] ?? 0), $marketFields);
|
||||
}
|
||||
if ($contactFields !== []) {
|
||||
$contactId = (int) ($fields['contact_person_id'] ?? $existingOccurrence['contact_person_id'] ?? 0);
|
||||
$submittedContactId = trim((string) ($fields['contact_person_id'] ?? ''));
|
||||
$contactId = (int) ($submittedContactId !== '' ? $submittedContactId : ($existingOccurrence['contact_person_id'] ?? 0));
|
||||
update_contact_details($pdo, $contactId, $contactFields);
|
||||
}
|
||||
$organizerFields = [];
|
||||
foreach (['organization_contact_id', 'contact_person_id'] as $organizerField) {
|
||||
if (array_key_exists($organizerField, $fields)) {
|
||||
$organizerFields[$organizerField] = $fields[$organizerField];
|
||||
$value = trim((string) $fields[$organizerField]);
|
||||
if ($value !== '') {
|
||||
$organizerFields[$organizerField] = $value;
|
||||
}
|
||||
unset($fields[$organizerField]);
|
||||
}
|
||||
}
|
||||
@@ -82,11 +87,16 @@ if ($requestMethod === 'POST') {
|
||||
if ($fields !== []) {
|
||||
market_management_update_occurrence($pdo, $id, $fields);
|
||||
}
|
||||
} else {
|
||||
throw new InvalidArgumentException('Ungültiger Bearbeitungsbereich.');
|
||||
} else {
|
||||
throw new InvalidArgumentException('Ungültiger Bearbeitungsbereich.');
|
||||
}
|
||||
echo json_encode(['ok' => true]);
|
||||
exit;
|
||||
} catch (Throwable $error) {
|
||||
http_response_code(422);
|
||||
echo json_encode(['ok' => false, 'error' => $error->getMessage()], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
echo json_encode(['ok' => true]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$occurrenceId = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
|
||||
|
||||
Reference in new issue
Block a user