Ai
2 Star 0 Fork 0

hashplus/ACdream

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
contest.js 3.49 KB
一键复制 编辑 原始数据 按行查看 历史
kidx 提交于 2014-06-06 11:07 +08:00 . models代码规范化
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var settings = require('../settings');
var pageNum = settings.contest_pageNum;
var OE = settings.outputErr;
function Contest(contest) {
this.contestID = contest.contestID;
this.userName = contest.userName,
this.title = contest.title;
this.startTime = contest.startTime;
this.len = contest.len;
this.penalty = contest.penalty;
this.description = contest.description;
this.msg = contest.msg;
this.probs = contest.probs;
this.password = contest.password;
this.type = contest.type;
};
module.exports = Contest;
var contestObj = new Schema({
contestID: {type: Number, index: {unique: true}},
userName: String,
title: String,
startTime: Number,
len: Number,
description: String,
msg: String,
probs: Array,
password: String,
type: Number,
contestants: Array,
stars: Array,
updateTime: Number,
maxRunID: Number,
penalty: Number,
FB: Object
});
mongoose.model('contests', contestObj);
var contests = mongoose.model('contests');
Contest.prototype.save = function(callback) {
contest = new contests();
contest.contestID = this.contestID;
contest.userName = this.userName;
contest.title = this.title;
contest.startTime = this.startTime;
contest.len = this.len;
contest.penalty = this.penalty;
contest.description = this.description;
contest.msg = this.msg;
contest.probs = this.probs;
contest.password = this.password;
contest.type = this.type;
contest.contestants = new Array();
contest.stars = new Array();
contest.updateTime = 0;
contest.maxRunID = 0;
contest.save(function(err){
if (err) {
OE('Contest.save failed!');
}
return callback(err);
});
};
Contest.find = function(Q, callback) {
contests.find(Q, function(err, docs){
if (err) {
OE('Contest.find failed!');
}
return callback(err, docs);
});
};
Contest.get = function(Q, page, callback) {
contests.count(Q, function(err, count){
if ((page-1)*pageNum > count) {
return callback(null, null, -1);
}
contests.find(Q).sort({startTime:-1, contestID:-1}).skip((page-1)*pageNum)
.limit(pageNum).exec(function(err, docs){
if (err) {
OE('Contest.get failed!');
}
return callback(err, docs, parseInt((count+pageNum-1)/pageNum, 10));
});
});
};
Contest.watch = function(cid, callback) {
contests.findOne({contestID:cid}, function(err, doc){
if (err) {
OE('Contest.watch failed!');
}
return callback(err, doc);
});
};
Contest.findOneAndUpdate = function(Q, H, O, callback) {
contests.findOneAndUpdate(Q, H, O, function(err, doc){
if (err) {
OE('Contest.findOneAndUpdate failed!');
}
return callback(err, doc);
});
};
Contest.update = function(cid, H, callback) {
contests.update({contestID:cid}, H, function(err){
if (err) {
OE('Contest.update failed!');
}
return callback(err);
});
};
Contest.multiUpdate = function(Q, H, callback) {
contests.update(Q, H, {multi: true}, function(err){
if (err) {
OE('Contest.multiUpdate failed!');
}
return callback(err);
});
};
Contest.remove = function(cid, callback) {
contests.remove({contestID: cid}, function(err){
if (err) {
OE('Contest.remove failed!');
}
return callback(err);
});
};
Contest.topFive = function(Q, callback) {
contests.find(Q).sort({startTime:-1, contestID: -1})
.limit(5).exec(function(err, docs){
if (err) {
OE('Contest.topFive failed!');
}
return callback(err, docs);
});
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hashplus/ACdream.git
git@gitee.com:hashplus/ACdream.git
hashplus
ACdream
ACdream
master

搜索帮助