diff --git a/lib/api/comments.ts b/lib/api/comments.ts index fc41f9c..c827a04 100644 --- a/lib/api/comments.ts +++ b/lib/api/comments.ts @@ -5,7 +5,7 @@ import type { Comment } from "@/lib/types" import { httpJson } from "./http" type Paginated = { - items: T[] + items: T[] | null meta: { total: number offset: number @@ -39,7 +39,7 @@ export async function listCommentsByPost( cache: "no-store", }, ) - return res.items + return res.items ?? [] } export async function addComment(postId: string, content: string) { diff --git a/lib/api/disputes.ts b/lib/api/disputes.ts index 3a7f0c1..508a96d 100644 --- a/lib/api/disputes.ts +++ b/lib/api/disputes.ts @@ -24,7 +24,7 @@ export type ListDisputesOptions = { } type Paginated = { - items: T[] + items: T[] | null meta?: { total: number offset: number @@ -50,6 +50,7 @@ function unwrapItems(value: unknown): T[] { if ("items" in value) { const envelope = value as { items?: unknown } if (Array.isArray(envelope.items)) return envelope.items as T[] + if (envelope.items === null) return [] } throw new Error("Invalid response") } diff --git a/lib/api/favorites.ts b/lib/api/favorites.ts index e8e97f6..383397a 100644 --- a/lib/api/favorites.ts +++ b/lib/api/favorites.ts @@ -3,7 +3,7 @@ import type { Favorite } from "@/lib/types" import { httpJson } from "./http" type Paginated = { - items: T[] + items: T[] | null meta: { total: number offset: number @@ -15,7 +15,7 @@ export async function listFavorites(): Promise { const res = await httpJson | Favorite[]>("/api/v1/favorites", { cache: "no-store", }) - return Array.isArray(res) ? res : res.items + return Array.isArray(res) ? res : (res.items ?? []) } export async function isFavorited( diff --git a/lib/api/games.ts b/lib/api/games.ts index 349080d..9e27d7d 100644 --- a/lib/api/games.ts +++ b/lib/api/games.ts @@ -4,7 +4,7 @@ import type { Game } from "@/lib/types" import { httpJson } from "./http" type Paginated = { - items: T[] + items: T[] | null meta: { total: number offset: number @@ -16,7 +16,7 @@ export async function listGames(): Promise { const res = await httpJson>("/api/v1/games?offset=0&limit=100", { cache: "no-store", }) - return res.items + return res.items ?? [] } export async function getGameById(gameId: string): Promise { diff --git a/lib/api/notifications.ts b/lib/api/notifications.ts index 321e02b..180ea05 100644 --- a/lib/api/notifications.ts +++ b/lib/api/notifications.ts @@ -3,7 +3,7 @@ import type { Notification } from "@/lib/types" import { httpJson } from "./http" type Paginated = { - items: T[] + items: T[] | null meta: { total: number offset: number @@ -26,7 +26,7 @@ export async function listNotifications(input?: { const res = await httpJson>(`/api/v1/notifications?${searchParams}`, { cache: "no-store", }) - return res.items + return res.items ?? [] } export async function markNotificationAsRead(notificationId: string): Promise { diff --git a/lib/api/orders.ts b/lib/api/orders.ts index cd68dee..433ed98 100644 --- a/lib/api/orders.ts +++ b/lib/api/orders.ts @@ -5,7 +5,7 @@ import type { Order, OrderStatus } from "@/lib/types" import { httpJson } from "./http" type Paginated = { - items: T[] + items: T[] | null meta: { total: number offset: number @@ -59,7 +59,7 @@ export async function listOrders(options?: ListOrdersOptions): Promise const res = await httpJson>(withOffsetLimit("/api/v1/orders", options), { cache: "no-store", }) - return res.items + return res.items ?? [] } export async function getOrderById(orderId: string): Promise { diff --git a/lib/api/players.ts b/lib/api/players.ts index 425a1c9..5e61d5e 100644 --- a/lib/api/players.ts +++ b/lib/api/players.ts @@ -4,7 +4,7 @@ import type { Player } from "@/lib/types" import { httpJson } from "./http" type Paginated = { - items: T[] + items: T[] | null meta: { total: number offset: number @@ -16,7 +16,7 @@ export async function listPlayers(): Promise { const res = await httpJson>("/api/v1/players?offset=0&limit=100", { cache: "no-store", }) - return res.items + return res.items ?? [] } export async function getPlayerById(playerId: string): Promise { diff --git a/lib/api/posts.ts b/lib/api/posts.ts index 55ecffc..ad5f99a 100644 --- a/lib/api/posts.ts +++ b/lib/api/posts.ts @@ -4,7 +4,7 @@ import type { Post } from "@/lib/types" import { httpJson } from "./http" type Paginated = { - items: T[] + items: T[] | null meta: { total: number offset: number @@ -40,7 +40,7 @@ export async function listPosts(options?: ListOptions): Promise { const res = await httpJson>(withOffsetLimit("/api/v1/posts", options), { cache: "no-store", }) - return res.items + return res.items ?? [] } export async function getPostById(postId: string): Promise { @@ -80,7 +80,7 @@ export async function listPostsByAuthor(userId: string, options?: ListOptions): cache: "no-store", }, ) - return res.items + return res.items ?? [] } export async function togglePostLike(postId: string, currentlyLiked: boolean): Promise { diff --git a/lib/api/reviews.ts b/lib/api/reviews.ts index faa199d..e17d571 100644 --- a/lib/api/reviews.ts +++ b/lib/api/reviews.ts @@ -5,7 +5,7 @@ import type { Review } from "@/lib/types" import { httpJson } from "./http" type Paginated = { - items: T[] + items: T[] | null meta: { total: number offset: number @@ -37,6 +37,7 @@ function unwrapItems(value: unknown): T[] { if ("items" in value) { const envelope = value as { items?: unknown } if (Array.isArray(envelope.items)) return envelope.items as T[] + if (envelope.items === null) return [] } throw new Error("Invalid response") } diff --git a/lib/api/transactions.ts b/lib/api/transactions.ts index bafe9d9..04a4713 100644 --- a/lib/api/transactions.ts +++ b/lib/api/transactions.ts @@ -3,7 +3,7 @@ import type { WalletTransaction } from "@/lib/types" import { httpJson } from "./http" type Paginated = { - items: T[] + items: T[] | null meta: { total: number offset: number @@ -57,7 +57,7 @@ export async function listWalletTransactions( cache: "no-store", }, ) - return res.items + return res.items ?? [] } export async function topUpWallet(input: { amount: number; method?: string }): Promise { diff --git a/lib/api/users.ts b/lib/api/users.ts index 6dfc568..e91f7da 100644 --- a/lib/api/users.ts +++ b/lib/api/users.ts @@ -65,8 +65,11 @@ export async function applyCurrentUserVerification(input: { } export async function listCurrentUserVerifications(): Promise { - const res = await httpJson<{ list: VerificationRecord[] }>("/api/v1/users/me/verification", { - cache: "no-store", - }) - return res.list + const res = await httpJson<{ list: VerificationRecord[] | null }>( + "/api/v1/users/me/verification", + { + cache: "no-store", + }, + ) + return res.list ?? [] }