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:
parent
0556502685
commit
6ffd6c6392
17 changed files with 104 additions and 59 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,17 @@ export async function POST(request: Request) {
|
|||
const session = await assertAdminSession()
|
||||
if (!session) return NextResponse.json({ error: "Não autorizado" }, { status: 401 })
|
||||
|
||||
const body = await request.json()
|
||||
const body = (await request.json()) as Partial<{
|
||||
name: string
|
||||
slug: string
|
||||
isAvulso: boolean
|
||||
cnpj: string | null
|
||||
domain: string | null
|
||||
phone: string | null
|
||||
description: string | null
|
||||
address: string | null
|
||||
contractedHoursPerMonth: number | string | null
|
||||
}>
|
||||
const { name, slug, isAvulso, cnpj, domain, phone, description, address, contractedHoursPerMonth } = body ?? {}
|
||||
if (!name || !slug) {
|
||||
return NextResponse.json({ error: "Nome e slug são obrigatórios" }, { status: 400 })
|
||||
|
|
@ -27,7 +37,7 @@ export async function POST(request: Request) {
|
|||
|
||||
try {
|
||||
const company = await prisma.company.create({
|
||||
data: ({
|
||||
data: {
|
||||
tenantId: session.user.tenantId ?? "tenant-atlas",
|
||||
name: String(name),
|
||||
slug: String(slug),
|
||||
|
|
@ -38,7 +48,7 @@ export async function POST(request: Request) {
|
|||
phone: phone ? String(phone) : null,
|
||||
description: description ? String(description) : null,
|
||||
address: address ? String(address) : null,
|
||||
} as any),
|
||||
},
|
||||
})
|
||||
return NextResponse.json({ company })
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { NextResponse } from "next/server"
|
|||
import { ConvexHttpClient } from "convex/browser"
|
||||
|
||||
import { assertAdminSession } from "@/lib/auth-server"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
|
||||
export const runtime = "nodejs"
|
||||
|
|
@ -10,7 +11,7 @@ export async function POST(request: Request) {
|
|||
const session = await assertAdminSession()
|
||||
if (!session) return NextResponse.json({ error: "Não autorizado" }, { status: 401 })
|
||||
|
||||
const body = await request.json().catch(() => null) as { email?: string; companyId?: string }
|
||||
const body = (await request.json().catch(() => null)) as { email?: string; companyId?: string }
|
||||
const email = body?.email?.trim().toLowerCase()
|
||||
const companyId = body?.companyId
|
||||
if (!email || !companyId) {
|
||||
|
|
@ -25,8 +26,8 @@ export async function POST(request: Request) {
|
|||
await client.mutation(api.users.assignCompany, {
|
||||
tenantId: session.user.tenantId ?? "tenant-atlas",
|
||||
email,
|
||||
companyId: companyId as any,
|
||||
actorId: (session.user as any).convexUserId ?? (session.user.id as any),
|
||||
companyId: companyId as Id<"companies">,
|
||||
actorId: (session.user as unknown as { convexUserId?: Id<"users">; id?: Id<"users"> }).convexUserId ?? (session.user.id as unknown as Id<"users">),
|
||||
})
|
||||
return NextResponse.json({ ok: true })
|
||||
} catch (error) {
|
||||
|
|
@ -34,4 +35,3 @@ export async function POST(request: Request) {
|
|||
return NextResponse.json({ error: "Falha ao vincular usuário" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ export async function GET(request: Request) {
|
|||
role: session.user.role.toUpperCase(),
|
||||
})
|
||||
viewerId = ensuredUser?._id ?? null
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
return NextResponse.json({ error: "Falha ao sincronizar usuário com Convex" }, { status: 500 })
|
||||
}
|
||||
if (!viewerId) return NextResponse.json({ error: "Usuário não encontrado no Convex" }, { status: 403 })
|
||||
|
|
@ -75,7 +75,7 @@ export async function GET(request: Request) {
|
|||
"Cache-Control": "no-store",
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
return NextResponse.json({ error: "Falha ao gerar CSV de horas por cliente" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -305,7 +305,11 @@ export async function GET(_request: Request, context: { params: Promise<{ id: st
|
|||
const badgeTextWidth = doc.widthOfString(statusText)
|
||||
const badgeHeight = badgeFontSize + badgePaddingY * 2
|
||||
const badgeWidth = badgeTextWidth + badgePaddingX * 2
|
||||
D.roundedRect?.(badgeX, badgeY, badgeWidth, badgeHeight, 4) ?? doc.rect(badgeX, badgeY, badgeWidth, badgeHeight)
|
||||
if (typeof D.roundedRect === "function") {
|
||||
D.roundedRect(badgeX, badgeY, badgeWidth, badgeHeight, 4)
|
||||
} else {
|
||||
doc.rect(badgeX, badgeY, badgeWidth, badgeHeight)
|
||||
}
|
||||
doc.fill(badgeColor)
|
||||
doc.fillColor("#FFFFFF").text(statusText, badgeX + badgePaddingX, badgeY + badgePaddingY)
|
||||
doc.restore()
|
||||
|
|
@ -316,7 +320,7 @@ export async function GET(_request: Request, context: { params: Promise<{ id: st
|
|||
const colGap = 24
|
||||
const colWidth = (doc.page.width - doc.page.margins.left - doc.page.margins.right - colGap) / 2
|
||||
const rightX = leftX + colWidth + colGap
|
||||
const startY = doc.y
|
||||
// const startY = doc.y
|
||||
const drawMeta = (x: number, lines: string[]) => {
|
||||
doc.save()
|
||||
doc.x = x
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue