forked from Northgate-Systems/RemitX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.ts
More file actions
39 lines (34 loc) · 1.14 KB
/
Copy pathroute.ts
File metadata and controls
39 lines (34 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { NextRequest } from "next/server";
import { supabase } from "@/lib/supabase";
import { getCurrentUser } from "@/lib/auth";
import { successResponse, unauthorizedResponse } from "@/lib/api-response";
export async function GET(request: NextRequest) {
try {
const user = await getCurrentUser();
if (!user) {
return unauthorizedResponse();
}
const { searchParams } = new URL(request.url);
const limit = Math.min(parseInt(searchParams.get("limit") || "50"), 100);
const offset = parseInt(searchParams.get("offset") || "0");
const { data: transactions, error, count } = await supabase
.from("transactions")
.select("*", { count: "exact" })
.eq("userId", user.id)
.order("createdAt", { ascending: false })
.range(offset, offset + limit - 1);
if (error) {
console.error("Transactions fetch error:", error);
return unauthorizedResponse();
}
return successResponse({
transactions: transactions || [],
total: count ?? 0,
limit,
offset,
});
} catch (err) {
console.error("Transactions fetch error:", err);
return unauthorizedResponse();
}
}