diff --git a/package.json b/package.json index e62254d4..fbb72df3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "elo", - "version": "1.46.0", + "version": "1.47.0", "private": true, "type": "module", "scripts": { diff --git a/prisma/migrations/20260617120000_vehicle_filial_fk/migration.sql b/prisma/migrations/20260617120000_vehicle_filial_fk/migration.sql new file mode 100644 index 00000000..80995891 --- /dev/null +++ b/prisma/migrations/20260617120000_vehicle_filial_fk/migration.sql @@ -0,0 +1,8 @@ +-- AlterTable +ALTER TABLE "vehicles" ADD COLUMN "filialId" TEXT; + +-- CreateIndex +CREATE INDEX "vehicles_filialId_idx" ON "vehicles"("filialId"); + +-- AddForeignKey +ALTER TABLE "vehicles" ADD CONSTRAINT "vehicles_filialId_fkey" FOREIGN KEY ("filialId") REFERENCES "filiais"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index ed641af2..3064efb1 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -256,11 +256,16 @@ model Vehicle { model String plate String @unique imageUrl String + // Enum legado mantido em sincronia com `filial.empresa.enterprise` para + // compatibilidade com relatórios/exibições antigas. A fonte da verdade é a filial. enterprise Enterprise + filialId String? + filial Filial? @relation(fields: [filialId], references: [id], onDelete: SetNull) kilometers BigInt availble Boolean @default(true) rents VehicleRent[] + @@index([filialId]) @@map("vehicles") } @@ -619,6 +624,7 @@ model Filial { empresa Empresa @relation(fields: [empresaId], references: [id], onDelete: Restrict) users User[] restaurants Restaurant[] + vehicles Vehicle[] createdAt DateTime @default(now()) updatedAt DateTime @updatedAt diff --git a/src/app/(authenticated)/admin/vehicles/page.tsx b/src/app/(authenticated)/admin/vehicles/page.tsx index de10182e..b2c148c2 100644 --- a/src/app/(authenticated)/admin/vehicles/page.tsx +++ b/src/app/(authenticated)/admin/vehicles/page.tsx @@ -50,11 +50,17 @@ export default function VehiclesAdminClient() { } } - const filteredVehicles = vehicles?.items?.filter(vehicle => - vehicle.model.toLowerCase().includes(searchTerm.toLowerCase()) || - vehicle.plate.toLowerCase().includes(searchTerm.toLowerCase()) || - vehicle.enterprise.toLowerCase().includes(searchTerm.toLowerCase()) - ) ?? [] + const filteredVehicles = vehicles?.items?.filter(vehicle => { + const term = searchTerm.toLowerCase() + return ( + vehicle.model.toLowerCase().includes(term) || + vehicle.plate.toLowerCase().includes(term) || + vehicle.enterprise.toLowerCase().includes(term) || + (vehicle.filial?.name.toLowerCase().includes(term) ?? false) || + (vehicle.filial?.code.toLowerCase().includes(term) ?? false) || + (vehicle.filial?.empresa.name.toLowerCase().includes(term) ?? false) + ) + }) ?? [] if (isLoading) { return ( @@ -110,9 +116,9 @@ export default function VehiclesAdminClient() { onSuccess={() => { setIsCreateDialogOpen(false) void refetch() - } } onCancel={function (): void { - throw new Error("Function not implemented.") - } } /> + }} + onCancel={() => setIsCreateDialogOpen(false)} + /> @@ -199,7 +205,11 @@ export default function VehiclesAdminClient() {
Carregando veículos disponíveis...