feat: dispositivos e ajustes de csat e relatórios
This commit is contained in:
parent
25d2a9b062
commit
e0ef66555d
86 changed files with 5811 additions and 992 deletions
|
|
@ -6,6 +6,7 @@ import { env } from "@/lib/env"
|
|||
import { assertAuthenticatedSession } from "@/lib/auth-server"
|
||||
import { DEFAULT_TENANT_ID } from "@/lib/constants"
|
||||
import { buildMachinesInventoryWorkbook, type MachineInventoryRecord } from "@/server/machines/inventory-export"
|
||||
import type { DeviceInventoryColumnConfig } from "@/lib/device-inventory-columns"
|
||||
|
||||
export const runtime = "nodejs"
|
||||
|
||||
|
|
@ -22,6 +23,31 @@ export async function GET(request: Request) {
|
|||
const companyId = searchParams.get("companyId") ?? undefined
|
||||
const machineIdParams = searchParams.getAll("machineId").filter(Boolean)
|
||||
const machineIdFilter = machineIdParams.length > 0 ? new Set(machineIdParams) : null
|
||||
const columnsParam = searchParams.get("columns")
|
||||
let columnConfig: DeviceInventoryColumnConfig[] | undefined
|
||||
if (columnsParam) {
|
||||
try {
|
||||
const parsed = JSON.parse(columnsParam)
|
||||
if (Array.isArray(parsed)) {
|
||||
columnConfig = parsed
|
||||
.map((item) => {
|
||||
if (typeof item === "string") {
|
||||
return { key: item }
|
||||
}
|
||||
if (item && typeof item === "object" && typeof item.key === "string") {
|
||||
return {
|
||||
key: item.key,
|
||||
label: typeof item.label === "string" && item.label.length > 0 ? item.label : undefined,
|
||||
}
|
||||
}
|
||||
return null
|
||||
})
|
||||
.filter((item): item is DeviceInventoryColumnConfig => item !== null)
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("Invalid columns parameter for machines export", error)
|
||||
}
|
||||
}
|
||||
|
||||
const client = new ConvexHttpClient(convexUrl)
|
||||
const tenantId = session.user.tenantId ?? DEFAULT_TENANT_ID
|
||||
|
|
@ -46,7 +72,7 @@ export async function GET(request: Request) {
|
|||
}
|
||||
|
||||
try {
|
||||
const machines = (await client.query(api.machines.listByTenant, {
|
||||
const machines = (await client.query(api.devices.listByTenant, {
|
||||
tenantId,
|
||||
includeMetadata: true,
|
||||
})) as MachineInventoryRecord[]
|
||||
|
|
@ -77,6 +103,7 @@ export async function GET(request: Request) {
|
|||
generatedBy: session.user.name ?? session.user.email,
|
||||
companyFilterLabel,
|
||||
generatedAt: new Date(),
|
||||
columns: columnConfig,
|
||||
})
|
||||
|
||||
const body = new Uint8Array(workbook)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue