mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
Hello airbnb
This commit is contained in:
1 parent
f9468536de
commit
8c195661d7
78 files changed
+2032
-1471
No files matched your search
+27
-26
@@ -1,13 +1,13 @@
|
||||
const
|
||||
_ = require('lodash'),
|
||||
{ ObjectID } = require('bson'),
|
||||
{ RecordNotFoundError } = require('../error'),
|
||||
{ STATUS_WAITING } = require('../model/builtin').STATUS,
|
||||
db = require('../service/db.js'),
|
||||
coll = db.collection('record');
|
||||
const _ = require('lodash');
|
||||
const { ObjectID } = require('bson');
|
||||
const { RecordNotFoundError } = require('../error');
|
||||
const { STATUS_WAITING } = require('./builtin').STATUS;
|
||||
const db = require('../service/db.js');
|
||||
|
||||
const coll = db.collection('record');
|
||||
|
||||
/**
|
||||
* @param {import('../interface').Record} data
|
||||
* @param {import('../interface').Record} data
|
||||
*/
|
||||
async function add(data) {
|
||||
_.defaults(data, {
|
||||
@@ -20,33 +20,34 @@ async function add(data) {
|
||||
compilerTexts: [],
|
||||
testCases: [],
|
||||
judger: null,
|
||||
judgeAt: null
|
||||
judgeAt: null,
|
||||
});
|
||||
let res = await coll.insertOne(data);
|
||||
const res = await coll.insertOne(data);
|
||||
return res.insertedId;
|
||||
}
|
||||
/**
|
||||
* @param {string} rid
|
||||
* @param {string} rid
|
||||
* @returns {import('../interface').Record}
|
||||
*/
|
||||
async function get(rid) {
|
||||
let _id = new ObjectID(rid);
|
||||
let rdoc = await coll.findOne({ _id });
|
||||
const _id = new ObjectID(rid);
|
||||
const rdoc = await coll.findOne({ _id });
|
||||
if (!rdoc) throw new RecordNotFoundError(rid);
|
||||
return rdoc;
|
||||
}
|
||||
async function getMany(query, sort, page, limit) {
|
||||
return await coll.find(query).sort(sort).skip((page - 1) * limit).limit(limit).toArray();
|
||||
function getMany(query, sort, page, limit) {
|
||||
return coll.find(query).sort(sort).skip((page - 1) * limit).limit(limit)
|
||||
.toArray();
|
||||
}
|
||||
async function update(rid, $set) {
|
||||
let _id = new ObjectID(rid);
|
||||
const _id = new ObjectID(rid);
|
||||
await coll.findOneAndUpdate({ _id }, { $set });
|
||||
let rdoc = await coll.findOne({ _id });
|
||||
const rdoc = await coll.findOne({ _id });
|
||||
if (!rdoc) throw new RecordNotFoundError(rid);
|
||||
return rdoc;
|
||||
}
|
||||
async function reset(rid) {
|
||||
return await update(rid, {
|
||||
function reset(rid) {
|
||||
return update(rid, {
|
||||
score: 0,
|
||||
status: STATUS_WAITING,
|
||||
time: 0,
|
||||
@@ -56,15 +57,15 @@ async function reset(rid) {
|
||||
compilerTexts: [],
|
||||
judgeAt: null,
|
||||
judger: null,
|
||||
rejudged: true
|
||||
rejudged: true,
|
||||
});
|
||||
}
|
||||
async function count(query) {
|
||||
return await coll.find(query).count();
|
||||
function count(query) {
|
||||
return coll.find(query).count();
|
||||
}
|
||||
async function getList(rids) {
|
||||
let r = {};
|
||||
for (let rid of rids) r[rid] = await get(rid);
|
||||
const r = {};
|
||||
for (const rid of rids) r[rid] = await get(rid); // eslint-disable-line no-await-in-loop
|
||||
return r;
|
||||
}
|
||||
function getUserInProblemMulti(uid, pid) {
|
||||
@@ -79,5 +80,5 @@ module.exports = {
|
||||
count,
|
||||
reset,
|
||||
getList,
|
||||
getUserInProblemMulti
|
||||
};
|
||||
getUserInProblemMulti,
|
||||
};
|
||||
Reference in new issue
Block a user