- Updated all packages to latest versions (React 19, Next.js 14.2.32) - Replaced sqlite3 with pg and drizzle-orm dependencies - Created complete PostgreSQL schema with relationships and indexes - Migrated all API endpoints from SQLite to Drizzle queries - Added database seeding with sample data - Updated authentication to use bcrypt instead of pbkdf2 - Configured connection pooling for PostgreSQL - Updated app version to 1.0.0 - All endpoints tested and working correctly
33 lines
956 B
TypeScript
33 lines
956 B
TypeScript
import type { NextApiRequest, NextApiResponse } from 'next'
|
|
import { db, schema } from '../../../../lib/db/connection'
|
|
import { eq, desc } from 'drizzle-orm'
|
|
|
|
export default async function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse
|
|
) {
|
|
if (req.method !== 'GET') {
|
|
return res.status(405).json({ error: 'Method not allowed' })
|
|
}
|
|
|
|
const { status = 'pending', page = '1', limit = '20' } = req.query
|
|
|
|
try {
|
|
const offset = (parseInt(page as string) - 1) * parseInt(limit as string)
|
|
const limitInt = parseInt(limit as string)
|
|
|
|
const sources = await db
|
|
.select()
|
|
.from(schema.sources)
|
|
.where(eq(schema.sources.status, status as any))
|
|
.orderBy(desc(schema.sources.createdAt))
|
|
.limit(limitInt)
|
|
.offset(offset)
|
|
|
|
return res.status(200).json(sources)
|
|
|
|
} catch (error) {
|
|
console.error('Database error:', error)
|
|
return res.status(500).json({ error: 'Internal server error' })
|
|
}
|
|
} |