This commit is contained in:
2023-10-13 21:06:23 +03:00
parent 129e3af471
commit 9e37a7f730
34 changed files with 845 additions and 780 deletions
+19 -11
View File
@@ -83,9 +83,11 @@ readonly class RecordService
_file: $uploadResult->recordFile,
);
$errors = $this->recordValidator->check($schemaName, $record->data, $uniqueEdgesCollection);
if ($errors->isNotEmpty()) {
$this->recordValidator->throwException($errors);
if (Status::from($status) === Status::PUBLISHED) {
$errors = $this->recordValidator->check($schemaName, $record->data, $uniqueEdgesCollection);
if ($errors->isNotEmpty()) {
$this->recordValidator->throwException($errors);
}
}
RecordRepo::create($record);
@@ -117,6 +119,7 @@ readonly class RecordService
}
$formattedData = $this->inputFormatter->fill($record->schema, new RecordData($data));
$uniqueEdgesCollection = null;
if ($updateEdges) {
$uniqueEdges = collect($edges)
->map(function ($edge, $index) {
@@ -127,9 +130,17 @@ readonly class RecordService
->unique(fn($e) => $e['field'] . $e['source'] . $e['target'] . $e['sourceSchema'])
->values()->toArray();
$uniqueEdgesCollection = EdgeCollection::fromArray($uniqueEdges);
$errors = $this->recordValidator->check($record->schema, $formattedData, $uniqueEdgesCollection);
} else {
$errors = $this->recordValidator->check($record->schema, $formattedData, null);
}
if (Status::from($status) === Status::PUBLISHED) {
$errors = $this->recordValidator->check($record->schema, $record->data, $uniqueEdgesCollection);
if ($errors->isNotEmpty()) {
$this->recordValidator->throwException($errors);
}
if ($errors->isNotEmpty()) {
$this->recordValidator->throwException($errors);
}
}
@@ -143,9 +154,7 @@ readonly class RecordService
);
if ($errors->isNotEmpty()) {
$this->recordValidator->throwException($errors);
}
RecordRepo::update($newRecord);
if ($updateEdges) {
@@ -237,7 +246,6 @@ readonly class RecordService
public function createEmpty(
Schema $schema,
string $userId,
): Record
{
@@ -252,7 +260,7 @@ readonly class RecordService
id: Id::new(),
schema: $schema->name,
status: Status::DRAFT,
_sys: System::newRecord($userId),
_sys: System::newRecord($this->authService->currentUserId()),
data: $formattedData,
_file: null,
);