mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: check solution existance before vote
This commit is contained in:
1 file changed
+3
-1
@@ -70,6 +70,8 @@ class SolutionModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async vote(domainId: string, psid: ObjectId, uid: number, value: number) {
|
static async vote(domainId: string, psid: ObjectId, uid: number, value: number) {
|
||||||
|
const doc = await document.get(domainId, document.TYPE_PROBLEM_SOLUTION, psid);
|
||||||
|
if (!doc) throw new SolutionNotFoundError(domainId, psid);
|
||||||
const before = await document.setStatus(
|
const before = await document.setStatus(
|
||||||
domainId, document.TYPE_PROBLEM_SOLUTION, psid, uid,
|
domainId, document.TYPE_PROBLEM_SOLUTION, psid, uid,
|
||||||
{ vote: value }, 'before',
|
{ vote: value }, 'before',
|
||||||
@@ -79,7 +81,7 @@ class SolutionModel {
|
|||||||
return [
|
return [
|
||||||
inc
|
inc
|
||||||
? await document.inc(domainId, document.TYPE_PROBLEM_SOLUTION, psid, 'vote', inc)
|
? await document.inc(domainId, document.TYPE_PROBLEM_SOLUTION, psid, 'vote', inc)
|
||||||
: await document.get(domainId, document.TYPE_PROBLEM_SOLUTION, psid),
|
: doc,
|
||||||
await document.getStatus(domainId, document.TYPE_PROBLEM_SOLUTION, psid, uid),
|
await document.getStatus(domainId, document.TYPE_PROBLEM_SOLUTION, psid, uid),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user