2018-05-28 22:37:09 +00:00
|
|
|
import { Collection, Model } from 'vue-mc';
|
2018-05-28 19:48:42 +00:00
|
|
|
import JwtDecode from 'jwt-decode';
|
|
|
|
|
2018-05-28 22:37:09 +00:00
|
|
|
export class User extends Model {
|
|
|
|
static defaults() {
|
|
|
|
return {
|
|
|
|
id: null,
|
|
|
|
uuid: '',
|
|
|
|
username: '',
|
|
|
|
email: '',
|
|
|
|
name_first: '',
|
|
|
|
name_last: '',
|
|
|
|
language: 'en',
|
|
|
|
root_admin: false,
|
|
|
|
}
|
|
|
|
}
|
2018-05-28 19:48:42 +00:00
|
|
|
|
2018-05-28 22:37:09 +00:00
|
|
|
static mutations() {
|
|
|
|
return {
|
|
|
|
id: Number,
|
|
|
|
uuid: String,
|
|
|
|
username: String,
|
|
|
|
email: String,
|
|
|
|
name_first: String,
|
|
|
|
name_last: String,
|
|
|
|
language: String,
|
|
|
|
root_admin: Boolean,
|
|
|
|
}
|
|
|
|
}
|
2018-05-28 19:48:42 +00:00
|
|
|
|
2018-05-28 22:37:09 +00:00
|
|
|
static fromJWT(token) {
|
|
|
|
return new User(JwtDecode(token).user || {});
|
|
|
|
}
|
|
|
|
}
|
2018-05-28 19:48:42 +00:00
|
|
|
|
2018-05-28 22:37:09 +00:00
|
|
|
export class UserCollection extends Collection {
|
|
|
|
static model() {
|
|
|
|
return User;
|
|
|
|
}
|
2018-05-28 19:48:42 +00:00
|
|
|
|
2018-05-28 22:37:09 +00:00
|
|
|
get todo() {
|
|
|
|
return this.sum('done');
|
|
|
|
}
|
|
|
|
|
|
|
|
get done() {
|
|
|
|
return this.todo === 0;
|
|
|
|
}
|
|
|
|
}
|