From c0d63fd4336dc22cb6133dbaf0bad27997632611 Mon Sep 17 00:00:00 2001 From: Izan Gil <66965250+SrIzan10@users.noreply.github.com> Date: Sat, 27 Jul 2024 01:40:28 +0200 Subject: [PATCH] fix: convert empty string to null --- package.json | 3 ++- src/app/getBots/route.ts | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a620fa8..5fbf8f3 100644 --- a/package.json +++ b/package.json @@ -46,5 +46,6 @@ "prisma": "^5.12.1", "tailwindcss": "^3.4.1", "typescript": "^5" - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/src/app/getBots/route.ts b/src/app/getBots/route.ts index cd66227..7f3f8a3 100644 --- a/src/app/getBots/route.ts +++ b/src/app/getBots/route.ts @@ -24,9 +24,22 @@ export async function GET(req: Request) { verified: true } }) - return new Response(JSON.stringify(dbFetch), { + return new Response(JSON.stringify(emptyValToNull(dbFetch)), { headers: { 'content-type': 'application/json' } }) +} + +function emptyValToNull(obj: any) { + for (const key in obj) { + if (typeof obj[key] === 'object') { + emptyValToNull(obj[key]); + } else { + if (obj[key] === '') { + obj[key] = null; + } + } + } + return obj; } \ No newline at end of file