You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constexistingVote=awaitprivateDB.prepare("get",`SELECT "UUID", "type" from "casualVotes" WHERE "videoID" = ? AND "service" = ? AND "userID" = ? AND category = ?`,[videoID,service,hashedUserID,category])asExistingVote;
constexistingVote=awaitprivateDB.prepare("get",`SELECT "UUID"from "casualVotes" WHERE "videoID" = ? AND "service" = ? AND "userID" = ? AND "category" = ?`,[videoID,service,hashedUserID,category])asExistingVote;
90
83
if(existingVote){
91
-
if(existingVote.type===voteType){
92
-
returntrue;
93
-
}
94
-
95
-
if(existingVote.type===CasualVoteType.Upvote){
96
-
awaitdb.prepare("run",`UPDATE "casualVotes" SET "upvotes" = "upvotes" - 1 WHERE "UUID" = ?`,[UUID]);
84
+
returntrue;
85
+
}else{
86
+
if(downvote){
87
+
// Remove upvotes for all categories on this video
88
+
constexistingUpvotes=awaitprivateDB.prepare("all",`SELECT "category" from "casualVotes" WHERE "category" != 'downvote' AND "videoID" = ? AND "service" = ? AND "userID" = ?`,[videoID,service,hashedUserID]);
89
+
for(constexistingUpvoteofexistingUpvotes){
90
+
awaitdb.prepare("run",`UPDATE "casualVotes" SET "upvotes" = "upvotes" - 1 WHERE "videoID" = ? AND "category" = ?`,[videoID,existingUpvote.category]);
91
+
awaitprivateDB.prepare("run",`DELETE FROM "casualVotes" WHERE "videoID" = ? AND "userID" = ? AND "category" = ?`,[videoID,hashedUserID,existingUpvote.category]);
92
+
}
97
93
}else{
98
-
awaitdb.prepare("run",`UPDATE "casualVotes" SET "downvotes" = "downvotes" - 1 WHERE "UUID" = ?`,[UUID]);
94
+
// Undo a downvote if it exists
95
+
constexistingDownvote=awaitprivateDB.prepare("get",`SELECT "UUID" from "casualVotes" WHERE "category" = 'downvote' AND "videoID" = ? AND "service" = ? AND "userID" = ?`,[videoID,service,hashedUserID])asExistingVote;
96
+
if(existingDownvote){
97
+
awaitdb.prepare("run",`UPDATE "casualVotes" SET "upvotes" = "upvotes" - 1 WHERE "category" = 'downvote' AND "videoID" = ?`,[videoID]);
98
+
awaitprivateDB.prepare("run",`DELETE FROM "casualVotes" WHERE "category" = 'downvote' AND "videoID" = ? AND "userID" = ?`,[videoID,hashedUserID]);
99
+
}
99
100
}
100
-
101
-
awaitprivateDB.prepare("run",`DELETE FROM "casualVotes" WHERE "UUID" = ?`,[existingVote.UUID]);
Copy file name to clipboardExpand all lines: test/cases/postCasual.ts
+63-27Lines changed: 63 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ describe("postCasual", () => {
16
16
data
17
17
});
18
18
19
-
constqueryCasualVotesByVideo=(videoID: string,all=false)=>db.prepare(all ? "all" : "get",`SELECT * FROM "casualVotes" WHERE "videoID" = ? ORDER BY "timeSubmitted" DESC`,[videoID]);
19
+
constqueryCasualVotesByVideo=(videoID: string,all=false)=>db.prepare(all ? "all" : "get",`SELECT * FROM "casualVotes" WHERE "videoID" = ? ORDER BY "timeSubmitted" ASC`,[videoID]);
0 commit comments