Add database integration, auth API, admin/user portals, and deploy-db.sh

This commit is contained in:
2026-06-27 16:40:58 -05:00
parent 26559d4cf8
commit cc59177a74
25 changed files with 1423 additions and 118 deletions
+47
View File
@@ -0,0 +1,47 @@
import { NextResponse } from 'next/server';
import { requireRole } from '@/lib/auth';
import { db } from '@/lib/db';
export async function GET() {
try {
const session = await requireRole('user');
const userId = session.id;
const { rows: reservations } = await db.query(
'SELECT id, date, time, guests, table_name FROM reservations WHERE user_id = $1 ORDER BY date, time',
[userId]
);
const { rows: coupons } = await db.query(
'SELECT id, code, discount FROM coupons WHERE user_id = $1 ORDER BY created_at',
[userId]
);
const { rows: offers } = await db.query(
'SELECT id, title, description FROM offers WHERE active = TRUE ORDER BY created_at'
);
const { rows: benefits } = await db.query(
'SELECT id, text FROM benefits ORDER BY id'
);
const { rows: configRows } = await db.query(
"SELECT value FROM config WHERE key = 'wifi_password'"
);
const wifiPassword = configRows[0]?.value || '';
return NextResponse.json({
reservations,
coupons,
offers,
benefits: benefits.map((b: { text: string }) => b.text),
wifiPassword,
});
} catch (error) {
if ((error as Error).message === 'Unauthorized') {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
console.error('User portal error:', error);
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
}
}