feat: improve reports filters and ticket flows
This commit is contained in:
parent
9c74e10675
commit
15d11b6b12
29 changed files with 437 additions and 140 deletions
|
|
@ -17,6 +17,8 @@ export async function GET(request: Request) {
|
|||
const { searchParams } = new URL(request.url)
|
||||
const range = searchParams.get("range") ?? undefined
|
||||
const companyId = searchParams.get("companyId") ?? undefined
|
||||
const dateFrom = searchParams.get("dateFrom") ?? undefined
|
||||
const dateTo = searchParams.get("dateTo") ?? undefined
|
||||
|
||||
const context = await createConvexContext({
|
||||
tenantId,
|
||||
|
|
@ -26,7 +28,12 @@ export async function GET(request: Request) {
|
|||
role: session.user.role.toUpperCase(),
|
||||
})
|
||||
|
||||
const artifact = await buildBacklogWorkbook(context, { range, companyId: companyId ?? undefined })
|
||||
const artifact = await buildBacklogWorkbook(context, {
|
||||
range,
|
||||
companyId: companyId ?? undefined,
|
||||
dateFrom,
|
||||
dateTo,
|
||||
})
|
||||
|
||||
return new NextResponse(artifact.buffer, {
|
||||
headers: {
|
||||
|
|
|
|||
50
src/app/api/reports/category-insights.xlsx/route.ts
Normal file
50
src/app/api/reports/category-insights.xlsx/route.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import { NextResponse } from "next/server"
|
||||
|
||||
import { assertAuthenticatedSession } from "@/lib/auth-server"
|
||||
import { DEFAULT_TENANT_ID } from "@/lib/constants"
|
||||
import { buildCategoryInsightsWorkbook, createConvexContext } from "@/server/report-exporters"
|
||||
|
||||
export const runtime = "nodejs"
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const session = await assertAuthenticatedSession()
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: "Não autorizado" }, { status: 401 })
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(request.url)
|
||||
const range = searchParams.get("range") ?? undefined
|
||||
const companyId = searchParams.get("companyId") ?? undefined
|
||||
const dateFrom = searchParams.get("dateFrom") ?? undefined
|
||||
const dateTo = searchParams.get("dateTo") ?? undefined
|
||||
|
||||
const tenantId = session.user.tenantId ?? DEFAULT_TENANT_ID
|
||||
|
||||
try {
|
||||
const context = await createConvexContext({
|
||||
tenantId,
|
||||
name: session.user.name ?? session.user.email,
|
||||
email: session.user.email,
|
||||
avatarUrl: session.user.avatarUrl,
|
||||
role: session.user.role.toUpperCase(),
|
||||
})
|
||||
|
||||
const artifact = await buildCategoryInsightsWorkbook(context, {
|
||||
range,
|
||||
companyId: companyId || undefined,
|
||||
dateFrom,
|
||||
dateTo,
|
||||
})
|
||||
|
||||
return new NextResponse(artifact.buffer, {
|
||||
headers: {
|
||||
"Content-Type": artifact.mimeType,
|
||||
"Content-Disposition": `attachment; filename="${artifact.fileName}"`,
|
||||
"Cache-Control": "no-store",
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("Failed to generate category insights export", error)
|
||||
return NextResponse.json({ error: "Falha ao gerar planilha de categorias" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,8 @@ export async function GET(request: Request) {
|
|||
const { searchParams } = new URL(request.url)
|
||||
const range = searchParams.get("range") ?? undefined
|
||||
const companyId = searchParams.get("companyId") ?? undefined
|
||||
const dateFrom = searchParams.get("dateFrom") ?? undefined
|
||||
const dateTo = searchParams.get("dateTo") ?? undefined
|
||||
|
||||
const tenantId = session.user.tenantId ?? DEFAULT_TENANT_ID
|
||||
|
||||
|
|
@ -26,7 +28,12 @@ export async function GET(request: Request) {
|
|||
role: session.user.role.toUpperCase(),
|
||||
})
|
||||
|
||||
const artifact = await buildCsatWorkbook(context, { range, companyId: companyId ?? undefined })
|
||||
const artifact = await buildCsatWorkbook(context, {
|
||||
range,
|
||||
companyId: companyId ?? undefined,
|
||||
dateFrom,
|
||||
dateTo,
|
||||
})
|
||||
|
||||
return new NextResponse(artifact.buffer, {
|
||||
headers: {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ export async function GET(request: Request) {
|
|||
const range = searchParams.get("range") ?? undefined
|
||||
const q = searchParams.get("q")?.toLowerCase().trim() ?? ""
|
||||
const companyId = searchParams.get("companyId") ?? ""
|
||||
const dateFrom = searchParams.get("dateFrom") ?? undefined
|
||||
const dateTo = searchParams.get("dateTo") ?? undefined
|
||||
|
||||
const tenantId = session.user.tenantId ?? DEFAULT_TENANT_ID
|
||||
|
||||
|
|
@ -29,6 +31,8 @@ export async function GET(request: Request) {
|
|||
range,
|
||||
companyId: companyId || undefined,
|
||||
search: q || undefined,
|
||||
dateFrom,
|
||||
dateTo,
|
||||
})
|
||||
|
||||
return new NextResponse(artifact.buffer, {
|
||||
|
|
|
|||
54
src/app/api/reports/machine-category.xlsx/route.ts
Normal file
54
src/app/api/reports/machine-category.xlsx/route.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import { NextResponse } from "next/server"
|
||||
|
||||
import { assertAuthenticatedSession } from "@/lib/auth-server"
|
||||
import { DEFAULT_TENANT_ID } from "@/lib/constants"
|
||||
import { buildMachineCategoryWorkbook, createConvexContext } from "@/server/report-exporters"
|
||||
|
||||
export const runtime = "nodejs"
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const session = await assertAuthenticatedSession()
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: "Não autorizado" }, { status: 401 })
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(request.url)
|
||||
const range = searchParams.get("range") ?? undefined
|
||||
const companyId = searchParams.get("companyId") ?? undefined
|
||||
const machineId = searchParams.get("machineId") ?? undefined
|
||||
const userId = searchParams.get("userId") ?? undefined
|
||||
const dateFrom = searchParams.get("dateFrom") ?? undefined
|
||||
const dateTo = searchParams.get("dateTo") ?? undefined
|
||||
|
||||
const tenantId = session.user.tenantId ?? DEFAULT_TENANT_ID
|
||||
|
||||
try {
|
||||
const context = await createConvexContext({
|
||||
tenantId,
|
||||
name: session.user.name ?? session.user.email,
|
||||
email: session.user.email,
|
||||
avatarUrl: session.user.avatarUrl,
|
||||
role: session.user.role.toUpperCase(),
|
||||
})
|
||||
|
||||
const artifact = await buildMachineCategoryWorkbook(context, {
|
||||
range,
|
||||
companyId: companyId || undefined,
|
||||
machineId: machineId || undefined,
|
||||
userId: userId || undefined,
|
||||
dateFrom,
|
||||
dateTo,
|
||||
})
|
||||
|
||||
return new NextResponse(artifact.buffer, {
|
||||
headers: {
|
||||
"Content-Type": artifact.mimeType,
|
||||
"Content-Disposition": `attachment; filename="${artifact.fileName}"`,
|
||||
"Cache-Control": "no-store",
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("Failed to generate machine category export", error)
|
||||
return NextResponse.json({ error: "Falha ao gerar planilha de máquinas x categorias" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,8 @@ export async function GET(request: Request) {
|
|||
const { searchParams } = new URL(request.url)
|
||||
const range = searchParams.get("range") ?? undefined
|
||||
const companyId = searchParams.get("companyId") ?? undefined
|
||||
const dateFrom = searchParams.get("dateFrom") ?? undefined
|
||||
const dateTo = searchParams.get("dateTo") ?? undefined
|
||||
|
||||
const tenantId = session.user.tenantId ?? DEFAULT_TENANT_ID
|
||||
|
||||
|
|
@ -26,7 +28,12 @@ export async function GET(request: Request) {
|
|||
role: session.user.role.toUpperCase(),
|
||||
})
|
||||
|
||||
const artifact = await buildSlaWorkbook(context, { range, companyId: companyId ?? undefined })
|
||||
const artifact = await buildSlaWorkbook(context, {
|
||||
range,
|
||||
companyId: companyId ?? undefined,
|
||||
dateFrom,
|
||||
dateTo,
|
||||
})
|
||||
|
||||
return new NextResponse(artifact.buffer, {
|
||||
headers: {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ export async function GET(request: Request) {
|
|||
const { searchParams } = new URL(request.url)
|
||||
const range = searchParams.get("range") ?? undefined // "7d" | "30d" | undefined(=90d)
|
||||
const companyId = searchParams.get("companyId") ?? undefined
|
||||
const dateFrom = searchParams.get("dateFrom") ?? undefined
|
||||
const dateTo = searchParams.get("dateTo") ?? undefined
|
||||
|
||||
const tenantId = session.user.tenantId ?? DEFAULT_TENANT_ID
|
||||
|
||||
|
|
@ -29,6 +31,8 @@ export async function GET(request: Request) {
|
|||
const artifact = await buildTicketsByChannelWorkbook(context, {
|
||||
range,
|
||||
companyId: companyId ?? undefined,
|
||||
dateFrom,
|
||||
dateTo,
|
||||
})
|
||||
|
||||
return new NextResponse(artifact.buffer, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue