This commit is contained in:
2021-12-17 14:22:20 +07:00
4 changed files with 63 additions and 46 deletions

View File

@@ -1,50 +1,52 @@
import {makeAutoObservable} from "mobx";
import {http} from "../utils/http";
import { makeAutoObservable } from "mobx";
import { http } from "../utils/http";
export class Role {
page = null;
pageSize = null;
data = [];
total_data = 0
page = null;
pageSize = null;
data = [];
total_data = 0;
constructor(ctx) {
this.ctx = ctx;
makeAutoObservable(this);
}
constructor(ctx) {
this.ctx = ctx;
makeAutoObservable(this);
}
async getData() {
try {
const response = await http.get(`/config/roles?page=${this.page}&pageSize=${this.pageSize}`);
this.data = response.body.data ?? []
this.total_data = response.body.total_data ?? 0
} catch (e) {
console.error(e);
}
async getData(isForMembership = false) {
try {
const response = await http.get(
`/config/roles${isForMembership ? "/for-membership" : ""}?page=${
this.page
}&pageSize=${this.pageSize}`
);
this.data = response.body.data ?? [];
this.total_data = response.body.total_data ?? 0;
} catch (e) {
console.error(e);
}
}
async create(data) {
try {
return await http.post('/users').send(data)
} catch (e) {
console.error(e);
}
async create(data) {
try {
return await http.post("/users").send(data);
} catch (e) {
console.error(e);
}
}
async update(id, data) {
try {
return await http.put('/users/' + id).send(data);
} catch (e) {
console.error(e);
}
async update(id, data) {
try {
return await http.put("/users/" + id).send(data);
} catch (e) {
console.error(e);
}
}
async delete(id) {
try {
return await http.del('/users/' + id);
} catch (e) {
console.error(e);
}
async delete(id) {
try {
return await http.del("/users/" + id);
} catch (e) {
console.error(e);
}
}
}