Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/app/api/streak/freeze/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,26 @@ export async function POST() {

const today = todayStr();

const { data: existing } = await supabaseAdmin
.from("streak_freezes")
.select("id")
.eq("user_id", user.id)
.eq("freeze_date", today)
.maybeSingle();

const { data: freeze, error } = await supabaseAdmin
.from("streak_freezes")
.insert({ user_id: user.id, freeze_date: today })
.upsert({ user_id: user.id, freeze_date: today }, { onConflict: "user_id,freeze_date" })
.select()
.single();

if (error) {
if (error.code === "23505") {
return Response.json(
{ error: "You already have an unused streak freeze." },
{ status: 409 }
);
}
return Response.json({ error: "Failed to apply freeze." }, { status: 500 });
}

return Response.json({ freeze }, { status: 201 });
const alreadyExisted = existing !== null;

return Response.json({ freeze, already_existed: alreadyExisted }, { status: 201 });
}

// DELETE /api/streak/freeze
Expand Down
12 changes: 6 additions & 6 deletions src/app/api/user/data-export/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function GET() {

const { data: userData } = await supabaseAdmin
.from("users")
.select("*")
.select("id, github_login, is_public, leaderboard_opt_in, created_at")
.eq("id", user.id)
.single();
if (userData) {
Expand All @@ -35,13 +35,13 @@ export async function GET() {

const { data: goals } = await supabaseAdmin
.from("goals")
.select("*")
.select("id, user_id, title, description, status, created_at, updated_at")
.eq("user_id", user.id);
sections.goals = goals || [];

const { data: snapshots } = await supabaseAdmin
.from("metric_snapshots")
.select("*")
.select("id, user_id, streak_current, streak_longest, total_commits, total_prs, total_issues, snapshot_at")
.eq("user_id", user.id)
.order("snapshot_at", { ascending: false })
.limit(1000);
Expand All @@ -62,13 +62,13 @@ export async function GET() {

const { data: streakFreezes } = await supabaseAdmin
.from("streak_freezes")
.select("*")
.select("id, user_id, freeze_date, created_at")
.eq("user_id", user.id);
sections.streakFreezes = streakFreezes || [];

const { data: streakMilestones } = await supabaseAdmin
.from("streak_milestones")
.select("*")
.select("id, user_id, streak_length, milestone_type, achieved_at")
.eq("user_id", user.id);
sections.streakMilestones = streakMilestones || [];

Expand All @@ -80,7 +80,7 @@ export async function GET() {

const { data: localCodingSessions } = await supabaseAdmin
.from("local_coding_sessions")
.select("*")
.select("id, user_id, date, duration_minutes, lines_added, lines_deleted, commits_count")
.eq("user_id", user.id)
.order("date", { ascending: false })
.limit(365);
Expand Down
Loading