From 8ccff82fd3a8638b589dd3944f2932f2324fc034 Mon Sep 17 00:00:00 2001
From: bytedream <bytedream@protonmail.com>
Date: Sat, 23 Dec 2023 14:15:29 +0100
Subject: [PATCH] fix uncaught null return on user info database query

---
 src/routes/api/user/+server.ts | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/routes/api/user/+server.ts b/src/routes/api/user/+server.ts
index 98f737d..829d2c0 100644
--- a/src/routes/api/user/+server.ts
+++ b/src/routes/api/user/+server.ts
@@ -20,18 +20,18 @@ export const GET = (async ({ url }) => {
 			'striked_at'
 		],
 		include: { model: StrikeReason, as: 'strike_reason' }
-	})) as { dataValues: { weight: number; striked_at: Date } } | null;
+	})) as { weight: number | null; striked_at: Date | null } | null;
 	const ban_time = (
 		await StrikePunishment.findOne({
 			attributes: ['punishment_in_seconds'],
-			where: { type: ['ban'], weight: { [Op.lte]: query?.dataValues.weight } },
+			where: { type: ['ban'], weight: { [Op.lte]: query?.weight } },
 			order: [['weight', 'DESC']]
 		})
 	)?.punishment_in_seconds;
 	const outlawed_time = (
 		await StrikePunishment.findOne({
 			attributes: ['punishment_in_seconds'],
-			where: { type: ['outlawed'], weight: { [Op.lte]: query?.dataValues.weight } },
+			where: { type: ['outlawed'], weight: { [Op.lte]: query?.weight } },
 			order: [['weight', 'DESC']]
 		})
 	)?.punishment_in_seconds;
@@ -43,12 +43,12 @@ export const GET = (async ({ url }) => {
 			firstname: user.firstname,
 			lastname: user.lastname,
 			banned_until:
-				query && ban_time
-					? Math.round(query.dataValues.striked_at.getTime() / 1000 + ban_time!)
+				query && query.striked_at && ban_time
+					? Math.round(query.striked_at.getTime() / 1000 + ban_time!)
 					: null,
 			outlawed_until:
-				query && outlawed_time
-					? Math.round(query.dataValues.striked_at.getTime() / 1000 + outlawed_time!)
+				query && query.striked_at && outlawed_time
+					? Math.round(query.striked_at.getTime() / 1000 + outlawed_time!)
 					: null
 		}),
 		{ status: 200 }