23aa78d3da
- GET /api/sheets/tabs : liste les onglets Google Sheets disponibles - readSheetProducts(tab?) et fetchPendingProducts(set, tab?) acceptent un filtre - /api/sync/preview?tab=xxx et /api/creation/preview?tab=xxx filtrent sur un onglet - Composant FamilySelector : grille de boutons chargeant les onglets dynamiquement - Page Sync : étape 0 de sélection famille avant l'analyse - Page Création : étape famille avant analyse, badge de famille sélectionnée Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
29 lines
1.4 KiB
TypeScript
29 lines
1.4 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'
|
|
|
|
export async function GET(req: NextRequest) {
|
|
const session = await getServerSession(authOptions)
|
|
if (!session) return NextResponse.json({ error: 'Non authentifié' }, { status: 401 })
|
|
const tab = new URL(req.url).searchParams.get('tab') ?? undefined
|
|
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, tab)
|
|
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 })
|
|
}
|
|
}
|