feat(menu): add tickets menu and update related seeder and tests
This commit is contained in:
parent
899bf12457
commit
6ee3f22e41
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
private const MENU_CODE = 'adminapp.tickets';
|
||||
|
||||
private const TENANT_CODE = 'fiesta_futbol_infantil';
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
if (! DB::table('menues')->where('code', 'main.adminapp')->exists()) {
|
||||
// Reference data is added by seeders on fresh installations.
|
||||
return;
|
||||
}
|
||||
|
||||
$now = now();
|
||||
|
||||
DB::transaction(function () use ($now): void {
|
||||
DB::table('menues')->updateOrInsert(
|
||||
['code' => self::MENU_CODE],
|
||||
[
|
||||
'label' => 'Tickets',
|
||||
'parent_menu_code' => 'main.adminapp',
|
||||
'content_type' => 'dynamic',
|
||||
'static_content_schema' => null,
|
||||
'route' => '/admin/tickets',
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
],
|
||||
);
|
||||
|
||||
DB::table('tenants_menues')
|
||||
->where('menu_code', self::MENU_CODE)
|
||||
->where('tenant_code', '!=', self::TENANT_CODE)
|
||||
->delete();
|
||||
|
||||
if (DB::table('tenants')->where('codigo', self::TENANT_CODE)->exists()) {
|
||||
DB::table('tenants_menues')->updateOrInsert(
|
||||
[
|
||||
'tenant_code' => self::TENANT_CODE,
|
||||
'menu_code' => self::MENU_CODE,
|
||||
],
|
||||
[
|
||||
'static_content' => null,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
DB::table('roles')
|
||||
->whereIn('codigo', ['admin', 'adminapp'])
|
||||
->pluck('codigo')
|
||||
->each(function (string $roleCode): void {
|
||||
DB::table('roles_menues')->updateOrInsert([
|
||||
'rol_codigo' => $roleCode,
|
||||
'menu_codigo' => self::MENU_CODE,
|
||||
]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
DB::transaction(function (): void {
|
||||
DB::table('tenants_menues')
|
||||
->where('menu_code', self::MENU_CODE)
|
||||
->delete();
|
||||
|
||||
DB::table('roles_menues')
|
||||
->where('menu_codigo', self::MENU_CODE)
|
||||
->delete();
|
||||
|
||||
DB::table('menues')
|
||||
->where('code', self::MENU_CODE)
|
||||
->delete();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -78,6 +78,12 @@ class MenuSeeder extends Seeder
|
|||
'parent_menu_code' => 'main.adminapp',
|
||||
'route' => '/admin/staff',
|
||||
],
|
||||
[
|
||||
'code' => 'adminapp.tickets',
|
||||
'label' => 'Tickets',
|
||||
'parent_menu_code' => 'main.adminapp',
|
||||
'route' => '/admin/tickets',
|
||||
],
|
||||
[
|
||||
'code' => 'adminapp.fiesta-futbol-infantil.entradas',
|
||||
'label' => 'Entradas',
|
||||
|
|
@ -270,6 +276,7 @@ class MenuSeeder extends Seeder
|
|||
'fiesta_futbol_infantil',
|
||||
];
|
||||
$fiestaCategoryMenuCodes = [
|
||||
'adminapp.tickets',
|
||||
'adminapp.fiesta-futbol-infantil.entradas',
|
||||
'adminapp.fiesta-futbol-infantil.alojamientos',
|
||||
'adminapp.fiesta-futbol-infantil.merchandising',
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ class MenuSeederTest extends TestCase
|
|||
'adminapp.ventas' => ['Ventas', '/admin/ventas'],
|
||||
];
|
||||
$fiestaCategoryMenus = [
|
||||
'adminapp.tickets' => ['Tickets', '/admin/tickets'],
|
||||
'adminapp.fiesta-futbol-infantil.entradas' => ['Entradas', '/admin/entradas'],
|
||||
'adminapp.fiesta-futbol-infantil.alojamientos' => ['Alojamientos', '/admin/alojamientos'],
|
||||
'adminapp.fiesta-futbol-infantil.merchandising' => ['Merchandising', '/admin/merchandising'],
|
||||
|
|
@ -49,7 +50,11 @@ class MenuSeederTest extends TestCase
|
|||
$this->assertSame(Menu::CONTENT_TYPE_DYNAMIC, $adminApp->content_type);
|
||||
$this->assertSame('/', $adminApp->route);
|
||||
$this->assertSame(
|
||||
array_keys([...$expectedMenus, ...$fiestaCategoryMenus]),
|
||||
collect(array_keys([
|
||||
...$expectedMenus,
|
||||
...$fiestaCategoryMenus,
|
||||
'adminapp.desfile.entradas' => ['Entradas', '/admin/desfile/entradas'],
|
||||
]))->sort()->values()->all(),
|
||||
$adminApp->children->pluck('code')->sort()->values()->all()
|
||||
);
|
||||
$this->assertTrue(
|
||||
|
|
|
|||
Loading…
Reference in New Issue