Skip to content

Commit a369575

Browse files
authored
Merge pull request #55 from OmAnand857/main
UI Enhancements and Bug Fixes for Reviews & Comments Functionality
2 parents 873a51f + e6bbdc3 commit a369575

File tree

2 files changed

+246
-74
lines changed

2 files changed

+246
-74
lines changed

src/pages/api/db/rateProfDb/index.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
2727
const reviewsRef = collection(db, COLLECTION_NAME);
2828
const docRef = await addDoc(reviewsRef, {
2929
...body,
30-
date: new Date().toISOString().split('T')[0],
30+
date: new Date().toISOString(),
3131
upvotes: 0,
3232
comments: []
3333
});
@@ -40,16 +40,18 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
4040

4141
case 'PUT':
4242
try {
43-
const body = req.body;
44-
const { id, ...updateData } = body;
45-
const reviewRef = doc(db, COLLECTION_NAME, id);
46-
47-
await updateDoc(reviewRef, {
48-
upvotes: increment(1),
49-
...updateData
50-
});
43+
const body = await req.body;
44+
const { id, userId, ...updateData } = body;
45+
if (!id) {
46+
res.status(400).json({ error: 'Review ID is required' });
47+
}
5148

52-
res.status(200).json({ success: true });
49+
if (!userId) {
50+
res.status(401).json({ error: 'User must be authenticated' });
51+
}
52+
const reviewRef = doc(db, COLLECTION_NAME, id);
53+
await updateDoc(reviewRef, updateData);
54+
res.json({ success: true, id, ...updateData });
5355
} catch (error) {
5456
console.error('Error updating review:', error);
5557
res.status(500).json({ error: 'Failed to update review' });

0 commit comments

Comments
 (0)