Skip to content

Commit 8f2d66c

Browse files
committed
prod explore page issue..
1 parent bea250e commit 8f2d66c

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1+
'use server';
12
import { getUser } from '@/actions/user/authed/get-user';
23
import { prisma } from '@/lib/prisma';
34

45
/**
5-
* Get's the answer for a given question uid
6+
* Gets the answer for a given question uid
67
* and user uid
78
*
8-
* @param opts
9-
* @returns
9+
* @param opts - Options containing the questionUid
10+
* @returns - The user's answer or null if not found
1011
*/
1112
export const getUserAnswer = async (opts: { questionUid: string }) => {
1213
const { questionUid } = opts;
1314

1415
const user = await getUser();
1516

1617
if (!user) {
17-
return false;
18+
return null; // Return null instead of false for better type consistency
1819
}
1920

20-
// find the answer to the question
21-
return await prisma.answers.findFirst({
22-
where: {
23-
questionUid,
24-
userUid: user?.uid,
25-
},
26-
});
21+
try {
22+
// Find the answer to the question
23+
return await prisma.answers.findFirst({
24+
where: {
25+
questionUid,
26+
userUid: user.uid, // user?.uid is unnecessary since we check for user existence
27+
},
28+
});
29+
} catch (error) {
30+
console.error('Error fetching user answer:', error);
31+
throw new Error('Could not fetch user answer. Please try again later.'); // Handle the error gracefully
32+
}
2733
};

0 commit comments

Comments
 (0)