- 로또 번호 추천 구독자 전용 페이지 (/services/lotto/recommend) - NAS 몬테카를로 API 연동 + 클라이언트 사이드 폴백 - 무료 미리보기 1개 + 구독자용 프리미엄 번호 추천 - 구독 플랜 변경: 골드(900원)/플래티넘(2,900원)/다이아(9,900원) - 텔레그램 봇 연동: 연결/해제, 웹훅, /start 명령 처리 - 마이페이지 텔레그램 연결 UI + 가이드 모달 - 관리자 페이지 (/admin): 대시보드, 회원, 서비스, 문의 관리 - Supabase 마이그레이션: profiles 텔레그램 컬럼, 신규 상품 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import { createAdminClient } from '@/lib/supabase/admin';
|
|
import { verifyAdminTokenNode } from '@/lib/admin-auth';
|
|
import { cookies } from 'next/headers';
|
|
|
|
export const runtime = 'nodejs';
|
|
|
|
export async function GET() {
|
|
const cookieStore = await cookies();
|
|
const token = cookieStore.get('admin_token')?.value;
|
|
if (!token || !verifyAdminTokenNode(token)) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
}
|
|
|
|
const supabase = createAdminClient();
|
|
|
|
const { data: profiles, error } = await supabase
|
|
.from('profiles')
|
|
.select('id, email, full_name, created_at')
|
|
.order('created_at', { ascending: false })
|
|
.limit(100);
|
|
|
|
if (error) {
|
|
return NextResponse.json({ error: error.message }, { status: 500 });
|
|
}
|
|
|
|
// 각 회원의 주문 수 + 결제 금액 집계
|
|
const enriched = await Promise.all(
|
|
(profiles ?? []).map(async (p: { id: string; email: string; full_name: string; created_at: string }) => {
|
|
const [ordersRes, paymentsRes] = await Promise.all([
|
|
supabase.from('orders').select('id', { count: 'exact', head: true }).eq('user_id', p.id).eq('status', 'paid'),
|
|
supabase.from('payments').select('amount').eq('user_id', p.id).eq('status', 'paid'),
|
|
]);
|
|
const totalPaid = (paymentsRes.data ?? []).reduce((s: number, x: { amount: number }) => s + x.amount, 0);
|
|
return { ...p, orderCount: ordersRes.count ?? 0, totalPaid };
|
|
})
|
|
);
|
|
|
|
return NextResponse.json({ members: enriched });
|
|
}
|