From 2d7979105eb0d45655e22cac0a6ace99bcb4169b Mon Sep 17 00:00:00 2001 From: undefined Date: Fri, 18 Jul 2025 11:56:29 +0800 Subject: [PATCH] core: check solution existance before vote --- packages/hydrooj/src/model/solution.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/hydrooj/src/model/solution.ts b/packages/hydrooj/src/model/solution.ts index fee847c7a..665e7dd29 100644 --- a/packages/hydrooj/src/model/solution.ts +++ b/packages/hydrooj/src/model/solution.ts @@ -70,6 +70,8 @@ class SolutionModel { } 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( domainId, document.TYPE_PROBLEM_SOLUTION, psid, uid, { vote: value }, 'before', @@ -79,7 +81,7 @@ class SolutionModel { return [ 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), ]; }