lots
This commit is contained in:
+8
-17
@@ -5,18 +5,16 @@ namespace Lucent\Record;
|
||||
use Carbon\Carbon;
|
||||
use Lucent\Schema\Schema;
|
||||
|
||||
class System
|
||||
readonly class System
|
||||
{
|
||||
|
||||
|
||||
function __construct(
|
||||
public readonly string $schema,
|
||||
public readonly int $version,
|
||||
public readonly string $status,
|
||||
public readonly string $createdBy,
|
||||
public readonly string $updatedBy,
|
||||
public readonly string $createdAt,
|
||||
public readonly string $updatedAt,
|
||||
public int $version,
|
||||
public string $createdBy,
|
||||
public string $updatedBy,
|
||||
public string $createdAt,
|
||||
public string $updatedAt,
|
||||
)
|
||||
{
|
||||
|
||||
@@ -26,9 +24,7 @@ class System
|
||||
public static function fromArray(array $data): System
|
||||
{
|
||||
return new System(
|
||||
schema: data_get($data, "schema"),
|
||||
version: data_get($data, "version"),
|
||||
status: data_get($data, "status"),
|
||||
createdBy: data_get($data, "createdBy"),
|
||||
updatedBy: data_get($data, "updatedBy"),
|
||||
createdAt: data_get($data, "createdAt"),
|
||||
@@ -37,13 +33,11 @@ class System
|
||||
}
|
||||
|
||||
|
||||
public static function newRecord(Schema $schema, string $userId, ?string $status = null): System
|
||||
public static function newRecord(string $userId): System
|
||||
{
|
||||
$now = Carbon::now()->toJson();
|
||||
return new System(
|
||||
schema: $schema->name,
|
||||
version: 1,
|
||||
status: (new RecordStatus($status))->value(),
|
||||
createdBy: $userId,
|
||||
updatedBy: $userId,
|
||||
createdAt: $now,
|
||||
@@ -52,14 +46,11 @@ class System
|
||||
}
|
||||
|
||||
|
||||
public function update(string $userId, ?string $status = null): System
|
||||
public function update(string $userId): System
|
||||
{
|
||||
$now = Carbon::now()->toJson();
|
||||
$newStatus = $status ?? $this->status;
|
||||
return new System(
|
||||
schema: $this->schema,
|
||||
version: $this->version + 1,
|
||||
status: (new RecordStatus($newStatus))->value(),
|
||||
createdBy: $this->createdBy,
|
||||
updatedBy: $userId,
|
||||
createdAt: $this->createdAt,
|
||||
|
||||
Reference in New Issue
Block a user