chore(types): remove explicit any, fix hook deps, and unused vars across admin/api/tickets; tighten zod server schemas; adjust UI types; fix pdf export expression; minor cleanup

This commit is contained in:
Esdras Renan 2025-10-09 22:43:39 -03:00
parent 0556502685
commit 6ffd6c6392
17 changed files with 104 additions and 59 deletions

View file

@ -1,6 +1,7 @@
import { NextResponse } from "next/server"
import { prisma } from "@/lib/prisma"
import type { Prisma } from "@prisma/client"
import { assertAdminSession } from "@/lib/auth-server"
export const runtime = "nodejs"
@ -9,20 +10,34 @@ export async function PATCH(request: Request, { params }: { params: Promise<{ id
const session = await assertAdminSession()
if (!session) return NextResponse.json({ error: "Não autorizado" }, { status: 401 })
const { id } = await params
const body = await request.json()
const raw = (await request.json()) as Partial<{
name: string
slug: string
cnpj: string | null
domain: string | null
phone: string | null
description: string | null
address: string | null
isAvulso: boolean
contractedHoursPerMonth: number | string | null
}>
const updates: Record<string, any> = {}
for (const key of ["name", "slug", "cnpj", "domain", "phone", "description", "address"]) {
if (key in body) updates[key] = body[key] ?? null
}
if ("isAvulso" in body) updates.isAvulso = Boolean(body.isAvulso)
if ("contractedHoursPerMonth" in body) {
const raw = body.contractedHoursPerMonth
updates.contractedHoursPerMonth = typeof raw === "number" ? raw : raw ? Number(raw) : null
const updates: Prisma.CompanyUpdateInput = {}
if (typeof raw.name === "string" && raw.name.trim()) updates.name = raw.name.trim()
if (typeof raw.slug === "string" && raw.slug.trim()) updates.slug = raw.slug.trim()
if ("cnpj" in raw) updates.cnpj = raw.cnpj ?? null
if ("domain" in raw) updates.domain = raw.domain ?? null
if ("phone" in raw) updates.phone = raw.phone ?? null
if ("description" in raw) updates.description = raw.description ?? null
if ("address" in raw) updates.address = raw.address ?? null
if ("isAvulso" in raw) updates.isAvulso = Boolean(raw.isAvulso)
if ("contractedHoursPerMonth" in raw) {
const v = raw.contractedHoursPerMonth
updates.contractedHoursPerMonth = typeof v === "number" ? v : v ? Number(v) : null
}
try {
const company = await prisma.company.update({ where: { id }, data: updates as any })
const company = await prisma.company.update({ where: { id }, data: updates })
return NextResponse.json({ company })
} catch (error) {
console.error("Failed to update company", error)