Skip to content

Commit 2d79791

Browse files
committed
core: check solution existance before vote
1 parent 10d90b5 commit 2d79791

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

packages/hydrooj/src/model/solution.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class SolutionModel {
7070
}
7171

7272
static async vote(domainId: string, psid: ObjectId, uid: number, value: number) {
73+
const doc = await document.get(domainId, document.TYPE_PROBLEM_SOLUTION, psid);
74+
if (!doc) throw new SolutionNotFoundError(domainId, psid);
7375
const before = await document.setStatus(
7476
domainId, document.TYPE_PROBLEM_SOLUTION, psid, uid,
7577
{ vote: value }, 'before',
@@ -79,7 +81,7 @@ class SolutionModel {
7981
return [
8082
inc
8183
? await document.inc(domainId, document.TYPE_PROBLEM_SOLUTION, psid, 'vote', inc)
82-
: await document.get(domainId, document.TYPE_PROBLEM_SOLUTION, psid),
84+
: doc,
8385
await document.getStatus(domainId, document.TYPE_PROBLEM_SOLUTION, psid, uid),
8486
];
8587
}

0 commit comments

Comments
 (0)