29 lines
1.3 KiB
TypeScript
29 lines
1.3 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { getServerSession } from 'next-auth'
|
|
import { authOptions } from '@/lib/auth'
|
|
import { fetchPendingProducts } from '@/lib/creationSheets'
|
|
import { prisma } from '@/lib/prisma'
|
|
import type { PendingProduct } from '@/types/creation'
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
export async function GET(_req: NextRequest) {
|
|
const session = await getServerSession(authOptions)
|
|
if (!session) return NextResponse.json({ error: 'Non authentifié' }, { status: 401 })
|
|
try {
|
|
const existing = await prisma.productCreation.findMany({ select: { sheetTab: true, sheetRow: true } })
|
|
const alreadyCreated = new Set(existing.map(e => `${e.sheetTab}:${e.sheetRow}`))
|
|
const pending = await fetchPendingProducts(alreadyCreated)
|
|
const byTab: Record<string, PendingProduct[]> = {}
|
|
const specificColumns = new Set<string>()
|
|
for (const p of pending) {
|
|
if (!byTab[p.tab]) byTab[p.tab] = []
|
|
byTab[p.tab].push(p)
|
|
Object.keys(p.specificFields).forEach(k => specificColumns.add(k))
|
|
}
|
|
return NextResponse.json({ byTab, total: pending.length, specificColumns: Array.from(specificColumns).sort() })
|
|
} catch (err) {
|
|
const message = err instanceof Error ? err.message : 'Erreur inconnue'
|
|
return NextResponse.json({ error: message }, { status: 500 })
|
|
}
|
|
}
|