mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
Hello airbnb
This commit is contained in:
1 parent
f9468536de
commit
8c195661d7
78 files changed
+2032
-1471
No files matched your search
+25
-27
@@ -1,26 +1,27 @@
|
||||
const
|
||||
validator = require('../lib/validator'),
|
||||
{ ValidationError, TrainingNotFoundError } = require('../error'),
|
||||
db = require('../service/db.js'),
|
||||
coll = db.collection('traning'),
|
||||
coll_status = db.collection('training.status');
|
||||
const validator = require('../lib/validator');
|
||||
const { ValidationError, TrainingNotFoundError } = require('../error');
|
||||
const db = require('../service/db.js');
|
||||
|
||||
const coll = db.collection('traning');
|
||||
const collStatus = db.collection('training.status');
|
||||
|
||||
module.exports = {
|
||||
SETTING_DIFFICULTY_ALGORITHM: 0,
|
||||
SETTING_DIFFICULTY_ADMIN: 1,
|
||||
SETTING_DIFFICULTY_AVERAGE: 2,
|
||||
|
||||
async add(title, content, owner_uid, dag = [], desc = '') {
|
||||
validator.check_title(title);
|
||||
validator.check_intro(content);
|
||||
validator.check_description(desc);
|
||||
for (let node of dag)
|
||||
for (let nid of node['require_nids'])
|
||||
if (nid >= node._id)
|
||||
throw new ValidationError('dag');
|
||||
async add(title, content, owner, dag = [], desc = '') {
|
||||
validator.checkTitle(title);
|
||||
validator.checkIntro(content);
|
||||
validator.checkDescription(desc);
|
||||
for (const node of dag) { for (const nid of node.require_nids) if (nid >= node._id) throw new ValidationError('dag'); }
|
||||
return await coll.insertOne({
|
||||
content, owner_uid,
|
||||
dag, title, desc, enroll: 0
|
||||
content,
|
||||
owner,
|
||||
dag,
|
||||
title,
|
||||
desc,
|
||||
enroll: 0,
|
||||
});
|
||||
},
|
||||
count: (query) => coll.find(query).count(),
|
||||
@@ -28,24 +29,21 @@ module.exports = {
|
||||
if ($set.title) validator.check_title($set.title);
|
||||
if ($set.content) validator.check_intro($set.content);
|
||||
if ($set.desc) validator.check_description($set.desc);
|
||||
if ($set.dag)
|
||||
for (let node of $set.dag)
|
||||
for (let nid of node.require_nids)
|
||||
if (nid >= node._id) throw new ValidationError('dag');
|
||||
if ($set.dag) { for (const node of $set.dag) for (const nid of node.require_nids) if (nid >= node._id) throw new ValidationError('dag'); }
|
||||
await coll.findOneAndUpdate({ tid }, { $set });
|
||||
let tdoc = await coll.findOne({ tid });
|
||||
const tdoc = await coll.findOne({ tid });
|
||||
if (!tdoc) throw new TrainingNotFoundError(tid);
|
||||
return tdoc;
|
||||
},
|
||||
async get(tid) {
|
||||
let tdoc = await coll.findOne({ tid });
|
||||
const tdoc = await coll.findOne({ tid });
|
||||
if (!tdoc) throw new TrainingNotFoundError(tid);
|
||||
return tdoc;
|
||||
},
|
||||
get_multi: (query) => coll.find( query),
|
||||
get_multi_status: (query) => coll_status.find(query),
|
||||
get_status: (tid, uid) => coll_status.findOne({ tid, uid }),
|
||||
set_status: (tid, uid, $set) => coll_status.findOneAndUpdate({ tid, uid }, { $set })
|
||||
get_multi: (query) => coll.find(query),
|
||||
get_multi_status: (query) => collStatus.find(query),
|
||||
get_status: (tid, uid) => collStatus.findOne({ tid, uid }),
|
||||
set_status: (tid, uid, $set) => collStatus.findOneAndUpdate({ tid, uid }, { $set }),
|
||||
|
||||
};
|
||||
|
||||
@@ -66,4 +64,4 @@ async def get_dict(domainId, tids, *, fields=None):
|
||||
fields=fields):
|
||||
result[tdoc['doc_id']] = tdoc
|
||||
return result
|
||||
*/
|
||||
*/
|
||||
Reference in new issue
Block a user