2 Star 5 Fork 0

ang / latte

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
model.js 1.88 KB
一键复制 编辑 原始数据 按行查看 历史
ang 提交于 2023-05-03 20:14 . 20230503
// Latte forum model base on MongoDB
// for CREATE operation ,when input unvailied throw exception
function Factory(){
this.post = function(ownner=null,title='',content='',topic='',nickname='',tags=[],replies=[],date=new Date(),edited_date=null,viewed=0,reply_n=0,star=0,hidden=false){
if(!ownner){
throw 'latte: need set ownner'
}else{
title = title.slice(0,60);
content = content.slice(0,5500);
return {
ownner,title,content,topic,nickname,tags,replies,date,edited_date,viewed,reply_n,star,hidden
}
}
};
this.reply = function(ownner=null,content='',post_id=null,nickname='',discuz=[],date=new Date(),hidden=false){
if(!ownner || !post_id || !content){
throw 'latte: need set ownner'
}else{
content = content.slice(0,750);
return {
ownner,content,post_id,nickname,discuz,date,hidden
}
}
};
this.user = function(account='',pwd='',nickname='',email='',avatar='',posts=[],replies=[],star_list=[],group=100,date=new Date(),near_login=null,hidden=false){
if(account&&pwd){
if(account.length>50 || pwd.length>50){
throw 'Latte : account or password too long'
}else if( account.length<5 || pwd.length<5 ){
throw 'Latte : account or passsword too short'
}else{
email = email.slice(0,60);
avatar = avatar.slice(0,500);
nickname = nickname.slice(0,60);
if(!nickname){ nickname = 'someone'};
return {
account,pwd,nickname,email,avatar,posts,replies,star_list,group,date,near_login,hidden
}
}
}else{
throw 'Latte: need set account and pwd'
}
};
};
module.exports = new Factory()
NodeJS
1
https://gitee.com/ang111/latte.git
git@gitee.com:ang111/latte.git
ang111
latte
latte
master

搜索帮助