core: check solution existance before vote

This commit is contained in:
undefined committed 2025-07-18 11:56:29 +08:00
1 parent 10d90b5ede
commit 2d7979105e
1 file changed
+3 -1
+3 -1
View File
@@ -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),
]; ];
} }