- 원인: purchase/personal은 유저별 데이터인데 NAS로 프록시 → NAS가 userId 모름 - ConnectTimeoutError는 NAS에 미구현 엔드포인트로 연결 시도한 결과 purchase/route.ts: nasGet/nasPost → Supabase lotto_purchases CRUD purchase/stats/route.ts: nasGet → Supabase 집계 (총구매/당첨금/순손익 계산) purchase/[id]/route.ts: nasPut/nasDelete → Supabase UPDATE/DELETE (user_id RLS) analysis/personal/route.ts: nasGet → lotto_history 테이블 직접 분석 (번호 빈도, top/least picks, 홀짝패턴, 구간 분포, 당첨평균 대비) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import { createClient } from '@/lib/supabase/server';
|
|
import { requireSubscription } from '../../_nas';
|
|
|
|
export async function PUT(request: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
try {
|
|
const auth = await requireSubscription();
|
|
if (auth instanceof NextResponse) return auth;
|
|
|
|
const supabase = await createClient();
|
|
const { id } = await params;
|
|
const body = await request.json();
|
|
|
|
const { data, error } = await supabase
|
|
.from('lotto_purchases')
|
|
.update({ prize: body.prize, note: body.note })
|
|
.eq('id', parseInt(id))
|
|
.eq('user_id', auth.userId) // 본인 데이터만 수정
|
|
.select()
|
|
.single();
|
|
|
|
if (error) throw error;
|
|
return NextResponse.json(data);
|
|
} catch (err) {
|
|
console.error('[purchase PUT]', err);
|
|
return NextResponse.json({ error: 'DB_ERROR' }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function DELETE(_req: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
try {
|
|
const auth = await requireSubscription();
|
|
if (auth instanceof NextResponse) return auth;
|
|
|
|
const supabase = await createClient();
|
|
const { id } = await params;
|
|
|
|
const { error } = await supabase
|
|
.from('lotto_purchases')
|
|
.delete()
|
|
.eq('id', parseInt(id))
|
|
.eq('user_id', auth.userId); // 본인 데이터만 삭제
|
|
|
|
if (error) throw error;
|
|
return NextResponse.json({ ok: true });
|
|
} catch (err) {
|
|
console.error('[purchase DELETE]', err);
|
|
return NextResponse.json({ error: 'DB_ERROR' }, { status: 500 });
|
|
}
|
|
}
|