MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / vote

Method vote

packages/hydrooj/src/model/solution.ts:72–84  ·  view source on GitHub ↗
(domainId: string, psid: ObjectId, uid: number, value: number)

Source from the content-addressed store, hash-verified

70 }
71
72 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);
75 const before = await document.setStatus(
76 domainId, document.TYPE_PROBLEM_SOLUTION, psid, uid,
77 { vote: value }, null, 'before',
78 );
79 let inc = value;
80 if (before?.vote) inc -= before.vote;
81 return inc
82 ? await document.inc(domainId, document.TYPE_PROBLEM_SOLUTION, psid, 'vote', inc)
83 : doc;
84 }
85
86 static async getListStatus(domainId: string, psids: ObjectId[], uid: number) {
87 const result: Record<string, { docId: ObjectId, vote: number }> = {};

Callers 2

postUpvoteMethod · 0.80
postDownvoteMethod · 0.80

Calls 3

setStatusMethod · 0.80
getMethod · 0.45
incMethod · 0.45

Tested by

no test coverage detected