yapi/server/models/group.js

51 lines
1.0 KiB
JavaScript
Raw Normal View History

import yapi from '../yapi.js'
import mongoose from 'mongoose'
import baseModel from './base.js'
class groupModel extends baseModel{
getName(){
return 'group'
}
2017-07-04 17:19:20 +08:00
getSchema(){
return {
2017-07-06 19:21:54 +08:00
uid: Number,
group_name: String,
group_desc: String,
add_time: Number,
up_time: Number
}
}
save(data) {
let m = new this.model(data);
2017-07-04 17:19:20 +08:00
return m.save();
}
checkRepeat(name) {
return this.model.count({
2017-07-04 17:19:20 +08:00
group_name: name
})
}
list(){
return this.model.find().select("group_name _id group_desc add_time up_time").exec()
}
del (id) {
return this.model.deleteOne({
2017-07-04 17:19:20 +08:00
_id: id
})
}
up (id, data) {
return this.model.update({
2017-07-04 17:19:20 +08:00
_id: id,
}, {
group_name: data.group_name,
group_desc: data.group_desc,
up_time: yapi.commons.time()
})
}
}
module.exports= groupModel