feat: establish reservation portal foundation
This commit is contained in:
1
database/.gitignore
vendored
Normal file
1
database/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.sqlite*
|
||||
43
database/factories/SnipeAssetFactory.php
Normal file
43
database/factories/SnipeAssetFactory.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Domain\Inventory\Models\SnipeAsset;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/** @extends Factory<SnipeAsset> */
|
||||
class SnipeAssetFactory extends Factory
|
||||
{
|
||||
protected $model = SnipeAsset::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
$category = fake()->randomElement(['Portáteis', 'Projetores', 'Fotografia', 'Áudio']);
|
||||
$id = fake()->unique()->numberBetween(1000, 99999);
|
||||
|
||||
return [
|
||||
'snipe_asset_id' => $id,
|
||||
'asset_tag' => 'EPVC-'.str_pad((string) $id, 5, '0', STR_PAD_LEFT),
|
||||
'name' => match ($category) {
|
||||
'Portáteis' => fake()->randomElement(['MacBook Air 13', 'Dell Latitude 5440', 'Lenovo ThinkPad E14']),
|
||||
'Projetores' => fake()->randomElement(['Projetor Epson EB-FH06', 'Projetor BenQ MH560']),
|
||||
'Fotografia' => fake()->randomElement(['Canon EOS R10', 'Kit Sony Alpha 6400']),
|
||||
default => fake()->randomElement(['Gravador Zoom H5', 'Kit Rode Wireless GO']),
|
||||
},
|
||||
'model_id' => fake()->numberBetween(1, 50),
|
||||
'model_name' => fake()->bothify('Modelo ##??'),
|
||||
'category_id' => array_search($category, ['Portáteis', 'Projetores', 'Fotografia', 'Áudio'], true) + 1,
|
||||
'category_name' => $category,
|
||||
'manufacturer' => fake()->company(),
|
||||
'status_id' => 1,
|
||||
'status_name' => 'Pronto a disponibilizar',
|
||||
'location_id' => fake()->numberBetween(1, 4),
|
||||
'location_name' => fake()->randomElement(['Biblioteca', 'Serviços de Informática', 'Sala de Audiovisuais']),
|
||||
'requestable' => true,
|
||||
'synced_at' => now(),
|
||||
'source_updated_at' => now(),
|
||||
'content_hash' => fake()->sha256(),
|
||||
'active' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
62
database/factories/UserFactory.php
Normal file
62
database/factories/UserFactory.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends Factory<User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'department' => fake()->randomElement(['Docentes', 'Direção', 'Serviços de Informática', 'Secretaria']),
|
||||
'active' => true,
|
||||
'remember_token' => Str::random(10),
|
||||
'two_factor_secret' => null,
|
||||
'two_factor_recovery_codes' => null,
|
||||
'two_factor_confirmed_at' => null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model has two-factor authentication configured.
|
||||
*/
|
||||
public function withTwoFactor(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'two_factor_secret' => encrypt('secret'),
|
||||
'two_factor_recovery_codes' => encrypt(json_encode(['recovery-code-1'])),
|
||||
'two_factor_confirmed_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
53
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
53
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->uuid('uuid')->unique();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->string('department')->nullable();
|
||||
$table->boolean('active')->default(true);
|
||||
$table->timestamp('last_login_at')->nullable();
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('sessions', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->foreignId('user_id')->nullable()->index();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->text('user_agent')->nullable();
|
||||
$table->longText('payload');
|
||||
$table->integer('last_activity')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
Schema::dropIfExists('sessions');
|
||||
}
|
||||
};
|
||||
35
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
35
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('cache', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->mediumText('value');
|
||||
$table->bigInteger('expiration')->index();
|
||||
});
|
||||
|
||||
Schema::create('cache_locks', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->string('owner');
|
||||
$table->bigInteger('expiration')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('cache');
|
||||
Schema::dropIfExists('cache_locks');
|
||||
}
|
||||
};
|
||||
59
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
59
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedSmallInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
|
||||
Schema::create('job_batches', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->string('name');
|
||||
$table->integer('total_jobs');
|
||||
$table->integer('pending_jobs');
|
||||
$table->integer('failed_jobs');
|
||||
$table->longText('failed_job_ids');
|
||||
$table->mediumText('options')->nullable();
|
||||
$table->integer('cancelled_at')->nullable();
|
||||
$table->integer('created_at');
|
||||
$table->integer('finished_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->string('connection');
|
||||
$table->string('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
|
||||
$table->index(['connection', 'queue', 'failed_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
Schema::dropIfExists('job_batches');
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('passkeys', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('name');
|
||||
$table->string('credential_id')->unique();
|
||||
$table->json('credential');
|
||||
$table->timestamp('last_used_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('user_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('passkeys');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->text('two_factor_secret')->after('password')->nullable();
|
||||
$table->text('two_factor_recovery_codes')->after('two_factor_secret')->nullable();
|
||||
$table->timestamp('two_factor_confirmed_at')->after('two_factor_recovery_codes')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'two_factor_secret',
|
||||
'two_factor_recovery_codes',
|
||||
'two_factor_confirmed_at',
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('roles', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->unique();
|
||||
$table->string('description')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('permissions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->unique();
|
||||
$table->string('description')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('permission_role', function (Blueprint $table) {
|
||||
$table->foreignId('permission_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('role_id')->constrained()->cascadeOnDelete();
|
||||
$table->primary(['permission_id', 'role_id']);
|
||||
});
|
||||
|
||||
Schema::create('role_user', function (Blueprint $table) {
|
||||
$table->foreignId('role_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->primary(['role_id', 'user_id']);
|
||||
});
|
||||
|
||||
Schema::create('external_identities', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('provider');
|
||||
$table->string('provider_subject');
|
||||
$table->string('tenant_id')->nullable();
|
||||
$table->string('provider_email');
|
||||
$table->json('claims')->nullable();
|
||||
$table->timestamp('last_login_at')->nullable();
|
||||
$table->timestamps();
|
||||
$table->unique(['provider', 'provider_subject']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('external_identities');
|
||||
Schema::dropIfExists('role_user');
|
||||
Schema::dropIfExists('permission_role');
|
||||
Schema::dropIfExists('permissions');
|
||||
Schema::dropIfExists('roles');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('snipe_assets', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('snipe_asset_id')->unique();
|
||||
$table->string('asset_tag')->unique();
|
||||
$table->string('name');
|
||||
$table->string('serial')->nullable();
|
||||
$table->unsignedBigInteger('model_id')->nullable();
|
||||
$table->string('model_name')->nullable();
|
||||
$table->unsignedBigInteger('category_id')->nullable();
|
||||
$table->string('category_name')->nullable()->index();
|
||||
$table->string('manufacturer')->nullable();
|
||||
$table->unsignedBigInteger('status_id')->nullable();
|
||||
$table->string('status_name')->nullable();
|
||||
$table->unsignedBigInteger('location_id')->nullable();
|
||||
$table->string('location_name')->nullable()->index();
|
||||
$table->boolean('requestable')->default(false)->index();
|
||||
$table->string('assigned_type')->nullable();
|
||||
$table->unsignedBigInteger('assigned_id')->nullable();
|
||||
$table->string('image_url')->nullable();
|
||||
$table->timestampTz('source_updated_at')->nullable();
|
||||
$table->timestampTz('synced_at')->nullable();
|
||||
$table->string('content_hash', 64)->nullable();
|
||||
$table->boolean('active')->default(true)->index();
|
||||
$table->timestampsTz();
|
||||
});
|
||||
|
||||
Schema::create('reservations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->uuid('uuid')->unique();
|
||||
$table->string('reference')->unique();
|
||||
$table->foreignId('requester_id')->constrained('users')->restrictOnDelete();
|
||||
$table->text('purpose');
|
||||
$table->string('usage_location');
|
||||
$table->timestampTz('starts_at')->index();
|
||||
$table->timestampTz('ends_at')->index();
|
||||
$table->string('status')->index();
|
||||
$table->timestampTz('approval_deadline')->nullable()->index();
|
||||
$table->foreignId('approved_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestampTz('approved_at')->nullable();
|
||||
$table->foreignId('rejected_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestampTz('rejected_at')->nullable();
|
||||
$table->text('decision_reason')->nullable();
|
||||
$table->foreignId('cancelled_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestampTz('cancelled_at')->nullable();
|
||||
$table->text('cancellation_reason')->nullable();
|
||||
$table->timestampsTz();
|
||||
});
|
||||
|
||||
Schema::create('reservation_items', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('reservation_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('snipe_asset_id')->constrained('snipe_assets')->restrictOnDelete();
|
||||
$table->timestampTz('starts_at')->index();
|
||||
$table->timestampTz('ends_at')->index();
|
||||
$table->string('status')->index();
|
||||
$table->timestampTz('delivered_at')->nullable();
|
||||
$table->timestampTz('returned_at')->nullable();
|
||||
$table->string('checkout_reference')->nullable();
|
||||
$table->string('checkin_reference')->nullable();
|
||||
$table->text('condition_out')->nullable();
|
||||
$table->text('condition_in')->nullable();
|
||||
$table->text('notes')->nullable();
|
||||
$table->timestampsTz();
|
||||
$table->unique(['reservation_id', 'snipe_asset_id']);
|
||||
});
|
||||
|
||||
Schema::create('approval_actions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('reservation_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('actor_id')->constrained('users')->restrictOnDelete();
|
||||
$table->string('action');
|
||||
$table->string('previous_status')->nullable();
|
||||
$table->string('new_status');
|
||||
$table->text('comment')->nullable();
|
||||
$table->timestampTz('created_at')->useCurrent();
|
||||
});
|
||||
|
||||
Schema::create('asset_blocks', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('snipe_asset_id')->constrained('snipe_assets')->cascadeOnDelete();
|
||||
$table->timestampTz('starts_at')->index();
|
||||
$table->timestampTz('ends_at')->index();
|
||||
$table->text('reason');
|
||||
$table->foreignId('created_by')->constrained('users')->restrictOnDelete();
|
||||
$table->timestampsTz();
|
||||
});
|
||||
|
||||
if (DB::getDriverName() === 'pgsql') {
|
||||
DB::statement('CREATE EXTENSION IF NOT EXISTS btree_gist');
|
||||
DB::statement(<<<'SQL'
|
||||
ALTER TABLE reservation_items
|
||||
ADD CONSTRAINT reservation_items_no_blocking_overlap
|
||||
EXCLUDE USING gist (
|
||||
snipe_asset_id WITH =,
|
||||
tstzrange(starts_at, ends_at, '[)') WITH &&
|
||||
)
|
||||
WHERE (status IN ('held', 'reserved', 'ready', 'delivered'))
|
||||
SQL);
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('asset_blocks');
|
||||
Schema::dropIfExists('approval_actions');
|
||||
Schema::dropIfExists('reservation_items');
|
||||
Schema::dropIfExists('reservations');
|
||||
Schema::dropIfExists('snipe_assets');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('handover_records', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('reservation_item_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('type');
|
||||
$table->foreignId('operator_id')->constrained('users')->restrictOnDelete();
|
||||
$table->foreignId('recipient_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->text('condition')->nullable();
|
||||
$table->text('notes')->nullable();
|
||||
$table->json('snipe_response')->nullable();
|
||||
$table->timestampTz('created_at')->useCurrent();
|
||||
});
|
||||
|
||||
Schema::create('sync_runs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('type');
|
||||
$table->timestampTz('started_at');
|
||||
$table->timestampTz('finished_at')->nullable();
|
||||
$table->string('status')->index();
|
||||
$table->unsignedInteger('records_processed')->default(0);
|
||||
$table->unsignedInteger('records_created')->default(0);
|
||||
$table->unsignedInteger('records_updated')->default(0);
|
||||
$table->unsignedInteger('records_disabled')->default(0);
|
||||
$table->text('error_message')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('audit_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('actor_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->string('event')->index();
|
||||
$table->nullableMorphs('auditable');
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->text('user_agent')->nullable();
|
||||
$table->json('before')->nullable();
|
||||
$table->json('after')->nullable();
|
||||
$table->json('metadata')->nullable();
|
||||
$table->timestampTz('created_at')->useCurrent()->index();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('audit_logs');
|
||||
Schema::dropIfExists('sync_runs');
|
||||
Schema::dropIfExists('handover_records');
|
||||
}
|
||||
};
|
||||
55
database/seeders/DatabaseSeeder.php
Normal file
55
database/seeders/DatabaseSeeder.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Domain\Identity\Enums\RoleName;
|
||||
use App\Domain\Identity\Models\Role;
|
||||
use App\Domain\Inventory\Models\SnipeAsset;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
use WithoutModelEvents;
|
||||
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$roles = collect(RoleName::cases())->mapWithKeys(fn (RoleName $role) => [
|
||||
$role->value => Role::firstOrCreate(
|
||||
['name' => $role->value],
|
||||
['description' => match ($role) {
|
||||
RoleName::Requester => 'Consulta equipamentos e cria requisições.',
|
||||
RoleName::Approver => 'Decide requisições e consulta o calendário global.',
|
||||
RoleName::InventoryOperator => 'Regista entregas, devoluções e incidentes.',
|
||||
RoleName::Administrator => 'Configura e administra todo o portal.',
|
||||
RoleName::Auditor => 'Consulta histórico e auditoria sem alterar dados.',
|
||||
}]
|
||||
),
|
||||
]);
|
||||
|
||||
$demo = User::factory()->create([
|
||||
'name' => 'Utilizador de Demonstração',
|
||||
'email' => 'demo@escola.pt',
|
||||
'department' => 'Docentes',
|
||||
]);
|
||||
$demo->roles()->attach($roles[RoleName::Requester->value]);
|
||||
|
||||
$admin = User::factory()->create([
|
||||
'name' => 'Administrador do Portal',
|
||||
'email' => 'admin@escola.pt',
|
||||
'department' => 'Serviços de Informática',
|
||||
]);
|
||||
$admin->roles()->attach([
|
||||
$roles[RoleName::Requester->value]->id,
|
||||
$roles[RoleName::Approver->value]->id,
|
||||
$roles[RoleName::InventoryOperator->value]->id,
|
||||
$roles[RoleName::Administrator->value]->id,
|
||||
]);
|
||||
|
||||
SnipeAsset::factory()->count(18)->create();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user