bukopin-redemption-client-r.../src/common/stores/employee.js
Rifqy Zacky Ariadhy 1a000700e6 Initial commit
2019-01-02 18:39:53 +07:00

43 lines
821 B
JavaScript

import { observable, action, computed } from 'mobx';
export default class EmployeeStore {
@observable employees = [];
@observable selectedEmployee = {};
@observable isLoading = false;
@observable newEmployee = {};
constructor(context) {
this.http = context.http;
this.context = context;
}
@action
getAll() {
this.isLoading = true;
return this.http.get("employees")
.then(res => {
this.isLoading = false;
this.employees = res;
})
.catch(err => {
this.isLoading = false;
throw err;
})
}
@action
create(data) {
this.isLoading = true;
return this.http.post("employees", data)
.then(res => {
this.isLoading = false;
})
.catch(err => {
this.isLoading = false;
});
}
}