You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.0 KiB

const AV = require('../lib/av-live-query-weapp-min');
const Presence = require("./presence")
class Class extends AV.Object{
get name(){
return this.get("name");
}
set name(value){
this.set("name", value);
}
get students(){
return this.get("students");
}
add_student(user){
this.addUnique("students", user.id);
}
del_student(user){
let students = this.get("students");
if(user.id in students){
this.remove(user.id);
}
}
static all() {
var query = new AV.Query("Class_");
return query.find();
}
enter() {
this.leave();
this._presence = new Presence({
user: AV.User.current(),
class: this
});
this._presence.save();
}
leave() {
if (this._presence != null) {
this._presence.destroy();
}
}
present_students() {
var query = new AV.Query("Presence");
//query.equalTo("class", this._class.id);
let students = query.find();
console.log(students);
return students;
}
}
AV.Object.register(Class, "Class_");
module.exports = Class;