fix: handle empty stays in query

This commit is contained in:
Christel Westerberg
2024-05-13 09:46:14 +02:00
parent 058f0cc898
commit a91ff342f0
5 changed files with 30 additions and 199 deletions

View File

@@ -1,5 +1,3 @@
import { z } from "zod"
import * as api from "@/lib/api"
import {
badRequestError,
@@ -43,6 +41,7 @@ export const userQueryRouter = router({
}
const apiJson = await apiResponse.json()
if (!apiJson.data?.length) {
throw internalServerError()
}
@@ -113,7 +112,7 @@ export const userQueryRouter = router({
}
const apiJson = await apiResponse.json()
if (!apiJson.data?.length) {
if (!apiJson.data) {
console.error(`Get Previous Stays - No data found from api call`)
throw internalServerError()
}
@@ -127,6 +126,7 @@ export const userQueryRouter = router({
}
const nextCursor =
verifiedData.data.links &&
verifiedData.data.links.offset < verifiedData.data.links.totalCount
? verifiedData.data.links.offset
: undefined
@@ -177,7 +177,7 @@ export const userQueryRouter = router({
}
const apiJson = await apiResponse.json()
if (!apiJson.data?.length) {
if (!apiJson.data) {
console.error(`Get Upcoming Stays - No data found from api call`)
throw internalServerError()
}
@@ -191,6 +191,7 @@ export const userQueryRouter = router({
}
const nextCursor =
verifiedData.data.links &&
verifiedData.data.links.offset < verifiedData.data.links.totalCount
? verifiedData.data.links.offset
: undefined