mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
训练(题单)功能
This commit is contained in:
1 parent
e06283c0cc
commit
97b0d782b9
24 files changed
+466
-105
No files matched your search
+16
-1
@@ -56,7 +56,7 @@ async function add({
|
||||
async function get(pid, uid = null) {
|
||||
let query = {};
|
||||
if (pid.generationTime || pid.length === 24) query = { _id: new ObjectID(pid) };
|
||||
else query = { pid: parseInt(pid) || pid };
|
||||
else query = { pid };
|
||||
const pdoc = await coll.findOne(query);
|
||||
if (!pdoc) throw new ProblemNotFoundError(pid);
|
||||
if (uid) {
|
||||
@@ -91,6 +91,13 @@ function getMany(query, sort, page, limit) {
|
||||
function getMulti(query) {
|
||||
return coll.find(query);
|
||||
}
|
||||
/**
|
||||
* @param {object} query
|
||||
* @returns {Cursor}
|
||||
*/
|
||||
function getMultiStatus(query) {
|
||||
return collStatus.find(query);
|
||||
}
|
||||
/**
|
||||
* @param {ObjectID} _id
|
||||
* @param {object} query
|
||||
@@ -120,6 +127,12 @@ async function getList(pids) {
|
||||
for (const pid of pids) r[pid] = await get(pid); // eslint-disable-line no-await-in-loop
|
||||
return r;
|
||||
}
|
||||
async function getListStatus(uid, pids) {
|
||||
const psdocs = await getMultiStatus({ uid, pid: { $in: Array.from(new Set(pids)) } }).toArray();
|
||||
const r = {};
|
||||
for (const psdoc of psdocs) r[psdoc.pid] = psdoc;
|
||||
return r;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
add,
|
||||
@@ -131,4 +144,6 @@ module.exports = {
|
||||
getById,
|
||||
getMulti,
|
||||
getList,
|
||||
getListStatus,
|
||||
getMultiStatus,
|
||||
};
|
||||
Reference in new issue
Block a user