错误修复

This commit is contained in:
masnn committed 2020-05-29 20:00:40 +08:00
1 parent fff2172c38
commit 257d9814a9
15 files changed
+57 -63

No files matched your search

+1 -1
View File
@@ -44,7 +44,7 @@ async function dec(_id) {
return file.count;
}
async function get(_id, secret = null) {
async function get(_id, secret) {
const file = await coll.findOne({ _id });
if (typeof secret !== 'undefined') {
const timestamp = _timestamp();
+3 -7
View File
@@ -1,10 +1,8 @@
const { ObjectID } = require('bson');
const { STATUS_ACCEPTED } = require('./builtin').STATUS;
const file = require('./file');
const document = require('./document');
const domain = require('./domain');
const { ProblemNotFoundError } = require('../error');
const validator = require('../lib/validator');
/**
* @typedef {import('../interface').Pdoc} Pdoc
@@ -30,8 +28,6 @@ async function add(domainId, title, content, owner, {
tag = [],
hidden = false,
}) {
validator.checkTitle(title);
validator.checkContent(content);
const d = await domain.inc(domainId, 'pidCounter', 1);
if (!pid) pid = d.pidCounter.toString();
return await document.add(domainId, content, owner, document.TYPE_PROBLEM, d.pidCounter, null, null, {
@@ -46,7 +42,9 @@ async function add(domainId, title, content, owner, {
* @returns {Pdoc}
*/
async function get(domainId, pid, uid = null) {
const pdoc = await document.get(domainId, document.TYPE_PROBLEM, pid);
const pdoc = Number.isInteger(pid)
? await document.get(domainId, document.TYPE_PROBLEM, pid)
: (await document.getMulti(domainId, document.TYPE_PROBLEM, { pid }).toArray())[0];
if (!pdoc) throw new ProblemNotFoundError(pid);
if (uid) {
pdoc.psdoc = await document.getStatus(domainId, document.TYPE_PROBLEM, pdoc.docId, uid);
@@ -92,8 +90,6 @@ function getMultiStatus(domainId, query) {
* @returns {Pdoc}
*/
function edit(domainId, _id, $set) {
if ($set.title) validator.checkTitle($set.title);
if ($set.content) validator.checkContent($set.content);
return document.set(domainId, document.TYPE_CONTEST, _id, $set);
}
+1
View File
@@ -3,6 +3,7 @@ const db = require('../service/db');
const coll = db.collection('task');
async function add(task) {
console.log(task);
const res = await coll.insertOne(task);
return res.insertedId;
}
+4
View File
@@ -38,6 +38,10 @@ class USER {
}
async function getPerm(domainId, udoc) {
if (udoc._id === 1) { // Is Guest
const p = await document.get(domainId, document.TYPE_DOMAIN_ROLE, 'guest');
return p.content;
}
if (udoc.priv === 1) {
const p = await document.get(domainId, document.TYPE_DOMAIN_ROLE, 'admin');
return p.content;