Skip to content

Commit 0a86190

Browse files
committed
fix temporary patch code
1 parent 7ea0dca commit 0a86190

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

app/AttributeValue.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Geodata;
66
use App\AttributeTypes\AttributeBase;
7+
use App\Exceptions\InvalidDataException;
78
use Illuminate\Database\Eloquent\Model;
89
use Clickbar\Magellan\Data\Geometries\Geometry;
910
use App\Traits\CommentTrait;
@@ -91,6 +92,7 @@ public function getValue() {
9192
// But this is also already fixed (in a different way) on pull/585 (0.11.2-fix-attribute-value-list-error)
9293
public static function handlePatch(int $entity_id, int $attribute_id, mixed $value, string $operation, User $user, array &$added = [], array &$deleted = []) {
9394
$error = null;
95+
$code = 400;
9496
switch($operation) {
9597
case 'remove':
9698
$attrval = AttributeValue::where([
@@ -146,7 +148,10 @@ public static function handlePatch(int $entity_id, int $attribute_id, mixed $val
146148
}
147149

148150
if($error !== null) {
149-
return $error;
151+
return [
152+
'message' => $error,
153+
'code' => $code,
154+
];
150155
}
151156

152157
// no further action required for deleted attribute values, continue with next patch
@@ -158,7 +163,10 @@ public static function handlePatch(int $entity_id, int $attribute_id, mixed $val
158163
$attr = Attribute::findOrFail($attribute_id);
159164
$formKeyValue = AttributeValue::getFormattedKeyValue($attr->datatype, $value);
160165
} catch(InvalidDataException $ide) {
161-
return $ide->getMessage(); // TODO code 422
166+
return [
167+
'message' => $ide->getMessage(),
168+
'code' => 422,
169+
];
162170
}
163171

164172
$attrval->{$formKeyValue->key} = $formKeyValue->val;

app/Http/Controllers/EntityController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,13 +855,14 @@ public function patchAttributes($id, Request $request) {
855855
foreach($request->request as $patch) {
856856
$op = $patch['op'];
857857
$aid = $patch['params']['aid'];
858-
$value = $patch['value'];
858+
// FIXME [VR]: `?? null` is only necessary, because of temporary AttributeValue::handlePatch() implementation
859+
$value = $patch['value'] ?? null;
859860
$error = AttributeValue::handlePatch($id, $aid, $value, $op, $user, $addedAttributes, $removedAttributes);
860861
if($error !== false) {
861862
DB::rollback();
862863
return response()->json([
863-
'error' => $error,
864-
], 400);
864+
'error' => $error['message'],
865+
], $error['code']);
865866
}
866867
}
867868

0 commit comments

Comments
 (0)