Compare commits
7 Commits
8aa3a26ee7
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| b294e5c46e | |||
| d02b0c5551 | |||
| ee911171be | |||
| e17d1fa15e | |||
| 2a15dc92be | |||
| 3a039a6055 | |||
| 84e45bb964 |
@@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable(['user_id', 'codigo', 'status'])]
|
||||
#[Fillable(['user_id', 'codigo', 'reason', 'status'])]
|
||||
#[Hidden(['codigo'])]
|
||||
class ResetPasswordAttempt extends Model
|
||||
{
|
||||
|
||||
@@ -4,12 +4,14 @@ namespace App\Domains\Auth\Models;
|
||||
|
||||
use App\Domains\Authorization\Enums\RoleCode;
|
||||
use App\Domains\Authorization\Models\Role;
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
@@ -59,6 +61,17 @@ class User extends Authenticatable
|
||||
return $this->belongsTo(Tenant::class, 'tenant_codigo', 'codigo');
|
||||
}
|
||||
|
||||
/** @return BelongsToMany<Category, $this> */
|
||||
public function scanCategories(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(
|
||||
Category::class,
|
||||
'category_scanners',
|
||||
'user_id',
|
||||
'categoria_id',
|
||||
)->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
|
||||
@@ -9,10 +9,15 @@ use App\Domains\Authorization\Enums\RoleCode;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class PasswordLoginService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ResetPasswordAttemptService $resetPasswordAttemptService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws AccountLockedException
|
||||
* @throws ValidationException
|
||||
@@ -118,7 +123,7 @@ class PasswordLoginService
|
||||
|
||||
if ($user === null || ! Hash::check($password, $user->password)) {
|
||||
if ($user !== null) {
|
||||
$this->registerFailure($user, $now);
|
||||
$this->registerFailure($user, $now, $tenantCode);
|
||||
}
|
||||
|
||||
$outcome = $user?->locked_until?->isFuture()
|
||||
@@ -177,7 +182,7 @@ class PasswordLoginService
|
||||
return $result['user'];
|
||||
}
|
||||
|
||||
private function registerFailure(User $user, CarbonImmutable $now): void
|
||||
private function registerFailure(User $user, CarbonImmutable $now, string $tenantCode): void
|
||||
{
|
||||
$windowMinutes = max(1, (int) config('login-security.attempt_window_minutes'));
|
||||
$maxAttempts = max(1, (int) config('login-security.max_attempts'));
|
||||
@@ -189,6 +194,8 @@ class PasswordLoginService
|
||||
? $user->failed_login_attempts + 1
|
||||
: 1;
|
||||
|
||||
$previousAttempts = $user->failed_login_attempts;
|
||||
|
||||
$user->forceFill([
|
||||
'failed_login_attempts' => $attempts,
|
||||
'last_failed_login_at' => $now,
|
||||
@@ -196,6 +203,17 @@ class PasswordLoginService
|
||||
? $now->addMinutes($lockMinutes)
|
||||
: null,
|
||||
])->save();
|
||||
|
||||
if ($attempts >= $maxAttempts && $previousAttempts < $maxAttempts) {
|
||||
try {
|
||||
$this->resetPasswordAttemptService->createForEmail($user->email, $tenantCode, 'account_locked');
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Failed to trigger reset password on account lock', [
|
||||
'user_id' => $user->id,
|
||||
'exception' => $e
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function recordAttempt(
|
||||
|
||||
@@ -11,12 +11,12 @@ use Throwable;
|
||||
|
||||
class ResetPasswordAttemptService
|
||||
{
|
||||
public function createForEmail(string $email, string $tenantCode): void
|
||||
public function createForEmail(string $email, string $tenantCode, string $reason = 'manual'): void
|
||||
{
|
||||
$emailFingerprint = $this->emailFingerprint($email);
|
||||
|
||||
try {
|
||||
$attemptId = DB::transaction(function () use ($email, $emailFingerprint): ?int {
|
||||
$attemptId = DB::transaction(function () use ($email, $emailFingerprint, $reason): ?int {
|
||||
$user = User::query()
|
||||
->where('email', $email)
|
||||
->lockForUpdate()
|
||||
@@ -39,6 +39,7 @@ class ResetPasswordAttemptService
|
||||
|
||||
$attempt = $user->resetPasswordAttempts()->create([
|
||||
'codigo' => $this->generateCode(),
|
||||
'reason' => $reason,
|
||||
'status' => ResetPasswordAttempt::STATUS_PENDING,
|
||||
]);
|
||||
|
||||
|
||||
@@ -6,5 +6,6 @@ enum RoleCode: string
|
||||
{
|
||||
case Admin = 'admin';
|
||||
case AdminApp = 'adminapp';
|
||||
case Scanner = 'scanner';
|
||||
case User = 'user';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Catalog\Controllers\AdminApp;
|
||||
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
use App\Domains\Catalog\Requests\AdminApp\UpsertOnTicketFeaturedGroupRequest;
|
||||
use App\Domains\Catalog\Resources\AdminApp\OnTicketFeaturedGroupResource;
|
||||
use App\Domains\Catalog\Services\OnTicketFeaturedGroupService;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||
|
||||
class OnTicketFeaturedGroupController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly OnTicketFeaturedGroupService $featuredGroupService,
|
||||
) {}
|
||||
|
||||
public function index(Request $request): AnonymousResourceCollection
|
||||
{
|
||||
return OnTicketFeaturedGroupResource::collection(
|
||||
$this->featuredGroupService->forTenant($this->onTicketTenant($request))
|
||||
);
|
||||
}
|
||||
|
||||
public function store(UpsertOnTicketFeaturedGroupRequest $request): JsonResponse
|
||||
{
|
||||
$featuredGroup = $this->featuredGroupService->create(
|
||||
$this->onTicketTenant($request),
|
||||
$request->validated(),
|
||||
);
|
||||
|
||||
return OnTicketFeaturedGroupResource::make($featuredGroup)
|
||||
->response()
|
||||
->setStatusCode(201);
|
||||
}
|
||||
|
||||
public function update(
|
||||
UpsertOnTicketFeaturedGroupRequest $request,
|
||||
FeaturedGroup $featuredGroup,
|
||||
): OnTicketFeaturedGroupResource {
|
||||
$tenant = $this->onTicketTenant($request);
|
||||
|
||||
abort_unless($featuredGroup->tenant_code === $tenant->codigo, 404);
|
||||
|
||||
return OnTicketFeaturedGroupResource::make(
|
||||
$this->featuredGroupService->update(
|
||||
$tenant,
|
||||
$featuredGroup,
|
||||
$request->validated(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function onTicketTenant(Request $request): Tenant
|
||||
{
|
||||
$tenant = $request->user()->tenant()->firstOrFail();
|
||||
|
||||
abort_unless($tenant->website_type_code === 'onticket', 404);
|
||||
|
||||
return $tenant;
|
||||
}
|
||||
}
|
||||
@@ -2,34 +2,28 @@
|
||||
|
||||
namespace App\Domains\Catalog\Controllers;
|
||||
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
use App\Domains\Catalog\Models\FeaturedItem;
|
||||
use App\Domains\Catalog\Requests\CatalogItemDetailRequest;
|
||||
use App\Domains\Catalog\Requests\CategoryPageRequest;
|
||||
use App\Domains\Catalog\Requests\FeaturedGroupPageRequest;
|
||||
use App\Domains\Catalog\Requests\SearchCatalogItemsRequest;
|
||||
use App\Domains\Catalog\Requests\StoreCatalogItemRequest;
|
||||
use App\Domains\Catalog\Resources\CatalogFeaturedGroupResource;
|
||||
use App\Domains\Catalog\Resources\CatalogFeaturedItemResource;
|
||||
use App\Domains\Catalog\Resources\CatalogItemDetailResource;
|
||||
use App\Domains\Catalog\Resources\CatalogItemResource;
|
||||
use App\Domains\Catalog\Resources\CatalogSearchItemResource;
|
||||
use App\Domains\Catalog\Services\CatalogService;
|
||||
use App\Domains\Catalog\Services\FeaturedGroupService;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
class CatalogController extends Controller
|
||||
{
|
||||
private const ITEMS_PER_PAGE = 12;
|
||||
|
||||
public function index(Tenant $tenant): JsonResponse
|
||||
public function index(Tenant $tenant, FeaturedGroupService $featuredGroupService): JsonResponse
|
||||
{
|
||||
$featuredGroups = FeaturedGroup::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
@@ -39,7 +33,7 @@ class CatalogController extends Controller
|
||||
return response()->json($featuredGroups->map(
|
||||
fn (FeaturedGroup $featuredGroup): array => (new CatalogFeaturedGroupResource(
|
||||
$featuredGroup,
|
||||
$this->featuredItemsResponse($featuredGroup, 1),
|
||||
$featuredGroupService->itemsResponse($featuredGroup, 1),
|
||||
))->resolve()
|
||||
));
|
||||
}
|
||||
@@ -89,12 +83,13 @@ class CatalogController extends Controller
|
||||
FeaturedGroupPageRequest $request,
|
||||
Tenant $tenant,
|
||||
FeaturedGroup $featuredGroup,
|
||||
FeaturedGroupService $featuredGroupService,
|
||||
): JsonResponse {
|
||||
abort_unless($featuredGroup->tenant_code === $tenant->codigo, 404);
|
||||
|
||||
$page = (int) $request->validated('page', 1);
|
||||
|
||||
return response()->json($this->featuredItemsResponse($featuredGroup, $page));
|
||||
return response()->json($featuredGroupService->itemsResponse($featuredGroup, $page));
|
||||
}
|
||||
|
||||
public function show(
|
||||
@@ -129,59 +124,4 @@ class CatalogController extends Controller
|
||||
->response()
|
||||
->setStatusCode(201);
|
||||
}
|
||||
|
||||
/** @return array<array-key, mixed> */
|
||||
private function featuredItemsResponse(FeaturedGroup $featuredGroup, int $page): array
|
||||
{
|
||||
if ($featuredGroup->group_layout !== GroupLayout::Paginated) {
|
||||
$featuredItems = $this->featuredItemsQuery($featuredGroup)->get();
|
||||
|
||||
$featuredItems->each(
|
||||
fn ($featuredItem) => $featuredItem->setRelation('featuredGroup', $featuredGroup)
|
||||
);
|
||||
|
||||
return CatalogFeaturedItemResource::collection($featuredItems)->resolve();
|
||||
}
|
||||
|
||||
$paginator = $this->paginateFeaturedItems($featuredGroup, $page);
|
||||
|
||||
$paginator->getCollection()->each(
|
||||
fn ($featuredItem) => $featuredItem->setRelation('featuredGroup', $featuredGroup)
|
||||
);
|
||||
|
||||
return CatalogFeaturedItemResource::collection($paginator)
|
||||
->response()
|
||||
->getData(true);
|
||||
}
|
||||
|
||||
private function paginateFeaturedItems(
|
||||
FeaturedGroup $featuredGroup,
|
||||
int $page,
|
||||
): LengthAwarePaginator {
|
||||
$paginator = $this->featuredItemsQuery($featuredGroup)->paginate(
|
||||
perPage: self::ITEMS_PER_PAGE,
|
||||
pageName: 'page',
|
||||
page: $page,
|
||||
);
|
||||
|
||||
return $paginator->withPath(route('catalog.featured-groups.items.index', [
|
||||
'tenant' => $featuredGroup->tenant_code,
|
||||
'featuredGroup' => $featuredGroup->id,
|
||||
]));
|
||||
}
|
||||
|
||||
/** @return HasMany<FeaturedItem, FeaturedGroup> */
|
||||
private function featuredItemsQuery(FeaturedGroup $featuredGroup): HasMany
|
||||
{
|
||||
return $featuredGroup->featuredItems()->with([
|
||||
'catalogItem.inventory',
|
||||
'catalogItem.attachments',
|
||||
'catalogItem.variants.inventory',
|
||||
'catalogItem.variants.attachments',
|
||||
'catalogItem.variants.eventDate',
|
||||
'catalogItem.variants.definitions.itemAttribute.attribute',
|
||||
'catalogItem.bundleComponents.catalogItem',
|
||||
'catalogItem.bundleComponents.variant.catalogItem',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
18
app/Domains/Catalog/Enums/FeaturedGroupSource.php
Normal file
18
app/Domains/Catalog/Enums/FeaturedGroupSource.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Catalog\Enums;
|
||||
|
||||
enum FeaturedGroupSource: string
|
||||
{
|
||||
case Manual = 'manual';
|
||||
case Category = 'category';
|
||||
case All = 'all';
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function values(): array
|
||||
{
|
||||
return array_column(self::cases(), 'value');
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,13 @@
|
||||
|
||||
namespace App\Domains\Catalog\Models;
|
||||
|
||||
use App\Domains\Auth\Models\User;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
#[Fillable([
|
||||
@@ -64,4 +66,15 @@ class Category extends Model
|
||||
{
|
||||
return $this->hasMany(CatalogItem::class);
|
||||
}
|
||||
|
||||
/** @return BelongsToMany<User, $this> */
|
||||
public function scanners(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(
|
||||
User::class,
|
||||
'category_scanners',
|
||||
'categoria_id',
|
||||
'user_id',
|
||||
)->withTimestamps();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Domains\Catalog\Models;
|
||||
|
||||
use App\Domains\Catalog\Enums\FeaturedGroupSource;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
@@ -13,6 +14,8 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
#[Fillable([
|
||||
'tenant_code',
|
||||
'source_type',
|
||||
'category_id',
|
||||
'product_layout',
|
||||
'group_layout',
|
||||
'group_name',
|
||||
@@ -26,9 +29,15 @@ class FeaturedGroup extends Model
|
||||
|
||||
protected $table = 'featured_groups';
|
||||
|
||||
protected $attributes = [
|
||||
'source_type' => FeaturedGroupSource::Manual->value,
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'source_type' => FeaturedGroupSource::class,
|
||||
'category_id' => 'integer',
|
||||
'product_layout' => ProductLayout::class,
|
||||
'group_layout' => GroupLayout::class,
|
||||
'group_order' => 'integer',
|
||||
@@ -41,6 +50,12 @@ class FeaturedGroup extends Model
|
||||
return $this->belongsTo(Tenant::class, 'tenant_code', 'codigo');
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Category, $this> */
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
/** @return HasMany<FeaturedItem, $this> */
|
||||
public function featuredItems(): HasMany
|
||||
{
|
||||
|
||||
@@ -95,25 +95,7 @@ class Variant extends Model
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
$name = $this->catalogItem->nombre;
|
||||
$this->loadMissing(['definitions.itemAttribute.attribute', 'eventDate']);
|
||||
$definitions = $this->definitions
|
||||
->map(function (VariantDefinition $definition): ?string {
|
||||
$attributeName = $definition->itemAttribute?->attribute?->nombre;
|
||||
|
||||
return $attributeName
|
||||
? "{$attributeName}: {$definition->value}"
|
||||
: $definition->value;
|
||||
})
|
||||
->filter();
|
||||
|
||||
if ($this->eventDate !== null) {
|
||||
$definitions->push('Fecha: '.$this->eventDate->date->format('Y-m-d'));
|
||||
}
|
||||
|
||||
$description = $definitions->implode(', ');
|
||||
|
||||
return $description === '' ? $name : "{$name} ({$description})";
|
||||
return $this->catalogItem->nombre;
|
||||
}
|
||||
|
||||
public function getMinimumUseDate(): ?CarbonInterface
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Catalog\Requests\AdminApp;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpsertOnTicketFeaturedGroupRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'category_name' => ['required', 'string', 'max:255'],
|
||||
'is_featured' => ['required', 'boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Catalog\Resources\AdminApp;
|
||||
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/** @mixin FeaturedGroup */
|
||||
class OnTicketFeaturedGroupResource extends JsonResource
|
||||
{
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'category_id' => $this->category_id,
|
||||
'category_name' => $this->category->nombre,
|
||||
'group_name' => $this->group_name,
|
||||
'is_featured' => $this->product_layout === ProductLayout::Row,
|
||||
'type' => $this->source_type->value,
|
||||
'product_layout' => $this->product_layout->value,
|
||||
'group_layout' => $this->group_layout->value,
|
||||
'order' => $this->group_order,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -5,20 +5,22 @@ namespace App\Domains\Catalog\Resources;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\FeaturedItem;
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
use App\Domains\Catalog\Models\Variant;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/** @mixin FeaturedItem */
|
||||
/** @mixin CatalogItem */
|
||||
class CatalogFeaturedItemResource extends JsonResource
|
||||
{
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$catalogItem = $this->catalogItem;
|
||||
$catalogItem = $this->resource;
|
||||
/** @var FeaturedGroup $featuredGroup */
|
||||
$featuredGroup = $catalogItem->getRelation('featuredGroup');
|
||||
|
||||
if ($this->featuredGroup->product_layout === ProductLayout::ColumnWithImage) {
|
||||
if ($featuredGroup->product_layout === ProductLayout::ColumnWithImage) {
|
||||
return $this->columnWithImageData($catalogItem);
|
||||
}
|
||||
|
||||
|
||||
87
app/Domains/Catalog/Services/FeaturedGroupService.php
Normal file
87
app/Domains/Catalog/Services/FeaturedGroupService.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Catalog\Services;
|
||||
|
||||
use App\Domains\Catalog\Enums\FeaturedGroupSource;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
use App\Domains\Catalog\Resources\CatalogFeaturedItemResource;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
class FeaturedGroupService
|
||||
{
|
||||
private const ITEMS_PER_PAGE = 12;
|
||||
|
||||
/** @return array<array-key, mixed> */
|
||||
public function itemsResponse(FeaturedGroup $featuredGroup, int $page): array
|
||||
{
|
||||
if ($featuredGroup->group_layout !== GroupLayout::Paginated) {
|
||||
$items = $this->itemsQuery($featuredGroup)->get();
|
||||
$this->attachGroup($items, $featuredGroup);
|
||||
|
||||
return CatalogFeaturedItemResource::collection($items)->resolve();
|
||||
}
|
||||
|
||||
$paginator = $this->paginateItems($featuredGroup, $page);
|
||||
$this->attachGroup($paginator->getCollection(), $featuredGroup);
|
||||
|
||||
return CatalogFeaturedItemResource::collection($paginator)
|
||||
->response()
|
||||
->getData(true);
|
||||
}
|
||||
|
||||
/** @return Builder<CatalogItem> */
|
||||
private function itemsQuery(FeaturedGroup $featuredGroup): Builder
|
||||
{
|
||||
$query = CatalogItem::query()
|
||||
->where('catalog_items.tenant_code', $featuredGroup->tenant_code)
|
||||
->with([
|
||||
'inventory',
|
||||
'attachments',
|
||||
'variants.inventory',
|
||||
'variants.attachments',
|
||||
'variants.eventDate',
|
||||
'variants.definitions.itemAttribute.attribute',
|
||||
'bundleComponents.catalogItem',
|
||||
'bundleComponents.variant.catalogItem',
|
||||
]);
|
||||
|
||||
return match ($featuredGroup->source_type) {
|
||||
FeaturedGroupSource::Manual => $query
|
||||
->select('catalog_items.*')
|
||||
->join('featured_items', 'featured_items.catalog_item_id', '=', 'catalog_items.id')
|
||||
->where('featured_items.featured_group_id', $featuredGroup->id)
|
||||
->orderBy('featured_items.order')
|
||||
->orderBy('featured_items.id'),
|
||||
FeaturedGroupSource::Category => $query
|
||||
->where('catalog_items.category_id', $featuredGroup->category_id)
|
||||
->orderBy('catalog_items.id'),
|
||||
FeaturedGroupSource::All => $query->orderBy('catalog_items.id'),
|
||||
};
|
||||
}
|
||||
|
||||
private function paginateItems(
|
||||
FeaturedGroup $featuredGroup,
|
||||
int $page,
|
||||
): LengthAwarePaginator {
|
||||
$paginator = $this->itemsQuery($featuredGroup)->paginate(
|
||||
perPage: self::ITEMS_PER_PAGE,
|
||||
pageName: 'page',
|
||||
page: $page,
|
||||
);
|
||||
|
||||
return $paginator->withPath(route('catalog.featured-groups.items.index', [
|
||||
'tenant' => $featuredGroup->tenant_code,
|
||||
'featuredGroup' => $featuredGroup->id,
|
||||
]));
|
||||
}
|
||||
|
||||
private function attachGroup(iterable $items, FeaturedGroup $featuredGroup): void
|
||||
{
|
||||
foreach ($items as $item) {
|
||||
$item->setRelation('featuredGroup', $featuredGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Catalog\Services;
|
||||
|
||||
use App\Domains\Catalog\Enums\FeaturedGroupSource;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class OnTicketFeaturedGroupService
|
||||
{
|
||||
/** @return Collection<int, FeaturedGroup> */
|
||||
public function forTenant(Tenant $tenant): Collection
|
||||
{
|
||||
return FeaturedGroup::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->where('source_type', FeaturedGroupSource::Category)
|
||||
->whereHas('category', fn ($query) => $query->where('tenant_code', $tenant->codigo))
|
||||
->with('category')
|
||||
->orderBy('group_order')
|
||||
->orderBy('id')
|
||||
->get();
|
||||
}
|
||||
|
||||
/** @param array{category_name: string, is_featured: bool} $data */
|
||||
public function create(Tenant $tenant, array $data): FeaturedGroup
|
||||
{
|
||||
return DB::transaction(function () use ($tenant, $data): FeaturedGroup {
|
||||
$category = $tenant->categories()->create([
|
||||
'nombre' => $data['category_name'],
|
||||
]);
|
||||
|
||||
$featuredGroup = FeaturedGroup::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'source_type' => FeaturedGroupSource::Category,
|
||||
'category_id' => $category->id,
|
||||
'product_layout' => $this->productLayout($data['is_featured']),
|
||||
'group_layout' => GroupLayout::Paginated,
|
||||
'group_name' => $data['category_name'],
|
||||
'group_order' => $this->nextOrder($tenant),
|
||||
]);
|
||||
|
||||
return $featuredGroup->setRelation('category', $category);
|
||||
});
|
||||
}
|
||||
|
||||
/** @param array{category_name: string, is_featured: bool} $data */
|
||||
public function update(
|
||||
Tenant $tenant,
|
||||
FeaturedGroup $featuredGroup,
|
||||
array $data,
|
||||
): FeaturedGroup {
|
||||
return DB::transaction(function () use ($tenant, $featuredGroup, $data): FeaturedGroup {
|
||||
$featuredGroup = FeaturedGroup::query()
|
||||
->whereKey($featuredGroup->getKey())
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->where('source_type', FeaturedGroupSource::Category)
|
||||
->lockForUpdate()
|
||||
->firstOrFail();
|
||||
|
||||
$category = Category::query()
|
||||
->whereKey($featuredGroup->category_id)
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->lockForUpdate()
|
||||
->firstOrFail();
|
||||
|
||||
$category->update(['nombre' => $data['category_name']]);
|
||||
$featuredGroup->update([
|
||||
'group_name' => $data['category_name'],
|
||||
'product_layout' => $this->productLayout($data['is_featured']),
|
||||
'group_layout' => GroupLayout::Paginated,
|
||||
]);
|
||||
|
||||
return $featuredGroup->setRelation('category', $category);
|
||||
});
|
||||
}
|
||||
|
||||
private function productLayout(bool $isFeatured): ProductLayout
|
||||
{
|
||||
return $isFeatured ? ProductLayout::Row : ProductLayout::ColumnWithCart;
|
||||
}
|
||||
|
||||
private function nextOrder(Tenant $tenant): int
|
||||
{
|
||||
$maximumOrder = FeaturedGroup::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->max('group_order');
|
||||
|
||||
return $maximumOrder === null ? 0 : ((int) $maximumOrder) + 1;
|
||||
}
|
||||
}
|
||||
15
app/Domains/Catalog/routes/adminapp.php
Normal file
15
app/Domains/Catalog/routes/adminapp.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use App\Domains\Catalog\Controllers\AdminApp\OnTicketFeaturedGroupController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::prefix('v1/adminapp/tenant')
|
||||
->middleware(['auth:sanctum', 'adminapp.tenant'])
|
||||
->group(function (): void {
|
||||
Route::get('featured-groups', [OnTicketFeaturedGroupController::class, 'index'])
|
||||
->name('adminapp.featured-groups.index');
|
||||
Route::post('featured-groups', [OnTicketFeaturedGroupController::class, 'store'])
|
||||
->name('adminapp.featured-groups.store');
|
||||
Route::put('featured-groups/{featuredGroup}', [OnTicketFeaturedGroupController::class, 'update'])
|
||||
->name('adminapp.featured-groups.update');
|
||||
});
|
||||
@@ -14,3 +14,5 @@ Route::prefix('tenants/{tenant:codigo}')->group(function (): void {
|
||||
Route::get('catalog-items/{catalogItem}', [CatalogController::class, 'show']);
|
||||
Route::post('catalog-items', [CatalogController::class, 'store']);
|
||||
});
|
||||
|
||||
require __DIR__.'/adminapp.php';
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Forms\Controllers\AdminApp;
|
||||
|
||||
use App\Domains\Forms\Resources\StaffFormResource;
|
||||
use App\Domains\Forms\Services\StaffFormService;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class StaffFormController extends Controller
|
||||
{
|
||||
public function __construct(protected StaffFormService $staffFormService) {}
|
||||
|
||||
public function __invoke(Request $request): StaffFormResource
|
||||
{
|
||||
return StaffFormResource::make(
|
||||
$this->staffFormService->get(
|
||||
$request->user('sanctum')->tenant()->firstOrFail()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
20
app/Domains/Forms/Resources/StaffFormResource.php
Normal file
20
app/Domains/Forms/Resources/StaffFormResource.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Forms\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class StaffFormResource extends JsonResource
|
||||
{
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'categories' => $this->resource['categories']->map(fn ($category) => [
|
||||
'id' => $category->id,
|
||||
'nombre' => $category->nombre,
|
||||
])->values(),
|
||||
];
|
||||
}
|
||||
}
|
||||
27
app/Domains/Forms/Services/StaffFormService.php
Normal file
27
app/Domains/Forms/Services/StaffFormService.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Forms\Services;
|
||||
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class StaffFormService
|
||||
{
|
||||
/** @return array{categories: Collection<int, Category>} */
|
||||
public function get(Tenant $tenant): array
|
||||
{
|
||||
return [
|
||||
'categories' => Category::query()
|
||||
->whereNull('categoria_id')
|
||||
->where(function (Builder $query) use ($tenant): void {
|
||||
$query->where('tenant_code', $tenant->codigo)
|
||||
->orWhereHas('catalogItems', fn (Builder $items) => $items
|
||||
->where('tenant_code', $tenant->codigo));
|
||||
})
|
||||
->orderBy('nombre')
|
||||
->get(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use App\Domains\Forms\Controllers\AdminApp\EventFormController;
|
||||
use App\Domains\Forms\Controllers\AdminApp\SaleFormController;
|
||||
use App\Domains\Forms\Controllers\AdminApp\StaffFormController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::prefix('v1/adminapp/forms')
|
||||
@@ -9,4 +10,5 @@ Route::prefix('v1/adminapp/forms')
|
||||
->group(function (): void {
|
||||
Route::get('event', EventFormController::class);
|
||||
Route::get('sale', SaleFormController::class);
|
||||
Route::get('staff', StaffFormController::class);
|
||||
});
|
||||
|
||||
49
app/Domains/Staff/Controllers/AdminAppStaffController.php
Normal file
49
app/Domains/Staff/Controllers/AdminAppStaffController.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Staff\Controllers;
|
||||
|
||||
use App\Domains\Staff\Requests\StoreStaffRequest;
|
||||
use App\Domains\Staff\Requests\UpdateStaffRequest;
|
||||
use App\Domains\Staff\Resources\StaffResource;
|
||||
use App\Domains\Staff\Services\StaffService;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class AdminAppStaffController extends Controller
|
||||
{
|
||||
public function __construct(private readonly StaffService $staffService) {}
|
||||
|
||||
public function index(Request $request): AnonymousResourceCollection
|
||||
{
|
||||
return StaffResource::collection($this->staffService->list(
|
||||
$request->user()->tenant()->firstOrFail(),
|
||||
$request->string('search')->trim()->toString() ?: null,
|
||||
));
|
||||
}
|
||||
|
||||
public function store(StoreStaffRequest $request): StaffResource
|
||||
{
|
||||
return StaffResource::make($this->staffService->create(
|
||||
$request->user()->tenant()->firstOrFail(),
|
||||
$request->validated(),
|
||||
));
|
||||
}
|
||||
|
||||
public function update(UpdateStaffRequest $request, int $staff): StaffResource
|
||||
{
|
||||
return StaffResource::make($this->staffService->update(
|
||||
$request->user()->tenant()->firstOrFail(),
|
||||
$staff,
|
||||
$request->validated(),
|
||||
));
|
||||
}
|
||||
|
||||
public function destroy(Request $request, int $staff): Response
|
||||
{
|
||||
$this->staffService->delete($request->user()->tenant()->firstOrFail(), $staff);
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
}
|
||||
26
app/Domains/Staff/Requests/StoreStaffRequest.php
Normal file
26
app/Domains/Staff/Requests/StoreStaffRequest.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Staff\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreStaffRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'nombre_apellido' => ['required', 'string', 'max:255'],
|
||||
'dni' => ['required', 'string', 'max:50'],
|
||||
'email' => ['required', 'email', 'max:255', 'unique:users,email'],
|
||||
'category_ids' => ['required', 'array', 'min:1'],
|
||||
'category_ids.*' => ['required', 'integer', 'distinct', Rule::exists('categorias', 'id')],
|
||||
];
|
||||
}
|
||||
}
|
||||
33
app/Domains/Staff/Requests/UpdateStaffRequest.php
Normal file
33
app/Domains/Staff/Requests/UpdateStaffRequest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Staff\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpdateStaffRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function rules(): array
|
||||
{
|
||||
$staffId = (int) $this->route('staff');
|
||||
|
||||
return [
|
||||
'nombre_apellido' => ['required', 'string', 'max:255'],
|
||||
'dni' => ['required', 'string', 'max:50'],
|
||||
'email' => [
|
||||
'required',
|
||||
'email',
|
||||
'max:255',
|
||||
Rule::unique('users', 'email')->ignore($staffId),
|
||||
],
|
||||
'category_ids' => ['required', 'array', 'min:1'],
|
||||
'category_ids.*' => ['required', 'integer', 'distinct', Rule::exists('categorias', 'id')],
|
||||
];
|
||||
}
|
||||
}
|
||||
32
app/Domains/Staff/Resources/StaffResource.php
Normal file
32
app/Domains/Staff/Resources/StaffResource.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Staff\Resources;
|
||||
|
||||
use App\Domains\Auth\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/** @mixin User */
|
||||
class StaffResource extends JsonResource
|
||||
{
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'nombre_apellido' => $this->nombre_apellido,
|
||||
'dni' => $this->dni,
|
||||
'email' => $this->email,
|
||||
'rol_codigo' => $this->rol_codigo,
|
||||
'role' => $this->whenLoaded('role', fn () => [
|
||||
'codigo' => $this->role?->codigo,
|
||||
'nombre' => $this->role?->nombre,
|
||||
]),
|
||||
'categories' => $this->whenLoaded('scanCategories', fn () => $this->scanCategories
|
||||
->map(fn ($category) => [
|
||||
'id' => $category->id,
|
||||
'nombre' => $category->nombre,
|
||||
])->values()),
|
||||
];
|
||||
}
|
||||
}
|
||||
113
app/Domains/Staff/Services/StaffService.php
Normal file
113
app/Domains/Staff/Services/StaffService.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Staff\Services;
|
||||
|
||||
use App\Domains\Auth\Models\User;
|
||||
use App\Domains\Authorization\Enums\RoleCode;
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class StaffService
|
||||
{
|
||||
/** @return Collection<int, User> */
|
||||
public function list(Tenant $tenant, ?string $search = null): Collection
|
||||
{
|
||||
return $this->staffQuery($tenant)
|
||||
->with(['role', 'scanCategories' => fn ($query) => $query->orderBy('nombre')])
|
||||
->when($search, function (Builder $query, string $search): void {
|
||||
$query->where(function (Builder $query) use ($search): void {
|
||||
$query->where('nombre_apellido', 'like', "%{$search}%")
|
||||
->orWhere('dni', 'like', "%{$search}%")
|
||||
->orWhere('email', 'like', "%{$search}%");
|
||||
});
|
||||
})
|
||||
->orderBy('nombre_apellido')
|
||||
->get();
|
||||
}
|
||||
|
||||
/** @return Collection<int, Category> */
|
||||
private function assignableCategories(Tenant $tenant): Collection
|
||||
{
|
||||
return Category::query()
|
||||
->whereNull('categoria_id')
|
||||
->where(function (Builder $query) use ($tenant): void {
|
||||
$query->where('tenant_code', $tenant->codigo)
|
||||
->orWhereHas('catalogItems', fn (Builder $items) => $items
|
||||
->where('tenant_code', $tenant->codigo));
|
||||
})
|
||||
->orderBy('nombre')
|
||||
->get();
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $data */
|
||||
public function create(Tenant $tenant, array $data): User
|
||||
{
|
||||
$this->assertCategoriesBelongToTenant($tenant, $data['category_ids']);
|
||||
|
||||
return DB::transaction(function () use ($tenant, $data): User {
|
||||
$staff = User::query()->create([
|
||||
...Arr::only($data, ['nombre_apellido', 'dni', 'email']),
|
||||
'email' => mb_strtolower(trim((string) $data['email'])),
|
||||
'password' => Str::random(64),
|
||||
'rol_codigo' => RoleCode::Scanner->value,
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
]);
|
||||
$staff->scanCategories()->sync($data['category_ids']);
|
||||
|
||||
return $staff->load('role', 'scanCategories');
|
||||
});
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $data */
|
||||
public function update(Tenant $tenant, int $staffId, array $data): User
|
||||
{
|
||||
$staff = $this->find($tenant, $staffId);
|
||||
$this->assertCategoriesBelongToTenant($tenant, $data['category_ids']);
|
||||
|
||||
return DB::transaction(function () use ($staff, $data): User {
|
||||
$attributes = Arr::only($data, ['nombre_apellido', 'dni', 'email']);
|
||||
$attributes['email'] = mb_strtolower(trim((string) $data['email']));
|
||||
$staff->update($attributes);
|
||||
$staff->scanCategories()->sync($data['category_ids']);
|
||||
|
||||
return $staff->load('role', 'scanCategories');
|
||||
});
|
||||
}
|
||||
|
||||
public function delete(Tenant $tenant, int $staffId): void
|
||||
{
|
||||
$this->find($tenant, $staffId)->delete();
|
||||
}
|
||||
|
||||
public function find(Tenant $tenant, int $staffId): User
|
||||
{
|
||||
return $this->staffQuery($tenant)->findOrFail($staffId);
|
||||
}
|
||||
|
||||
private function staffQuery(Tenant $tenant): Builder
|
||||
{
|
||||
return User::query()
|
||||
->where('tenant_codigo', $tenant->codigo)
|
||||
->where('rol_codigo', RoleCode::Scanner->value);
|
||||
}
|
||||
|
||||
/** @param array<int, int> $categoryIds */
|
||||
private function assertCategoriesBelongToTenant(Tenant $tenant, array $categoryIds): void
|
||||
{
|
||||
$validIds = $this->assignableCategories($tenant)
|
||||
->whereIn('id', $categoryIds)
|
||||
->pluck('id');
|
||||
|
||||
if ($validIds->count() !== count($categoryIds)) {
|
||||
throw ValidationException::withMessages([
|
||||
'category_ids' => 'Una o más categorías no pertenecen al tenant.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
10
app/Domains/Staff/routes/api.php
Normal file
10
app/Domains/Staff/routes/api.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
use App\Domains\Staff\Controllers\AdminAppStaffController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::prefix('v1/adminapp/tenant')
|
||||
->middleware(['auth:sanctum', 'adminapp.tenant'])
|
||||
->group(function (): void {
|
||||
Route::apiResource('staff', AdminAppStaffController::class)->except('show');
|
||||
});
|
||||
@@ -24,6 +24,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
'starts_at',
|
||||
'expires_at',
|
||||
'used_at',
|
||||
'scanner_user_id',
|
||||
'user_id',
|
||||
])]
|
||||
class Ticket extends Model
|
||||
@@ -47,6 +48,7 @@ class Ticket extends Model
|
||||
'starts_at' => 'datetime',
|
||||
'expires_at' => 'datetime',
|
||||
'used_at' => 'datetime',
|
||||
'scanner_user_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
];
|
||||
}
|
||||
@@ -63,6 +65,12 @@ class Ticket extends Model
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/** @return BelongsTo<User, $this> */
|
||||
public function scannerUser(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'scanner_user_id');
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Purchase, $this> */
|
||||
public function sourcePurchase(): BelongsTo
|
||||
{
|
||||
|
||||
@@ -23,6 +23,7 @@ class TicketResource extends JsonResource
|
||||
'starts_at' => $this->getEffectiveStartsAt(),
|
||||
'expires_at' => $this->getEffectiveExpiresAt(),
|
||||
'used_at' => $this->used_at,
|
||||
'scanner_user_id' => $this->scanner_user_id,
|
||||
'is_valid' => $this->is_valid,
|
||||
'is_expired' => $this->is_expired,
|
||||
'is_used' => $this->is_used,
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use App\Domains\Catalog\Enums\FeaturedGroupSource;
|
||||
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::table('featured_groups', function (Blueprint $table): void {
|
||||
$table->enum('source_type', FeaturedGroupSource::values())
|
||||
->default(FeaturedGroupSource::Manual->value)
|
||||
->after('tenant_code');
|
||||
$table->foreignId('category_id')
|
||||
->nullable()
|
||||
->after('source_type')
|
||||
->constrained('categorias')
|
||||
->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('featured_groups', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('category_id');
|
||||
$table->dropColumn('source_type');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
<?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('category_scanners', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnUpdate()->cascadeOnDelete();
|
||||
$table->foreignId('categoria_id')->constrained('categorias')->cascadeOnUpdate()->cascadeOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['user_id', 'categoria_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('category_scanners');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
<?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::table('tickets', function (Blueprint $table): void {
|
||||
$table->foreignId('scanner_user_id')
|
||||
->nullable()
|
||||
->after('used_at')
|
||||
->constrained('users')
|
||||
->cascadeOnUpdate()
|
||||
->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('tickets', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('scanner_user_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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('reset_password_attempts', function (Blueprint $table): void {
|
||||
$table->string('reason')->default('manual')->after('codigo');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('reset_password_attempts', function (Blueprint $table): void {
|
||||
$table->dropColumn('reason');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -81,6 +81,10 @@ class AuthorizationSeeder extends Seeder
|
||||
'nombre' => 'Gestionar tickets',
|
||||
'descripcion' => 'Permite emitir, invalidar o regenerar tickets.',
|
||||
],
|
||||
'tickets.escanear' => [
|
||||
'nombre' => 'Escanear tickets',
|
||||
'descripcion' => 'Permite validar y consumir tickets de las categorías asignadas al usuario.',
|
||||
],
|
||||
'contenido.gestionar' => [
|
||||
'nombre' => 'Gestionar contenido',
|
||||
'descripcion' => 'Permite administrar menús, carruseles, destacados y redes sociales.',
|
||||
@@ -117,6 +121,11 @@ class AuthorizationSeeder extends Seeder
|
||||
'descripcion' => 'Accede a los menús administrativos de la aplicación.',
|
||||
'permisos' => [],
|
||||
],
|
||||
RoleCode::Scanner->value => [
|
||||
'nombre' => 'Scanner',
|
||||
'descripcion' => 'Valida y consume tickets de las categorías que tiene asignadas.',
|
||||
'permisos' => ['tickets.escanear'],
|
||||
],
|
||||
RoleCode::User->value => [
|
||||
'nombre' => 'Usuario',
|
||||
'descripcion' => 'Cliente final limitado a sus propios datos y operaciones.',
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Database\Seeders;
|
||||
|
||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use App\Domains\Catalog\Enums\FeaturedGroupSource;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
@@ -61,6 +62,18 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
'nombre' => 'Gastronomía',
|
||||
'tenant_code' => $tenant->codigo,
|
||||
]);
|
||||
$mealCategory = Category::query()->updateOrCreate([
|
||||
'nombre' => 'Comidas',
|
||||
'tenant_code' => $tenant->codigo,
|
||||
], [
|
||||
'categoria_id' => $foodCategory->id,
|
||||
]);
|
||||
$drinkCategory = Category::query()->updateOrCreate([
|
||||
'nombre' => 'Bebidas',
|
||||
'tenant_code' => $tenant->codigo,
|
||||
], [
|
||||
'categoria_id' => $foodCategory->id,
|
||||
]);
|
||||
$parkingCategory = Category::query()->firstOrCreate([
|
||||
'nombre' => 'Estacionamiento',
|
||||
'tenant_code' => $tenant->codigo,
|
||||
@@ -93,10 +106,10 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
]);
|
||||
|
||||
$items = [
|
||||
['slug' => 'hamburguesa-papa-frita', 'nombre' => 'Hamburguesa con papa frita', 'precio' => 8000, 'category_id' => $foodCategory->id],
|
||||
['slug' => 'pancho', 'nombre' => 'Pancho', 'precio' => 4000, 'category_id' => $foodCategory->id],
|
||||
['slug' => 'coca-cola-500ml', 'nombre' => 'Coca Cola 500ml', 'precio' => 3000, 'category_id' => $foodCategory->id],
|
||||
['slug' => 'agua-mineral-1l', 'nombre' => 'Agua Mineral 1L', 'precio' => 2500, 'category_id' => $foodCategory->id],
|
||||
['slug' => 'hamburguesa-papa-frita', 'nombre' => 'Hamburguesa con papa frita', 'precio' => 8000, 'category_id' => $mealCategory->id],
|
||||
['slug' => 'pancho', 'nombre' => 'Pancho', 'precio' => 4000, 'category_id' => $mealCategory->id],
|
||||
['slug' => 'coca-cola-500ml', 'nombre' => 'Coca Cola 500ml', 'precio' => 3000, 'category_id' => $drinkCategory->id],
|
||||
['slug' => 'agua-mineral-1l', 'nombre' => 'Agua Mineral 1L', 'precio' => 2500, 'category_id' => $drinkCategory->id],
|
||||
['slug' => 'estacionamiento-auto', 'nombre' => 'Estacionamiento Auto', 'precio' => 5000, 'category_id' => $parkingCategory->id],
|
||||
['slug' => 'estacionamiento-moto', 'nombre' => 'Estacionamiento Moto', 'precio' => 2000, 'category_id' => $parkingCategory->id],
|
||||
];
|
||||
@@ -144,7 +157,7 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
'nombre' => 'Combo 2 Panchos + 2 Hamburguesas',
|
||||
'descripcion' => 'Incluye 2 panchos y 2 hamburguesas con papa frita.',
|
||||
'precio' => 24000,
|
||||
'category_id' => $foodCategory->id,
|
||||
'category_id' => $mealCategory->id,
|
||||
'components' => [
|
||||
[
|
||||
'catalog_item_id' => $createdItems['pancho']->id,
|
||||
@@ -157,7 +170,12 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
],
|
||||
]);
|
||||
|
||||
$this->seedFeaturedGroups($tenant);
|
||||
$this->seedFeaturedGroups($tenant, [
|
||||
'Entradas' => $ticketCategory,
|
||||
'Estacionamiento' => $parkingCategory,
|
||||
'Comidas' => $mealCategory,
|
||||
'Bebidas' => $drinkCategory,
|
||||
]);
|
||||
}
|
||||
|
||||
private function deleteExistingCatalog(Tenant $tenant): void
|
||||
@@ -173,7 +191,8 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
->each(fn (CatalogItem $item) => $this->catalogService->delete($item));
|
||||
}
|
||||
|
||||
private function seedFeaturedGroups(Tenant $tenant): void
|
||||
/** @param array<string, Category> $categories */
|
||||
private function seedFeaturedGroups(Tenant $tenant, array $categories): void
|
||||
{
|
||||
FeaturedGroup::query()->where('tenant_code', $tenant->codigo)->delete();
|
||||
|
||||
@@ -181,62 +200,33 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
'Entradas' => [
|
||||
'product_layout' => ProductLayout::Row,
|
||||
'group_layout' => GroupLayout::SimpleVertical,
|
||||
'slugs' => [
|
||||
'entrada-general',
|
||||
'entrada-general-todos-los-dias',
|
||||
],
|
||||
],
|
||||
'Estacionamiento' => [
|
||||
'product_layout' => ProductLayout::ColumnWithCart,
|
||||
'group_layout' => GroupLayout::Simple,
|
||||
'slugs' => [
|
||||
'estacionamiento-auto',
|
||||
'estacionamiento-moto',
|
||||
],
|
||||
],
|
||||
'Comidas' => [
|
||||
'product_layout' => ProductLayout::ColumnWithCart,
|
||||
'group_layout' => GroupLayout::Simple,
|
||||
'slugs' => [
|
||||
'hamburguesa-papa-frita',
|
||||
'pancho',
|
||||
'combo-2-panchos-2-hamburguesas',
|
||||
],
|
||||
],
|
||||
'Bebidas' => [
|
||||
'product_layout' => ProductLayout::ColumnWithCart,
|
||||
'group_layout' => GroupLayout::Simple,
|
||||
'slugs' => [
|
||||
'coca-cola-500ml',
|
||||
'agua-mineral-1l',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$catalogItems = CatalogItem::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->whereIn('slug', collect($groups)->pluck('slugs')->flatten()->all())
|
||||
->get()
|
||||
->keyBy('slug');
|
||||
|
||||
$groupOrder = 0;
|
||||
foreach ($groups as $groupName => $config) {
|
||||
$featuredGroup = FeaturedGroup::query()->create([
|
||||
FeaturedGroup::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'source_type' => FeaturedGroupSource::Category,
|
||||
'category_id' => $categories[$groupName]->id,
|
||||
'product_layout' => $config['product_layout'],
|
||||
'group_layout' => $config['group_layout'],
|
||||
'group_name' => $groupName,
|
||||
'group_order' => $groupOrder++,
|
||||
]);
|
||||
|
||||
$featuredGroup->featuredItems()->createMany(
|
||||
collect($config['slugs'])->values()->map(
|
||||
fn (string $slug, int $order): array => [
|
||||
'catalog_item_id' => $catalogItems->get($slug)->id,
|
||||
'order' => $order,
|
||||
]
|
||||
)->all()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Domains\Catalog\Enums\FeaturedGroupSource;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
@@ -168,30 +169,18 @@ class ProductCatalogFromImagesSeeder extends Seeder
|
||||
{
|
||||
FeaturedGroup::query()->where('tenant_code', $tenant->codigo)->delete();
|
||||
|
||||
$paginatedGroup = FeaturedGroup::query()->create([
|
||||
FeaturedGroup::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'source_type' => FeaturedGroupSource::All,
|
||||
'product_layout' => ProductLayout::ColumnWithImage,
|
||||
'group_layout' => GroupLayout::Paginated,
|
||||
'group_name' => 'Productos',
|
||||
'group_order' => 2,
|
||||
]);
|
||||
|
||||
$items = CatalogItem::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->orderBy('id')
|
||||
->get('id');
|
||||
|
||||
$paginatedGroup->featuredItems()->createMany(
|
||||
$items->values()->map(
|
||||
fn (CatalogItem $item, int $order): array => [
|
||||
'catalog_item_id' => $item->id,
|
||||
'order' => $order,
|
||||
]
|
||||
)->all()
|
||||
);
|
||||
|
||||
$carouselGroup = FeaturedGroup::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'source_type' => FeaturedGroupSource::Manual,
|
||||
'product_layout' => ProductLayout::ColumnWithImage,
|
||||
'group_layout' => GroupLayout::Carousel,
|
||||
'group_name' => 'Productos destacados',
|
||||
|
||||
@@ -2,10 +2,16 @@
|
||||
Recuperá tu contraseña
|
||||
</h1>
|
||||
|
||||
@if($attempt->reason === 'account_locked')
|
||||
<p>
|
||||
Hola {{ $attempt->user->nombre_apellido }}, registramos varios intentos fallidos de inicio de sesión en tu cuenta. Por seguridad, hemos bloqueado el acceso temporalmente. Puedes utilizar este código para cambiar tu contraseña y desbloquearla inmediatamente.
|
||||
</p>
|
||||
@else
|
||||
<p>
|
||||
Hola {{ $attempt->user->nombre_apellido }}, recibimos una solicitud para restablecer
|
||||
la contraseña de tu cuenta.
|
||||
</p>
|
||||
@endif
|
||||
|
||||
<p>Ingresá este código en {{ $tenant->nombre }}:</p>
|
||||
|
||||
@@ -15,6 +21,21 @@
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@php
|
||||
$recoveryUrl = 'https://' . $tenant->dominio . '/recuperar-contrasena/codigo?email=' . urlencode($attempt->user->email);
|
||||
@endphp
|
||||
|
||||
<div style="text-align: center; margin-bottom: 28px;">
|
||||
<a href="{{ $recoveryUrl }}"
|
||||
style="display: inline-block; padding: 12px 24px; background-color: {{ $tenant->primary_color }}; color: #ffffff; text-decoration: none; border-radius: 6px; font-weight: bold;">
|
||||
Ingresar código ahora
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<p style="color: #64748b; font-size: 14px;">
|
||||
@if($attempt->reason === 'account_locked')
|
||||
Si no fuiste vos, por favor desestimá y borrá este correo. Tu cuenta seguirá protegida.
|
||||
@else
|
||||
Si no solicitaste recuperar tu contraseña, podés ignorar este mensaje.
|
||||
@endif
|
||||
</p>
|
||||
|
||||
@@ -14,3 +14,4 @@ require __DIR__.'/../app/Domains/Ticket/routes/api.php';
|
||||
require __DIR__.'/../app/Domains/Event/routes/api.php';
|
||||
require __DIR__.'/../app/Domains/Bootstrap/routes/api.php';
|
||||
require __DIR__.'/../app/Domains/Forms/routes/api.php';
|
||||
require __DIR__.'/../app/Domains/Staff/routes/api.php';
|
||||
|
||||
@@ -4,9 +4,11 @@ namespace Tests\Feature\Catalog;
|
||||
|
||||
use App\Domains\Attachable\Enums\AttachmentType;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Enums\FeaturedGroupSource;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
use App\Domains\Catalog\Models\Inventory;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
@@ -198,6 +200,46 @@ class CatalogControllerTest extends TestCase
|
||||
->assertJsonPath('0.nombre', 'carousel Item 1');
|
||||
}
|
||||
|
||||
public function test_groups_can_source_items_from_a_category_or_the_entire_catalog(): void
|
||||
{
|
||||
$tenant = $this->createTenant('catalog-sources');
|
||||
$category = Category::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'nombre' => 'Food',
|
||||
]);
|
||||
|
||||
FeaturedGroup::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'source_type' => FeaturedGroupSource::Category,
|
||||
'category_id' => $category->id,
|
||||
'product_layout' => ProductLayout::Row,
|
||||
'group_layout' => GroupLayout::Simple,
|
||||
'group_name' => 'Food',
|
||||
'group_order' => 0,
|
||||
]);
|
||||
FeaturedGroup::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'source_type' => FeaturedGroupSource::All,
|
||||
'product_layout' => ProductLayout::Row,
|
||||
'group_layout' => GroupLayout::Paginated,
|
||||
'group_name' => 'All products',
|
||||
'group_order' => 1,
|
||||
]);
|
||||
|
||||
$food = $this->createItem($tenant, 'Hamburger');
|
||||
$food->category()->associate($category)->save();
|
||||
$this->createItem($tenant, 'Parking');
|
||||
|
||||
$this->getJson("/api/tenants/{$tenant->codigo}/catalog")
|
||||
->assertOk()
|
||||
->assertJsonPath('0.title', 'Food')
|
||||
->assertJsonCount(1, '0.items')
|
||||
->assertJsonPath('0.items.0.nombre', 'Hamburger')
|
||||
->assertJsonPath('1.title', 'All products')
|
||||
->assertJsonCount(2, '1.items.data')
|
||||
->assertJsonPath('1.items.meta.total', 2);
|
||||
}
|
||||
|
||||
private function createGroup(
|
||||
Tenant $tenant,
|
||||
ProductLayout $layout,
|
||||
|
||||
@@ -79,6 +79,8 @@ class CatalogSchemaTest extends TestCase
|
||||
$this->assertEqualsCanonicalizing([
|
||||
'id',
|
||||
'tenant_code',
|
||||
'source_type',
|
||||
'category_id',
|
||||
'product_layout',
|
||||
'group_layout',
|
||||
'group_name',
|
||||
|
||||
262
tests/Feature/Catalog/OnTicketFeaturedGroupControllerTest.php
Normal file
262
tests/Feature/Catalog/OnTicketFeaturedGroupControllerTest.php
Normal file
@@ -0,0 +1,262 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Catalog;
|
||||
|
||||
use App\Domains\Auth\Models\User;
|
||||
use App\Domains\Authorization\Enums\RoleCode;
|
||||
use App\Domains\Catalog\Enums\FeaturedGroupSource;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Tenant\Models\WebsiteType;
|
||||
use Database\Seeders\AuthorizationSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class OnTicketFeaturedGroupControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->seed(AuthorizationSeeder::class);
|
||||
WebsiteType::query()->create([
|
||||
'codigo' => 'onticket',
|
||||
'nombre' => 'OnTicket',
|
||||
]);
|
||||
WebsiteType::query()->create([
|
||||
'codigo' => 'shopit',
|
||||
'nombre' => 'Shopit',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_authentication_is_required(): void
|
||||
{
|
||||
$this->getJson('/api/v1/adminapp/tenant/featured-groups')->assertUnauthorized();
|
||||
$this->postJson('/api/v1/adminapp/tenant/featured-groups', $this->payload())
|
||||
->assertUnauthorized();
|
||||
$this->putJson('/api/v1/adminapp/tenant/featured-groups/1', $this->payload())
|
||||
->assertUnauthorized();
|
||||
}
|
||||
|
||||
public function test_index_returns_only_category_groups_for_the_onticket_tenant(): void
|
||||
{
|
||||
$tenant = $this->createTenant('acme');
|
||||
$otherTenant = $this->createTenant('other');
|
||||
$first = $this->createCategoryGroup($tenant, 'Food', order: 2);
|
||||
$second = $this->createCategoryGroup($tenant, 'Tickets', order: 1);
|
||||
$this->createCategoryGroup($otherTenant, 'Other tenant');
|
||||
FeaturedGroup::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'source_type' => FeaturedGroupSource::All,
|
||||
'product_layout' => ProductLayout::Row,
|
||||
'group_layout' => GroupLayout::Paginated,
|
||||
'group_name' => 'All products',
|
||||
'group_order' => 0,
|
||||
]);
|
||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/featured-groups')
|
||||
->assertOk()
|
||||
->assertJsonCount(2, 'data')
|
||||
->assertJsonPath('data.0.id', $second->id)
|
||||
->assertJsonPath('data.0.category_name', 'Tickets')
|
||||
->assertJsonPath('data.1.id', $first->id)
|
||||
->assertJsonMissing(['category_name' => 'Other tenant'])
|
||||
->assertJsonMissing(['group_name' => 'All products']);
|
||||
}
|
||||
|
||||
public function test_store_creates_a_category_and_a_featured_horizontal_group(): void
|
||||
{
|
||||
$tenant = $this->createTenant('acme');
|
||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||
|
||||
$response = $this->postJson('/api/v1/adminapp/tenant/featured-groups', [
|
||||
'category_name' => 'Food',
|
||||
'is_featured' => true,
|
||||
])
|
||||
->assertCreated()
|
||||
->assertJsonPath('data.category_name', 'Food')
|
||||
->assertJsonPath('data.group_name', 'Food')
|
||||
->assertJsonPath('data.is_featured', true)
|
||||
->assertJsonPath('data.type', 'category')
|
||||
->assertJsonPath('data.product_layout', 'row')
|
||||
->assertJsonPath('data.group_layout', 'paginated');
|
||||
|
||||
$categoryId = $response->json('data.category_id');
|
||||
$this->assertDatabaseHas('categorias', [
|
||||
'id' => $categoryId,
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'nombre' => 'Food',
|
||||
]);
|
||||
$this->assertDatabaseHas('featured_groups', [
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'source_type' => 'category',
|
||||
'category_id' => $categoryId,
|
||||
'product_layout' => 'row',
|
||||
'group_layout' => 'paginated',
|
||||
'group_name' => 'Food',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_store_uses_column_with_cart_when_the_category_is_not_featured(): void
|
||||
{
|
||||
$tenant = $this->createTenant('acme');
|
||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||
|
||||
$this->postJson('/api/v1/adminapp/tenant/featured-groups', [
|
||||
'category_name' => 'Parking',
|
||||
'is_featured' => false,
|
||||
])
|
||||
->assertCreated()
|
||||
->assertJsonPath('data.is_featured', false)
|
||||
->assertJsonPath('data.product_layout', 'column_with_cart')
|
||||
->assertJsonPath('data.group_layout', 'paginated');
|
||||
}
|
||||
|
||||
public function test_update_changes_the_category_and_group_together(): void
|
||||
{
|
||||
$tenant = $this->createTenant('acme');
|
||||
$group = $this->createCategoryGroup($tenant, 'Old name', ProductLayout::ColumnWithCart);
|
||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||
|
||||
$this->putJson("/api/v1/adminapp/tenant/featured-groups/{$group->id}", [
|
||||
'category_name' => 'New name',
|
||||
'is_featured' => true,
|
||||
])
|
||||
->assertOk()
|
||||
->assertJsonPath('data.category_name', 'New name')
|
||||
->assertJsonPath('data.group_name', 'New name')
|
||||
->assertJsonPath('data.is_featured', true)
|
||||
->assertJsonPath('data.product_layout', 'row')
|
||||
->assertJsonPath('data.group_layout', 'paginated');
|
||||
|
||||
$this->assertDatabaseHas('categorias', [
|
||||
'id' => $group->category_id,
|
||||
'nombre' => 'New name',
|
||||
]);
|
||||
$this->assertDatabaseHas('featured_groups', [
|
||||
'id' => $group->id,
|
||||
'group_name' => 'New name',
|
||||
'product_layout' => 'row',
|
||||
'group_layout' => 'paginated',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_rejects_groups_from_another_tenant_or_source(): void
|
||||
{
|
||||
$tenant = $this->createTenant('acme');
|
||||
$otherTenant = $this->createTenant('other');
|
||||
$otherGroup = $this->createCategoryGroup($otherTenant, 'Other');
|
||||
$allGroup = FeaturedGroup::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'source_type' => FeaturedGroupSource::All,
|
||||
'product_layout' => ProductLayout::Row,
|
||||
'group_layout' => GroupLayout::Paginated,
|
||||
'group_name' => 'All products',
|
||||
'group_order' => 0,
|
||||
]);
|
||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||
|
||||
$this->putJson(
|
||||
"/api/v1/adminapp/tenant/featured-groups/{$otherGroup->id}",
|
||||
$this->payload(),
|
||||
)->assertNotFound();
|
||||
$this->putJson(
|
||||
"/api/v1/adminapp/tenant/featured-groups/{$allGroup->id}",
|
||||
$this->payload(),
|
||||
)->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_name_and_featured_flag_are_required(): void
|
||||
{
|
||||
$tenant = $this->createTenant('acme');
|
||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||
|
||||
$this->postJson('/api/v1/adminapp/tenant/featured-groups', [
|
||||
'category_name' => '',
|
||||
'is_featured' => 'yes',
|
||||
])
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors(['category_name', 'is_featured']);
|
||||
|
||||
$this->assertDatabaseCount('categorias', 0);
|
||||
$this->assertDatabaseCount('featured_groups', 0);
|
||||
}
|
||||
|
||||
public function test_the_controller_is_not_available_for_non_onticket_tenants(): void
|
||||
{
|
||||
$tenant = $this->createTenant('store', 'shopit');
|
||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/featured-groups')->assertNotFound();
|
||||
$this->postJson('/api/v1/adminapp/tenant/featured-groups', $this->payload())
|
||||
->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_a_customer_cannot_manage_onticket_featured_groups(): void
|
||||
{
|
||||
Sanctum::actingAs(User::factory()->create([
|
||||
'rol_codigo' => RoleCode::User->value,
|
||||
'tenant_codigo' => null,
|
||||
]));
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/featured-groups')->assertForbidden();
|
||||
$this->postJson('/api/v1/adminapp/tenant/featured-groups', $this->payload())
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
/** @return array{category_name: string, is_featured: bool} */
|
||||
private function payload(): array
|
||||
{
|
||||
return [
|
||||
'category_name' => 'Food',
|
||||
'is_featured' => true,
|
||||
];
|
||||
}
|
||||
|
||||
private function createTenant(string $code, string $websiteType = 'onticket'): Tenant
|
||||
{
|
||||
return Tenant::query()->create([
|
||||
'codigo' => $code,
|
||||
'nombre' => ucfirst($code),
|
||||
'dominio' => "{$code}.test",
|
||||
'website_type_code' => $websiteType,
|
||||
]);
|
||||
}
|
||||
|
||||
private function createAdminAppUser(Tenant $tenant): User
|
||||
{
|
||||
return User::factory()->create([
|
||||
'rol_codigo' => RoleCode::AdminApp->value,
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
]);
|
||||
}
|
||||
|
||||
private function createCategoryGroup(
|
||||
Tenant $tenant,
|
||||
string $name,
|
||||
ProductLayout $productLayout = ProductLayout::Row,
|
||||
int $order = 0,
|
||||
): FeaturedGroup {
|
||||
$category = Category::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'nombre' => $name,
|
||||
]);
|
||||
|
||||
return FeaturedGroup::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'source_type' => FeaturedGroupSource::Category,
|
||||
'category_id' => $category->id,
|
||||
'product_layout' => $productLayout,
|
||||
'group_layout' => GroupLayout::Paginated,
|
||||
'group_name' => $name,
|
||||
'group_order' => $order,
|
||||
]);
|
||||
}
|
||||
}
|
||||
84
tests/Feature/Forms/AdminAppStaffFormControllerTest.php
Normal file
84
tests/Feature/Forms/AdminAppStaffFormControllerTest.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Forms;
|
||||
|
||||
use App\Domains\Auth\Models\User;
|
||||
use App\Domains\Authorization\Enums\RoleCode;
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Tenant\Models\WebsiteType;
|
||||
use Database\Seeders\AuthorizationSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminAppStaffFormControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->seed(AuthorizationSeeder::class);
|
||||
WebsiteType::query()->create([
|
||||
'codigo' => 'onticket',
|
||||
'nombre' => 'OnTicket',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_authentication_is_required(): void
|
||||
{
|
||||
$this->getJson('/api/v1/adminapp/forms/staff')->assertUnauthorized();
|
||||
}
|
||||
|
||||
public function test_adminapp_user_gets_only_its_tenant_categories(): void
|
||||
{
|
||||
$tenant = $this->createTenant('acme');
|
||||
$otherTenant = $this->createTenant('other');
|
||||
$category = Category::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'nombre' => 'Bebidas',
|
||||
]);
|
||||
Category::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'categoria_id' => $category->id,
|
||||
'nombre' => 'Gaseosas',
|
||||
]);
|
||||
Category::query()->create([
|
||||
'tenant_code' => $otherTenant->codigo,
|
||||
'nombre' => 'Privada',
|
||||
]);
|
||||
Sanctum::actingAs(User::factory()->create([
|
||||
'rol_codigo' => RoleCode::AdminApp->value,
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
]));
|
||||
|
||||
$this->getJson('/api/v1/adminapp/forms/staff')
|
||||
->assertOk()
|
||||
->assertJsonCount(1, 'data.categories')
|
||||
->assertJsonPath('data.categories.0.id', $category->id)
|
||||
->assertJsonPath('data.categories.0.nombre', 'Bebidas')
|
||||
->assertJsonMissingPath('data.categories.0.categoria_id')
|
||||
->assertJsonMissingPath('data.roles');
|
||||
}
|
||||
|
||||
public function test_customer_cannot_get_staff_form(): void
|
||||
{
|
||||
Sanctum::actingAs(User::factory()->create([
|
||||
'rol_codigo' => RoleCode::User->value,
|
||||
]));
|
||||
|
||||
$this->getJson('/api/v1/adminapp/forms/staff')->assertForbidden();
|
||||
}
|
||||
|
||||
private function createTenant(string $code): Tenant
|
||||
{
|
||||
return Tenant::query()->create([
|
||||
'codigo' => $code,
|
||||
'nombre' => ucfirst($code),
|
||||
'dominio' => "{$code}.test",
|
||||
'website_type_code' => 'onticket',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use App\Domains\Attachable\Enums\AttachmentType;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use App\Domains\Catalog\Enums\FeaturedGroupSource;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Catalog\Models\Attribute;
|
||||
@@ -174,7 +175,7 @@ class FiestaFutbolInfantilProductSeederTest extends TestCase
|
||||
$this->assertSame(9, CatalogItem::query()->where('tenant_code', $tenant->codigo)->count());
|
||||
$this->assertSame(10, Inventory::query()->count());
|
||||
$this->assertSame(
|
||||
['Entradas', 'Estacionamiento', 'Gastronomía'],
|
||||
['Bebidas', 'Comidas', 'Entradas', 'Estacionamiento', 'Gastronomía'],
|
||||
Category::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->orderBy('nombre')
|
||||
@@ -194,7 +195,7 @@ class FiestaFutbolInfantilProductSeederTest extends TestCase
|
||||
|
||||
$featuredGroups = FeaturedGroup::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->with('featuredItems.catalogItem')
|
||||
->with('category.catalogItems')
|
||||
->orderBy('group_order')
|
||||
->get();
|
||||
|
||||
@@ -207,21 +208,23 @@ class FiestaFutbolInfantilProductSeederTest extends TestCase
|
||||
],
|
||||
$featuredGroups
|
||||
->mapWithKeys(fn (FeaturedGroup $group): array => [
|
||||
$group->group_name => $group->featuredItems->pluck('catalogItem.slug')->all(),
|
||||
$group->group_name => $group->category->catalogItems->pluck('slug')->all(),
|
||||
])
|
||||
->all()
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
[
|
||||
['Entradas', ProductLayout::Row, GroupLayout::SimpleVertical, 0],
|
||||
['Estacionamiento', ProductLayout::ColumnWithCart, GroupLayout::Simple, 1],
|
||||
['Comidas', ProductLayout::ColumnWithCart, GroupLayout::Simple, 2],
|
||||
['Bebidas', ProductLayout::ColumnWithCart, GroupLayout::Simple, 3],
|
||||
['Entradas', FeaturedGroupSource::Category, 'Entradas', ProductLayout::Row, GroupLayout::SimpleVertical, 0],
|
||||
['Estacionamiento', FeaturedGroupSource::Category, 'Estacionamiento', ProductLayout::ColumnWithCart, GroupLayout::Simple, 1],
|
||||
['Comidas', FeaturedGroupSource::Category, 'Comidas', ProductLayout::ColumnWithCart, GroupLayout::Simple, 2],
|
||||
['Bebidas', FeaturedGroupSource::Category, 'Bebidas', ProductLayout::ColumnWithCart, GroupLayout::Simple, 3],
|
||||
],
|
||||
$featuredGroups
|
||||
->map(fn (FeaturedGroup $group): array => [
|
||||
$group->group_name,
|
||||
$group->source_type,
|
||||
$group->category->nombre,
|
||||
$group->product_layout,
|
||||
$group->group_layout,
|
||||
$group->group_order,
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Tests\Feature\Seeders;
|
||||
|
||||
use App\Domains\Attachable\Enums\AttachmentType;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Enums\FeaturedGroupSource;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
@@ -70,16 +71,14 @@ class ProductCatalogFromImagesSeederTest extends TestCase
|
||||
$this->assertNotNull($paginatedGroup);
|
||||
$this->assertSame(ProductLayout::ColumnWithImage, $paginatedGroup->product_layout);
|
||||
$this->assertSame(GroupLayout::Paginated, $paginatedGroup->group_layout);
|
||||
$this->assertSame(0, $paginatedGroup->group_order);
|
||||
$this->assertSame(
|
||||
CatalogItem::query()->where('tenant_code', $tenant->codigo)->orderBy('id')->pluck('slug')->all(),
|
||||
$paginatedGroup->featuredItems->pluck('catalogItem.slug')->all(),
|
||||
);
|
||||
$this->assertCount(10, $paginatedGroup->featuredItems);
|
||||
$this->assertSame(FeaturedGroupSource::All, $paginatedGroup->source_type);
|
||||
$this->assertSame(2, $paginatedGroup->group_order);
|
||||
$this->assertCount(0, $paginatedGroup->featuredItems);
|
||||
|
||||
$this->assertNotNull($carouselGroup);
|
||||
$this->assertSame(ProductLayout::ColumnWithImage, $carouselGroup->product_layout);
|
||||
$this->assertSame(GroupLayout::Carousel, $carouselGroup->group_layout);
|
||||
$this->assertSame(FeaturedGroupSource::Manual, $carouselGroup->source_type);
|
||||
$this->assertSame(1, $carouselGroup->group_order);
|
||||
$this->assertCount(5, $carouselGroup->featuredItems);
|
||||
$this->assertCount(
|
||||
|
||||
138
tests/Feature/Staff/StaffControllerTest.php
Normal file
138
tests/Feature/Staff/StaffControllerTest.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Staff;
|
||||
|
||||
use App\Domains\Auth\Models\User;
|
||||
use App\Domains\Authorization\Enums\RoleCode;
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Tenant\Models\WebsiteType;
|
||||
use Database\Seeders\AuthorizationSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class StaffControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Tenant $tenant;
|
||||
|
||||
private User $admin;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->seed(AuthorizationSeeder::class);
|
||||
WebsiteType::query()->create(['codigo' => 'onticket', 'nombre' => 'OnTicket']);
|
||||
$this->tenant = Tenant::query()->create([
|
||||
'codigo' => 'acme',
|
||||
'nombre' => 'Acme',
|
||||
'dominio' => 'acme.test',
|
||||
'website_type_code' => 'onticket',
|
||||
]);
|
||||
$this->admin = User::factory()->create([
|
||||
'rol_codigo' => RoleCode::AdminApp->value,
|
||||
'tenant_codigo' => $this->tenant->codigo,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_adminapp_can_create_update_list_and_delete_staff_with_categories(): void
|
||||
{
|
||||
Sanctum::actingAs($this->admin);
|
||||
$firstCategory = $this->createCategory('Bebidas');
|
||||
$secondCategory = $this->createCategory('Comidas');
|
||||
|
||||
$response = $this->postJson('/api/v1/adminapp/tenant/staff', [
|
||||
'nombre_apellido' => 'Ada Lovelace',
|
||||
'dni' => '12345678',
|
||||
'email' => 'ADA@example.test',
|
||||
'category_ids' => [$firstCategory->id],
|
||||
])->assertSuccessful()
|
||||
->assertJsonPath('data.email', 'ada@example.test')
|
||||
->assertJsonPath('data.role.codigo', RoleCode::Scanner->value)
|
||||
->assertJsonPath('data.categories.0.id', $firstCategory->id);
|
||||
|
||||
$staffId = $response->json('data.id');
|
||||
$this->assertDatabaseHas('category_scanners', [
|
||||
'user_id' => $staffId,
|
||||
'categoria_id' => $firstCategory->id,
|
||||
]);
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/staff?search=ada')
|
||||
->assertOk()
|
||||
->assertJsonCount(1, 'data');
|
||||
|
||||
$this->putJson("/api/v1/adminapp/tenant/staff/{$staffId}", [
|
||||
'nombre_apellido' => 'Ada Byron',
|
||||
'dni' => '12345678',
|
||||
'email' => 'ada@example.test',
|
||||
'category_ids' => [$secondCategory->id],
|
||||
])->assertOk()
|
||||
->assertJsonPath('data.nombre_apellido', 'Ada Byron')
|
||||
->assertJsonPath('data.categories.0.id', $secondCategory->id);
|
||||
|
||||
$this->assertDatabaseMissing('category_scanners', [
|
||||
'user_id' => $staffId,
|
||||
'categoria_id' => $firstCategory->id,
|
||||
]);
|
||||
|
||||
$this->deleteJson("/api/v1/adminapp/tenant/staff/{$staffId}")->assertNoContent();
|
||||
$this->assertDatabaseMissing('users', ['id' => $staffId]);
|
||||
}
|
||||
|
||||
public function test_admin_cannot_assign_another_tenants_category(): void
|
||||
{
|
||||
Sanctum::actingAs($this->admin);
|
||||
$otherTenant = Tenant::query()->create([
|
||||
'codigo' => 'other',
|
||||
'nombre' => 'Other',
|
||||
'dominio' => 'other.test',
|
||||
'website_type_code' => 'onticket',
|
||||
]);
|
||||
$foreignCategory = Category::query()->create([
|
||||
'tenant_code' => $otherTenant->codigo,
|
||||
'nombre' => 'Privada',
|
||||
]);
|
||||
$payload = [
|
||||
'nombre_apellido' => 'Grace Hopper',
|
||||
'dni' => '87654321',
|
||||
'email' => 'grace@example.test',
|
||||
'category_ids' => [$foreignCategory->id],
|
||||
];
|
||||
|
||||
$this->postJson('/api/v1/adminapp/tenant/staff', $payload)
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors('category_ids');
|
||||
|
||||
$parent = $this->createCategory('Local');
|
||||
$child = Category::query()->create([
|
||||
'tenant_code' => $this->tenant->codigo,
|
||||
'categoria_id' => $parent->id,
|
||||
'nombre' => 'Subcategoría',
|
||||
]);
|
||||
$payload['category_ids'] = [$child->id];
|
||||
|
||||
$this->postJson('/api/v1/adminapp/tenant/staff', $payload)
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors('category_ids');
|
||||
}
|
||||
|
||||
public function test_customer_cannot_manage_staff(): void
|
||||
{
|
||||
Sanctum::actingAs(User::factory()->create([
|
||||
'rol_codigo' => RoleCode::User->value,
|
||||
]));
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/staff')->assertForbidden();
|
||||
}
|
||||
|
||||
private function createCategory(string $name): Category
|
||||
{
|
||||
return Category::query()->create([
|
||||
'tenant_code' => $this->tenant->codigo,
|
||||
'nombre' => $name,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace Tests\Unit\Catalog;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use App\Domains\Catalog\Enums\FeaturedGroupSource;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
@@ -104,6 +105,8 @@ class CatalogModelsTest extends TestCase
|
||||
{
|
||||
$group = new FeaturedGroup;
|
||||
$group->setRawAttributes([
|
||||
'source_type' => FeaturedGroupSource::Category->value,
|
||||
'category_id' => '4',
|
||||
'product_layout' => ProductLayout::ColumnWithImage->value,
|
||||
'group_layout' => GroupLayout::SimpleVertical->value,
|
||||
'group_order' => '2',
|
||||
@@ -118,9 +121,12 @@ class CatalogModelsTest extends TestCase
|
||||
$this->assertSame('featured_groups', $group->getTable());
|
||||
$this->assertFalse($group->usesTimestamps());
|
||||
$this->assertSame(ProductLayout::ColumnWithImage, $group->product_layout);
|
||||
$this->assertSame(FeaturedGroupSource::Category, $group->source_type);
|
||||
$this->assertSame(4, $group->category_id);
|
||||
$this->assertSame(GroupLayout::SimpleVertical, $group->group_layout);
|
||||
$this->assertSame(2, $group->group_order);
|
||||
$this->assertInstanceOf(Tenant::class, $group->tenant()->getRelated());
|
||||
$this->assertInstanceOf(Category::class, $group->category()->getRelated());
|
||||
$this->assertInstanceOf(FeaturedItem::class, $group->featuredItems()->getRelated());
|
||||
|
||||
$this->assertSame('featured_items', $featuredItem->getTable());
|
||||
@@ -189,7 +195,7 @@ class CatalogModelsTest extends TestCase
|
||||
$variant->setRelation('eventDate', $eventDate);
|
||||
$variant->setRelation('definitions', new EloquentCollection);
|
||||
|
||||
$this->assertSame('Entrada General (Fecha: 2026-10-09)', $variant->getName());
|
||||
$this->assertSame('Entrada General', $variant->getName());
|
||||
$this->assertSame('2026-10-09 09:00:00', $variant->getMinimumUseDate()->format('Y-m-d H:i:s'));
|
||||
$this->assertSame('2026-10-09 18:00:00', $variant->getMaximumUseDate()->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ class TicketTest extends TestCase
|
||||
'starts_at' => '2026-07-21 10:00:00',
|
||||
'expires_at' => '2026-07-22 10:00:00',
|
||||
'used_at' => null,
|
||||
'scanner_user_id' => '15',
|
||||
'user_id' => '10',
|
||||
]);
|
||||
|
||||
@@ -39,9 +40,11 @@ class TicketTest extends TestCase
|
||||
$this->assertInstanceOf(Carbon::class, $ticket->starts_at);
|
||||
$this->assertInstanceOf(Carbon::class, $ticket->expires_at);
|
||||
$this->assertNull($ticket->used_at);
|
||||
$this->assertSame(15, $ticket->scanner_user_id);
|
||||
$this->assertSame(10, $ticket->user_id);
|
||||
$this->assertInstanceOf(Tenant::class, $ticket->tenant()->getRelated());
|
||||
$this->assertInstanceOf(User::class, $ticket->user()->getRelated());
|
||||
$this->assertInstanceOf(User::class, $ticket->scannerUser()->getRelated());
|
||||
$this->assertInstanceOf(CatalogItem::class, $ticket->sourceCatalogItem()->getRelated());
|
||||
$this->assertInstanceOf(Variant::class, $ticket->sourceVariant()->getRelated());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user