lots
This commit is contained in:
@@ -60,11 +60,9 @@ readonly class RecordService
|
||||
$uploadResult = FileService::create($schema, $uploadFromUrl, $file);
|
||||
|
||||
$uniqueEdges = collect($edges)
|
||||
->map(fn($e) => (array)(new Edge(...$e)))
|
||||
->map(function ($edge, $index) {
|
||||
$edgeData = (array)(new Edge(...$edge));
|
||||
$edgeData["rank"] = $index;
|
||||
return $edgeData;
|
||||
$edge["rank"] = $index;
|
||||
return (array)(new Edge(...$edge));
|
||||
})
|
||||
->unique(fn($e) => $e['field'] . $e['source'] . $e['target'] . $e['sourceSchema'])
|
||||
->values()->toArray();
|
||||
@@ -77,7 +75,9 @@ readonly class RecordService
|
||||
|
||||
$record = new Record(
|
||||
id: $id ?? Id::new(),
|
||||
_sys: System::newRecord($schema, $this->authService->currentUserId(), $status),
|
||||
schema: $schema->name,
|
||||
status: Status::from($status),
|
||||
_sys: System::newRecord($this->authService->currentUserId()),
|
||||
data: $formattedData,
|
||||
_file: $uploadResult->recordFile,
|
||||
);
|
||||
@@ -109,33 +109,34 @@ readonly class RecordService
|
||||
): void
|
||||
{
|
||||
|
||||
$queryResult = $this->query->filter(["id" => $id])->run();
|
||||
$record = $queryResult->getQueryRecords()->records[0] ?? null;
|
||||
$record = $this->query->filter(["id" => $id])->run()->records->first();
|
||||
|
||||
if (empty($record)) {
|
||||
throw new LucentException("Record id is missing");
|
||||
}
|
||||
$formattedData = $this->inputFormatter->fill($record->_sys->schema, new RecordData($data));
|
||||
$formattedData = $this->inputFormatter->fill($record->schema, new RecordData($data));
|
||||
|
||||
if ($updateEdges) {
|
||||
$uniqueEdges = collect($edges)
|
||||
->map(function ($edge, $index) {
|
||||
$edge["rank"] = $index;
|
||||
$edgeData = (array)(new Edge(...$edge));
|
||||
$edgeData["rank"] = $index;
|
||||
return $edgeData;
|
||||
})
|
||||
->unique(fn($e) => $e['field'] . $e['source'] . $e['target'] . $e['sourceSchema'])
|
||||
->values()->toArray();
|
||||
$uniqueEdgesCollection = EdgeCollection::fromArray($uniqueEdges);
|
||||
$errors = $this->recordValidator->check($record->_sys->schema, $formattedData, $uniqueEdgesCollection);
|
||||
$errors = $this->recordValidator->check($record->schema, $formattedData, $uniqueEdgesCollection);
|
||||
} else {
|
||||
$errors = $this->recordValidator->check($record->_sys->schema, $formattedData, null);
|
||||
$errors = $this->recordValidator->check($record->schema, $formattedData, null);
|
||||
}
|
||||
|
||||
|
||||
$newRecord = new Record(
|
||||
id: $record->id,
|
||||
_sys: $record->_sys->update($this->authService->currentUserId(), $status),
|
||||
schema: $record->schema,
|
||||
status: Status::from($status),
|
||||
_sys: $record->_sys->update($this->authService->currentUserId()),
|
||||
data: $record->data->merge($formattedData),
|
||||
_file: $record->_file,
|
||||
);
|
||||
@@ -162,8 +163,7 @@ readonly class RecordService
|
||||
array $recordsIds,
|
||||
): void
|
||||
{
|
||||
$recordsStatus = (new RecordStatus($status));
|
||||
RecordRepo::updateStatusBulk($recordsStatus, $recordsIds);
|
||||
RecordRepo::updateStatusBulk(Status::from($status), $recordsIds);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,18 +175,17 @@ readonly class RecordService
|
||||
string $recordId,
|
||||
): string
|
||||
{
|
||||
$queryResult = $this->query
|
||||
$graph = $this->query
|
||||
->filter(["id" => $recordId])
|
||||
->limit(1)
|
||||
->childrenDepth(1)
|
||||
->runWithCount();
|
||||
->run();
|
||||
|
||||
|
||||
$graph = $queryResult->getQueryRecords();
|
||||
$record = $graph->records[0] ?? null;
|
||||
$record = $graph->records->first();
|
||||
if (empty($record)) {
|
||||
throw new LucentException("Record id is missing");
|
||||
}
|
||||
|
||||
$newRecordId = (string)Str::uuid();
|
||||
$newEdgesData = $graph->edges
|
||||
->filter(fn(Edge $edge) => $edge->source == $recordId)
|
||||
@@ -199,7 +198,7 @@ readonly class RecordService
|
||||
$record->id = $newRecordId;
|
||||
|
||||
return $this->create(
|
||||
schemaName: $record->_sys->schema,
|
||||
schemaName: $record->schema,
|
||||
data: $record->data->toArray(),
|
||||
id: $record->id,
|
||||
file: $record->_file?->toArray() ?? [],
|
||||
@@ -223,18 +222,14 @@ readonly class RecordService
|
||||
* @throws ValidatorException
|
||||
*/
|
||||
public function rollback(
|
||||
string $userId,
|
||||
string $recordId,
|
||||
int $version,
|
||||
): void
|
||||
{
|
||||
$revision = $this->revisionService->getByRecordIdAndVersion($recordId, $version)->get();
|
||||
$this->update(
|
||||
userId: $userId,
|
||||
id: $revision->recordId,
|
||||
data: $revision->data->toArray(),
|
||||
status: $revision->_sys->status,
|
||||
updateEdges: false
|
||||
);
|
||||
}
|
||||
|
||||
@@ -254,7 +249,9 @@ readonly class RecordService
|
||||
|
||||
return new Record(
|
||||
id: Id::new(),
|
||||
_sys: System::newRecord($schema, $userId),
|
||||
schema: $schema->name,
|
||||
status: Status::DRAFT,
|
||||
_sys: System::newRecord($userId),
|
||||
data: $formattedData,
|
||||
_file: null,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user