refactor(metadata): rewrite legacy-era regions of the value writer and routes in place

This commit is contained in:
Darko Gjorgjijoski
2026-08-21 10:27:21 +02:00
parent 791a11478d
commit 6372373e81
2 changed files with 20 additions and 11 deletions
@@ -13,12 +13,13 @@ class EloquentCustomFieldValueWriter implements CustomFieldValueWriter
foreach ($customFields as $field) {
$field = $this->normalize($field);
$customField = CustomField::find($field['id']);
$answerColumn = getCustomFieldValueKey($customField->type);
$valuable->fields()->create([
'type' => $customField->type,
'custom_field_id' => $customField->id,
'company_id' => $customField->company_id,
getCustomFieldValueKey($customField->type) => $field['value'],
'type' => $customField['type'],
'custom_field_id' => $customField['id'],
'company_id' => $customField['company_id'],
$answerColumn => $field['value'],
]);
}
}
@@ -29,14 +30,13 @@ class EloquentCustomFieldValueWriter implements CustomFieldValueWriter
$field = $this->normalize($field);
$customField = CustomField::find($field['id']);
$customFieldValue = $valuable->fields()->firstOrCreate([
'custom_field_id' => $customField->id,
'type' => $customField->type,
'custom_field_id' => $customField['id'],
'type' => $customField['type'],
'company_id' => $valuable->company_id,
]);
$type = getCustomFieldValueKey($customField->type);
$customFieldValue->$type = $field['value'];
$customFieldValue->save();
$answerColumn = getCustomFieldValueKey($customField->type);
$customFieldValue->forceFill([$answerColumn => $field['value']])->save();
}
}