Skip to content

Commit 6f396ae

Browse files
authored
Merge pull request #99 from techulus/develop
Fix voting update bug
2 parents 84572ed + f25344a commit 6f396ae

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

apps/page/pages/api/roadmap/vote.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import { getVisitorId } from "../../../lib/visitor-auth";
55

66
export default async function voteOnRoadmapItem(
77
req: NextApiRequest,
8-
res: NextApiResponse<{ ok: boolean; vote_count?: number; error?: string }>
8+
res: NextApiResponse<{ success: boolean; vote_count?: number; error?: string }>
99
) {
1010
if (req.method !== "POST") {
11-
return res.status(405).json({ ok: false, error: "Method not allowed" });
11+
return res.status(405).json({ success: false, error: "Method not allowed" });
1212
}
1313

1414
const { item_id } = req.body;
1515

1616
if (!item_id) {
17-
return res.status(400).json({ ok: false, error: "Missing item_id" });
17+
return res.status(400).json({ success: false, error: "Missing item_id" });
1818
}
1919

2020
const visitor_id = await getVisitorId(req);
@@ -30,7 +30,7 @@ export default async function voteOnRoadmapItem(
3030
if (itemCheckError || !itemCheck) {
3131
return res
3232
.status(404)
33-
.json({ ok: false, error: "Item not found or not public" });
33+
.json({ success: false, error: "Item not found or not public" });
3434
}
3535

3636
// Check if user has already voted
@@ -52,7 +52,7 @@ export default async function voteOnRoadmapItem(
5252
console.error("voteOnRoadmapItem [Delete Error]", deleteError);
5353
return res
5454
.status(500)
55-
.json({ ok: false, error: "Failed to remove vote" });
55+
.json({ success: false, error: "Failed to remove vote" });
5656
}
5757
} else {
5858
// Add vote
@@ -66,7 +66,7 @@ export default async function voteOnRoadmapItem(
6666

6767
if (insertError) {
6868
console.error("voteOnRoadmapItem [Insert Error]", insertError);
69-
return res.status(500).json({ ok: false, error: "Failed to add vote" });
69+
return res.status(500).json({ success: false, error: "Failed to add vote" });
7070
}
7171
}
7272

@@ -81,11 +81,11 @@ export default async function voteOnRoadmapItem(
8181
}
8282

8383
res.status(200).json({
84-
ok: true,
84+
success: true,
8585
vote_count: count || 0,
8686
});
8787
} catch (e: Error | any) {
8888
console.log("voteOnRoadmapItem [Error]", e);
89-
res.status(500).json({ ok: false, error: "Internal server error" });
89+
res.status(500).json({ success: false, error: "Internal server error" });
9090
}
9191
}

apps/page/pages/api/roadmap/votes.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { NextApiRequest, NextApiResponse } from "next";
33
import { v4 } from "uuid";
44

55
type BulkVotesResponse = {
6-
ok: boolean;
6+
success: boolean;
77
votes: Record<string, { vote_count: number; user_voted: boolean }>;
88
};
99

@@ -18,31 +18,31 @@ export default async function getBulkRoadmapItemVotes(
1818
// Validate HTTP method
1919
if (req.method !== "POST") {
2020
res.setHeader("Allow", "POST");
21-
return res.status(405).json({ ok: false, votes: {} });
21+
return res.status(405).json({ success: false, votes: {} });
2222
}
2323

2424
const { item_ids } = req.body;
2525
let { cp_pa_vid: visitor_id } = req.cookies;
2626

2727
// Input validation
2828
if (!item_ids || !Array.isArray(item_ids)) {
29-
return res.status(400).json({ ok: false, votes: {} });
29+
return res.status(400).json({ success: false, votes: {} });
3030
}
3131

3232
// Prevent abuse with max array length
3333
if (item_ids.length > 100) {
34-
return res.status(400).json({ ok: false, votes: {} });
34+
return res.status(400).json({ success: false, votes: {} });
3535
}
3636

3737
// Validate all item_ids are valid UUIDs
3838
if (!item_ids.every((id) => typeof id === "string" && UUID_REGEX.test(id))) {
39-
return res.status(400).json({ ok: false, votes: {} });
39+
return res.status(400).json({ success: false, votes: {} });
4040
}
4141

4242
// De-duplicate to keep queries lean
4343
const distinctItemIds: string[] = Array.from(new Set(item_ids));
4444
if (distinctItemIds.length === 0) {
45-
return res.status(200).json({ ok: true, votes: {} });
45+
return res.status(200).json({ success: true, votes: {} });
4646
}
4747

4848
if (!visitor_id) {
@@ -76,7 +76,7 @@ export default async function getBulkRoadmapItemVotes(
7676
"getBulkRoadmapItemVotes [User Error]",
7777
userVoteResult.error
7878
);
79-
return res.status(500).json({ ok: false, votes: {} });
79+
return res.status(500).json({ success: false, votes: {} });
8080
}
8181

8282
// Check for any errors in vote count queries
@@ -87,7 +87,7 @@ export default async function getBulkRoadmapItemVotes(
8787
distinctItemIds[i],
8888
voteCountResults[i].error
8989
);
90-
return res.status(500).json({ ok: false, votes: {} });
90+
return res.status(500).json({ success: false, votes: {} });
9191
}
9292
}
9393

@@ -111,11 +111,11 @@ export default async function getBulkRoadmapItemVotes(
111111
});
112112

113113
res.status(200).json({
114-
ok: true,
114+
success: true,
115115
votes,
116116
});
117117
} catch (e: Error | any) {
118118
console.log("getBulkRoadmapItemVotes [Error]", e);
119-
res.status(500).json({ ok: false, votes: {} });
119+
res.status(500).json({ success: false, votes: {} });
120120
}
121121
}

0 commit comments

Comments
 (0)