ice-frontend-react-mobx
Version:
ICE Frontend REACT+MobX
72 lines (59 loc) • 1.42 kB
JavaScript
import { observable, computed } from 'mobx';
export default class User {
_id = null;
active = true;
firstName = '';
lastName = '';
email = '';
phoneNumber = '';
roles = [];
logins = [];
password = '';
oldPassword = '';
store = null;
constructor (store) {
this.store = store;
}
get id () {
return this._id;
}
get fullName () {
return this.firstName + ' ' + this.lastName;
}
get toJson () {
let user = {
active: this.active,
firstName: this.firstName,
lastName: this.lastName,
email: this.email,
phoneNumber: this.phoneNumber,
roles: this.roles
};
if (this.id) {
user.id = this.id;
}
if (this.password) {
user.password = this.password;
}
if (this.oldPassword) {
user.oldpassword = this.oldPassword;
}
return user;
}
updateFromJson (json) {
this._id = json.id;
this.active = json.active || true;
this.firstName = json.firstName || '';
this.lastName = json.lastName || '';
this.email = json.email || '';
this.phoneNumber = json.phoneNumber || '';
this.roles = json.roles || [];
this.logins = json.lastLoginDate || [];
}
save () {
return this.store.save(this.toJson);
}
delete () {
return this.store.delete(this.id);
}
}