修复在线IDE

This commit is contained in:
masnn committed 2020-04-17 18:09:41 +08:00
1 parent b1153b641a
commit 61cba6f180
12 files changed
+94 -76

No files matched your search

+5 -2
View File
@@ -1,4 +1,5 @@
const db = require('../service/db.js');
const { ValidationError } = require('../error');
const coll = db.collection('token');
@@ -33,8 +34,10 @@ module.exports = {
* @param {number} tokenType type of the token.
* @returns {object} The token document, or null.
*/
get(tokenId, tokenType) {
return coll.findOne({ _id: tokenId, tokenType });
async get(tokenId, tokenType) {
const res = await coll.findOne({ _id: tokenId, tokenType });
if (!res) throw new ValidationError('token');
return res;
},
/**
+8 -2
View File
@@ -13,9 +13,9 @@ function getMultiStatus(query) {
return collStatus.find(query);
}
async function getListStatus(uid, tids) {
const psdocs = await getMultiStatus({ uid, pid: { $in: Array.from(new Set(tids)) } }).toArray();
const tsdocs = await getMultiStatus({ uid, tid: { $in: Array.from(new Set(tids)) } }).toArray();
const r = {};
for (const psdoc of psdocs) r[psdoc.pid] = psdoc;
for (const tsdoc of tsdocs) r[tsdoc.pid] = tsdoc;
return r;
}
async function enroll(tid, uid) {
@@ -104,6 +104,12 @@ module.exports = {
if (!tdoc) throw new TrainingNotFoundError(tid);
return tdoc;
},
async getList(tids) {
const tdocs = await this.getMulti({ _id: { $in: Array.from(new Set(tids)) } }).toArray();
const r = {};
for (const tdoc of tdocs) r[tdoc._id] = tdoc;
return r;
},
getMulti: (query) => coll.find(query),
getMultiStatus,
getStatus,