Download src/app/api/seed/route.ts from simikkk/test7: direct link, hf CLI and curl.
- Browser
- Download file 10.6 kB
-
https://huggingface.co/spaces/simikkk/test7/resolve/main/src/app/api/seed/route.ts
- Command line
-
hf download hf://spaces/simikkk/test7/src/app/api/seed/route.ts
-
curl -L -o route.ts https://huggingface.co/spaces/simikkk/test7/resolve/main/src/app/api/seed/route.ts
10.6 kB
| import { db } from '@/lib/db'; | |
| import { hashPassword, generateApiKey } from '@/lib/auth'; | |
| import { NextResponse } from 'next/server'; | |
| export async function GET() { | |
| try { | |
| // Upsert demo user | |
| const hashedPw = await hashPassword('demo1234'); | |
| const apiKey = generateApiKey(); | |
| const user = await db.user.upsert({ | |
| where: { email: 'demo@omniparse.ai' }, | |
| update: {}, | |
| create: { | |
| email: 'demo@omniparse.ai', | |
| name: 'Demo User', | |
| password: hashedPw, | |
| plan: 'pro', | |
| apiKey, | |
| }, | |
| }); | |
| // Delete any existing invoices for this user | |
| await db.invoice.deleteMany({ | |
| where: { userId: user.id }, | |
| }); | |
| // Define 20 diverse invoices | |
| const invoiceData = [ | |
| // ── January 2025 (5 invoices) ── | |
| { | |
| vendor: 'Acme Corp', | |
| invNumber: 'INV-2024-001', | |
| invDate: '2025-01-05', | |
| dueDate: '2025-02-04', | |
| amount: 1200, | |
| vatPct: 0.20, | |
| currency: 'USD', | |
| status: 'done' as const, | |
| isDuplicate: false, | |
| confidence: 0.95, | |
| filename: 'invoice_acme_jan.pdf', | |
| createdAt: new Date('2025-01-06T09:15:00Z'), | |
| }, | |
| { | |
| vendor: 'TechVision Inc', | |
| invNumber: 'INV-2024-002', | |
| invDate: '2025-01-12', | |
| dueDate: '2025-02-11', | |
| amount: 3450, | |
| vatPct: 0.21, | |
| currency: 'EUR', | |
| status: 'done' as const, | |
| isDuplicate: false, | |
| confidence: 0.97, | |
| filename: 'invoice_techvision_jan.pdf', | |
| createdAt: new Date('2025-01-13T14:30:00Z'), | |
| }, | |
| { | |
| vendor: 'Global Supplies Ltd', | |
| invNumber: 'INV-2024-003', | |
| invDate: '2025-01-18', | |
| dueDate: '2025-02-17', | |
| amount: 890, | |
| vatPct: 0.15, | |
| currency: 'USD', | |
| status: 'done' as const, | |
| isDuplicate: false, | |
| confidence: 0.92, | |
| filename: 'receipt_global_jan.png', | |
| createdAt: new Date('2025-01-19T11:00:00Z'), | |
| }, | |
| { | |
| vendor: 'CloudNine Services', | |
| invNumber: 'INV-2024-004', | |
| invDate: '2025-01-22', | |
| dueDate: '2025-02-21', | |
| amount: 5200, | |
| vatPct: 0.20, | |
| currency: 'USD', | |
| status: 'review' as const, | |
| isDuplicate: false, | |
| confidence: 0.88, | |
| filename: 'invoice_cloudnine_jan.pdf', | |
| createdAt: new Date('2025-01-23T08:45:00Z'), | |
| }, | |
| { | |
| vendor: 'DataFlow Systems', | |
| invNumber: 'INV-2024-005', | |
| invDate: '2025-01-28', | |
| dueDate: '2025-02-27', | |
| amount: 750, | |
| vatPct: 0.10, | |
| currency: 'USD', | |
| status: 'done' as const, | |
| isDuplicate: false, | |
| confidence: 0.96, | |
| filename: 'receipt_dataflow_jan.pdf', | |
| createdAt: new Date('2025-01-29T16:20:00Z'), | |
| }, | |
| // ── February 2025 (5 invoices) ── | |
| { | |
| vendor: 'Pinnacle Solutions', | |
| invNumber: 'INV-2024-006', | |
| invDate: '2025-02-03', | |
| dueDate: '2025-03-05', | |
| amount: 1250, | |
| vatPct: 0.18, | |
| currency: 'USD', | |
| status: 'done' as const, | |
| isDuplicate: false, | |
| confidence: 0.94, | |
| filename: 'invoice_pinnacle_feb.pdf', | |
| createdAt: new Date('2025-02-04T10:00:00Z'), | |
| }, | |
| { | |
| vendor: 'TechVision Inc', | |
| invNumber: 'INV-2024-007', | |
| invDate: '2025-02-08', | |
| dueDate: '2025-03-10', | |
| amount: 2100, | |
| vatPct: 0.20, | |
| currency: 'USD', | |
| status: 'done' as const, | |
| isDuplicate: false, | |
| confidence: 0.98, | |
| filename: 'invoice_techvision_feb.pdf', | |
| createdAt: new Date('2025-02-09T13:15:00Z'), | |
| }, | |
| { | |
| vendor: 'Acme Corp', | |
| invNumber: 'INV-2024-008', | |
| invDate: '2025-02-14', | |
| dueDate: '2025-03-16', | |
| amount: 8750, | |
| vatPct: 0.20, | |
| currency: 'GBP', | |
| status: 'review' as const, | |
| isDuplicate: false, | |
| confidence: 0.87, | |
| filename: 'invoice_acme_feb.pdf', | |
| createdAt: new Date('2025-02-15T09:30:00Z'), | |
| }, | |
| { | |
| vendor: 'Meridian Group', | |
| invNumber: 'INV-2024-009', | |
| invDate: '2025-02-20', | |
| dueDate: '2025-03-22', | |
| amount: 430, | |
| vatPct: 0.12, | |
| currency: 'USD', | |
| status: 'pending' as const, | |
| isDuplicate: false, | |
| confidence: 0.99, | |
| filename: 'receipt_meridian_feb.png', | |
| createdAt: new Date('2025-02-21T15:45:00Z'), | |
| }, | |
| { | |
| vendor: 'Nexus Technologies', | |
| invNumber: 'INV-2024-010', | |
| invDate: '2025-02-26', | |
| dueDate: '2025-03-28', | |
| amount: 6300, | |
| vatPct: 0.25, | |
| currency: 'USD', | |
| status: 'done' as const, | |
| isDuplicate: false, | |
| confidence: 0.91, | |
| filename: 'invoice_nexus_feb.pdf', | |
| createdAt: new Date('2025-02-27T11:10:00Z'), | |
| }, | |
| // ── March 2025 (5 invoices) ── | |
| { | |
| vendor: 'CloudNine Services', | |
| invNumber: 'INV-2024-011', | |
| invDate: '2025-03-04', | |
| dueDate: '2025-04-03', | |
| amount: 4800, | |
| vatPct: 0.20, | |
| currency: 'USD', | |
| status: 'done' as const, | |
| isDuplicate: false, | |
| confidence: 0.93, | |
| filename: 'invoice_cloudnine_mar.pdf', | |
| createdAt: new Date('2025-03-05T08:00:00Z'), | |
| }, | |
| { | |
| vendor: 'Pinnacle Solutions', | |
| invNumber: 'INV-2024-012', | |
| invDate: '2025-03-10', | |
| dueDate: '2025-04-09', | |
| amount: 15000, | |
| vatPct: 0.22, | |
| currency: 'USD', | |
| status: 'review' as const, | |
| isDuplicate: false, | |
| confidence: 0.86, | |
| filename: 'invoice_pinnacle_mar.pdf', | |
| createdAt: new Date('2025-03-11T14:25:00Z'), | |
| }, | |
| { | |
| vendor: 'Global Supplies Ltd', | |
| invNumber: 'INV-2024-013', | |
| invDate: '2025-03-15', | |
| dueDate: '2025-04-14', | |
| amount: 2350, | |
| vatPct: 0.19, | |
| currency: 'EUR', | |
| status: 'done' as const, | |
| isDuplicate: false, | |
| confidence: 0.95, | |
| filename: 'invoice_global_mar.pdf', | |
| createdAt: new Date('2025-03-16T10:40:00Z'), | |
| }, | |
| { | |
| vendor: 'DataFlow Systems', | |
| invNumber: 'INV-2024-014', | |
| invDate: '2025-03-19', | |
| dueDate: '2025-04-18', | |
| amount: 1100, | |
| vatPct: 0.15, | |
| currency: 'USD', | |
| status: 'done' as const, | |
| isDuplicate: false, | |
| confidence: 0.97, | |
| filename: 'receipt_dataflow_mar.png', | |
| createdAt: new Date('2025-03-20T09:55:00Z'), | |
| }, | |
| { | |
| vendor: 'Acme Corp', | |
| invNumber: 'INV-2024-015', | |
| invDate: '2025-03-25', | |
| dueDate: '2025-04-24', | |
| amount: 9200, | |
| vatPct: 0.20, | |
| currency: 'USD', | |
| status: 'done' as const, | |
| isDuplicate: false, | |
| confidence: 0.89, | |
| filename: 'invoice_acme_mar.pdf', | |
| createdAt: new Date('2025-03-26T16:30:00Z'), | |
| }, | |
| // ── April 2025 (5 invoices) ── | |
| { | |
| vendor: 'Nexus Technologies', | |
| invNumber: 'INV-2024-016', | |
| invDate: '2025-04-02', | |
| dueDate: '2025-05-02', | |
| amount: 6280, | |
| vatPct: 0.23, | |
| currency: 'USD', | |
| status: 'done' as const, | |
| isDuplicate: true, // Duplicate of INV-2024-010 (same vendor, $6300) | |
| confidence: 0.88, | |
| filename: 'invoice_nexus_apr.pdf', | |
| createdAt: new Date('2025-04-03T11:20:00Z'), | |
| }, | |
| { | |
| vendor: 'Meridian Group', | |
| invNumber: 'INV-2024-017', | |
| invDate: '2025-04-08', | |
| dueDate: '2025-05-08', | |
| amount: 780, | |
| vatPct: 0.14, | |
| currency: 'EUR', | |
| status: 'pending' as const, | |
| isDuplicate: false, | |
| confidence: 0.96, | |
| filename: 'receipt_meridian_apr.png', | |
| createdAt: new Date('2025-04-09T08:10:00Z'), | |
| }, | |
| { | |
| vendor: 'CloudNine Services', | |
| invNumber: 'INV-2024-018', | |
| invDate: '2025-04-14', | |
| dueDate: '2025-05-14', | |
| amount: 5150, | |
| vatPct: 0.20, | |
| currency: 'USD', | |
| status: 'done' as const, | |
| isDuplicate: true, // Duplicate of INV-2024-004 (same vendor, $5200) | |
| confidence: 0.92, | |
| filename: 'invoice_cloudnine_apr.pdf', | |
| createdAt: new Date('2025-04-15T13:50:00Z'), | |
| }, | |
| { | |
| vendor: 'Pinnacle Solutions', | |
| invNumber: 'INV-2024-019', | |
| invDate: '2025-04-20', | |
| dueDate: '2025-05-20', | |
| amount: 3200, | |
| vatPct: 0.20, | |
| currency: 'GBP', | |
| status: 'done' as const, | |
| isDuplicate: false, | |
| confidence: 0.94, | |
| filename: 'invoice_pinnacle_apr.pdf', | |
| createdAt: new Date('2025-04-21T10:05:00Z'), | |
| }, | |
| { | |
| vendor: 'TechVision Inc', | |
| invNumber: 'INV-2024-020', | |
| invDate: '2025-04-27', | |
| dueDate: '2025-05-27', | |
| amount: 2800, | |
| vatPct: 0.17, | |
| currency: 'USD', | |
| status: 'review' as const, | |
| isDuplicate: false, | |
| confidence: 0.85, | |
| filename: 'invoice_techvision_apr.pdf', | |
| createdAt: new Date('2025-04-28T15:00:00Z'), | |
| }, | |
| ]; | |
| // Create all invoices with computed VAT and total | |
| const invoices = await db.invoice.createMany({ | |
| data: invoiceData.map((inv) => ({ | |
| userId: user.id, | |
| vendor: inv.vendor, | |
| invNumber: inv.invNumber, | |
| invDate: inv.invDate, | |
| dueDate: inv.dueDate, | |
| amount: inv.amount, | |
| vatAmount: Math.round(inv.amount * inv.vatPct * 100) / 100, | |
| total: Math.round(inv.amount * (1 + inv.vatPct) * 100) / 100, | |
| currency: inv.currency, | |
| status: inv.status, | |
| isDuplicate: inv.isDuplicate, | |
| confidence: inv.confidence, | |
| filename: inv.filename, | |
| rawJson: null, | |
| createdAt: inv.createdAt, | |
| })), | |
| }); | |
| return NextResponse.json({ | |
| message: `Seed complete: ${invoices.count} invoices created for demo user`, | |
| userId: user.id, | |
| invoiceCount: invoices.count, | |
| breakdown: { | |
| byVendor: { | |
| 'Acme Corp': 3, | |
| 'TechVision Inc': 3, | |
| 'Global Supplies Ltd': 2, | |
| 'CloudNine Services': 3, | |
| 'DataFlow Systems': 2, | |
| 'Pinnacle Solutions': 3, | |
| 'Meridian Group': 2, | |
| 'Nexus Technologies': 2, | |
| }, | |
| byStatus: { done: 14, review: 4, pending: 2 }, | |
| duplicates: 2, | |
| byCurrency: { USD: 15, EUR: 3, GBP: 2 }, | |
| }, | |
| }); | |
| } catch (error) { | |
| console.error('[SEED_ERROR]', error); | |
| return NextResponse.json({ error: 'Seed failed' }, { status: 500 }); | |
| } | |
| } |