feat: adding try catch

This commit is contained in:
caturbgs 2021-12-16 22:40:21 +07:00
parent 2acf3c9d5e
commit a62315641a
11 changed files with 385 additions and 194 deletions

View File

@ -56,7 +56,6 @@ export class Authentication {
this.profileData = response.body; this.profileData = response.body;
} catch (e) { } catch (e) {
console.error(e); console.error(e);
throw e;
} }
} }

View File

@ -20,55 +20,78 @@ export class Category {
} }
async getData() { async getData() {
const response = await http.get(`/product/categories?page=${this.page}&pageSize=${this.pageSize}`); try {
this.data = response.body.data.map((item, idx) => { const response = await http.get(`/product/categories?page=${this.page}&pageSize=${this.pageSize}`);
this.data = response.body.data .map((item, idx) => {
item.key = idx; item.key = idx;
return item return item
}) ?? [] }) ?? []
this.total_data = response.body.total_data ?? 0
this.total_data = response.body.total_data ?? 0 } catch (e) {
console.log(e);
}
} }
async getDataSubCategories() { async getDataSubCategories() {
const response = await http.get(`/product/sub-categories?page=${this.pageSubCategories}&pageSize=${this.pageSizeSubCategories}`); try {
this.dataSubCategories = response.body.data.map((item, idx) => { const response = await http.get(`/product/sub-categories?page=${this.pageSubCategories}&pageSize=${this.pageSizeSubCategories}`);
this.dataSubCategories = response.body.data.map((item, idx) => {
item.key = idx; item.key = idx;
return item return item
}) ?? [] }) ?? []
this.total_dataSubCategories = response.body.count ?? 0 this.total_dataSubCategories = response.body.count ?? 0
} catch (e) {
console.log(e);
}
} }
async getDataCategories() { async getDataCategories() {
const response = await http.get(`/product/categories?page=${this.pageCategories}&pageSize=${this.pageSizeCategories}`); try {
const response = await http.get(`/product/categories?page=${this.pageCategories}&pageSize=${this.pageSizeCategories}`);
this.dataCategories = response.body.data.map((item, idx) => { this.dataCategories = response.body.data.map((item, idx) => {
item.key = idx; item.key = idx;
return item return item
}) ?? [] }) ?? []
this.total_dataCategories = response.body.total_data ?? 0 this.total_dataCategories = response.body.total_data ?? 0
if (this.dataCategories.length > 0) { if (this.dataCategories.length > 0) {
this.filterCategory = this.dataCategories[0].id this.filterCategory = this.dataCategories[0].id
}
} catch (e) {
console.error(e);
} }
} }
async create(data) { async create(data) {
const response = await http.post('/product/categories').send(data); try {
await this.getData(); const response = await http.post('/product/categories').send(data);
return response; await this.getData();
return response;
} catch (e) {
console.log(e);
}
} }
async update(id, data) { async update(id, data) {
const response = await http.put(`/product/categories/${id}`).send(data); try {
await this.getData(); const response = await http.put(`/product/categories/${id}`).send(data);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
async delete(id) { async delete(id) {
const response = await http.del(`/product/${id}`); try {
await this.getData(); const response = await http.del(`/product/${id}`);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
} }

View File

@ -25,25 +25,37 @@ export class Commission {
} }
async getData() { async getData() {
const response = await http.get(`/config/commission?page=${this.page}&pageSize=${this.pageSize}`); try {
this.data = response.body.data.map((item, idx) => { const response = await http.get(`/config/commission?page=${this.page}&pageSize=${this.pageSize}`);
item.key = idx; this.data = response.body.data.map((item, idx) => {
return item item.key = idx;
}) ?? [] return item
}) ?? []
this.total_data = response.body.total_data ?? 0 this.total_data = response.body.total_data ?? 0
} catch (e) {
console.error(e);
}
} }
async update(id, data) { async update(id, data) {
const response = await http.put(`/config/commission/${id}`).send(data); try {
await this.getData(); const response = await http.put(`/config/commission/${id}`).send(data);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
async delete(id) { async delete(id) {
const response = await http.del(`/product/${id}`); try {
await this.getData(); const response = await http.del(`/product/${id}`);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
} }

View File

@ -1,4 +1,4 @@
import {action, makeAutoObservable} from "mobx"; import {makeAutoObservable} from "mobx";
import {http} from "../utils/http"; import {http} from "../utils/http";
export class Membership { export class Membership {
@ -13,60 +13,75 @@ export class Membership {
} }
async getData() { async getData() {
const response = await http.get(`/users?page=${this.page}&pageSize=${this.pageSize}`); try {
const response = await http.get(`/users?page=${this.page}&pageSize=${this.pageSize}`);
this.data = response.body.data.map((item, idx) => { this.data = response.body.data.map((item, idx) => {
item.key = idx; item.key = idx;
item.name = item?.user_detail?.name; item.name = item?.user_detail?.name;
item.phone_number = item?.user_detail?.phone_number; item.phone_number = item?.user_detail?.phone_number;item.roleId = item?.roles.id;
item.roleId = item?.roles.id; item.roleName = item?.roles.name;
item.roleName = item?.roles.name; return item
return item }) ?? []
}) ?? []
console.log(JSON.stringify(this.data), "DATA"); this.total_data = response.body.total_data ?? 0
} catch (e) {
this.total_data = response.body.total_data ?? 0 console.error(e);
}
} }
async getDataBySuperior() { async getDataBySuperior() {
const response = await http.get(`/users/find-by-supperior?page=${this.page}&pageSize=${this.pageSize}`); try {
this.data = response.body.data.map((item, idx) => { const response = await http.get(`/users/find-by-supperior?page=${this.page}&pageSize=${this.pageSize}`);
item.key = idx; this.data = response.body.data.map((item, idx) => {
item.name = item?.user_detail?.name; item.key = idx;
item.phone_number = item?.user_detail?.phone_number; item.name = item?.user_detail?.name;
item.roleId = item?.roles.id; item.phone_number = item?.user_detail?.phone_number;item.roleId = item?.roles.id;
item.roleName = item?.roles?.name; item.roleName = item?.roles?.name;
return item return item
}) ?? [] }) ?? []
this.total_data = response.body.total_data ?? 0 this.total_data = response.body.total_data ?? 0
} catch (e) {
console.error(e);
}
} }
async create(data) { async create(data) {
return await http.post('/users').send(data) try {
return await http.post('/users').send(data)
} catch (e) {
console.error(e);
}
} }
async update(id, data) { async update(id, data) {
// console.log(data) try {
// console.log(id) const response = await http.put('/users/' + id).send(data);
const response = await http.put('/users/' + id).send(data); console.log(response, 'Data user')
console.log(response, 'Data user') console.log(JSON.stringify(response.body.data), 'Data')
console.log(JSON.stringify(response.body.data), 'Data') } catch (e) {
console.error(e);
}
} }
async delete(id) { async delete(id) {
console.log(id) try {
return await http.del('/users/' + id); return await http.del('/users/' + id);
} catch (e) {
console.error(e);
}
} }
async changeStatus(id, status) { async changeStatus(id, status) {
console.log(`/users/${id}/${status}`); try {
const response = await http.get(`/users/${id}/${status}`);
const response = await http.get(`/users/${id}/${status}`); await this.getData();
await this.getData(); return response;
return response; } catch (e) {
console.error(e);
}
} }
} }

View File

@ -25,26 +25,38 @@ export class Partner {
} }
async getData() { async getData() {
const response = await http.get(`/users/partner?page=${this.page}&pageSize=${this.pageSize}`); try {
const response = await http.get(`/users/partner?page=${this.page}&pageSize=${this.pageSize}`);
this.data = response.body.data.map((item, idx) => { this.data = response.body.data.map((item, idx) => {
item.key = idx; item.key = idx;
return item return item
}) ?? [] }) ?? []
this.total_data = response.body.count ?? 0 this.total_data = response.body.count ?? 0
} catch (e) {
console.error(e);
}
} }
async create(data) { async create(data) {
const response = await http.post('/users/partner').send(data); try {
await this.getData(); const response = await http.post('/users/partner').send(data);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
async update(id, data) { async update(id, data) {
const response = await http.put(`/users/partner/${id}`).send(data); try {
await this.getData(); const response = await http.put(`/users/partner/${id}`).send(data);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
// async updateStatus(id, data) { // async updateStatus(id, data) {
@ -54,15 +66,23 @@ export class Partner {
// } // }
async delete(id) { async delete(id) {
const response = await http.del(`/product/${id}`); try {
await this.getData(); const response = await http.del(`/product/${id}`);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
async changeStatus(id, status) { async changeStatus(id, status) {
const response = await http.get(`/users/partner/${id}/${status}`); try {
await this.getData(); const response = await http.get(`/users/partner/${id}/${status}`);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
} }

View File

@ -29,48 +29,72 @@ export class Product {
} }
async getData() { async getData() {
const response = await http.get(`/product/all?supplier=${this.filterSupplier}&categories=${this.filterCategory}&categories=${this.filterSubCategory}&page=${this.page}&pageSize=${this.pageSize}`); try {
this.data = response.body.data.map((item, idx) => { const response = await http.get(`/product/all?supplier=${this.filterSupplier}&categories=${this.filterCategory}&categories=${this.filterSubCategory}&page=${this.page}&pageSize=${this.pageSize}`);
item.key = idx; this.data = response.body.data.map((item, idx) => {
return item item.key = idx;
}) ?? [] return item
}) ?? []
this.total_data = response.body.total_data ?? 0 this.total_data = response.body.total_data ?? 0
} catch (e) {
console.error(e);
}
} }
async getDataSubCategories() { async getDataSubCategories() {
const response = await http.get(`/product/sub-categories?page=${this.pageSubCategories}&pageSize=${this.pageSizeSubCategories}`); try {
this.dataSubCategories = response.body.data.map((item, idx) => { const response = await http.get(`/product/sub-categories?page=${this.pageSubCategories}&pageSize=${this.pageSizeSubCategories}`);
item.key = idx; this.dataSubCategories = response.body.data.map((item, idx) => {
return item item.key = idx;
}) ?? [] return item
this.total_dataSubCategories = response.body.count ?? 0 }) ?? []
this.total_dataSubCategories = response.body.count ?? 0
} catch (e) {
console.error(e);
}
} }
async getDataCategories() { async getDataCategories() {
const response = await http.get(`/product/categories?page=${this.pageCategories}&pageSize=${this.pageSizeCategories}`); try {
this.dataCategories = response.body.data.map((item, idx) => { const response = await http.get(`/product/categories?page=${this.pageCategories}&pageSize=${this.pageSizeCategories}`);
item.key = idx; this.dataCategories = response.body.data.map((item, idx) => {
return item item.key = idx;
}) ?? [] return item
}) ?? []
} catch (e) {
console.error(e);
}
} }
async create(data) { async create(data) {
const response = await http.post('/product').send(data); try {
await this.getData(); const response = await http.post('/product').send(data);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
async update(id, data) { async update(id, data) {
const response = await http.put(`/product/${id}`).send(data); try {
await this.getData(); const response = await http.put(`/product/${id}`).send(data);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
async delete(id) { async delete(id) {
const response = await http.del(`/product/${id}`); try {
await this.getData(); const response = await http.del(`/product/${id}`);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
} }

View File

@ -13,21 +13,37 @@ export class Role {
} }
async getData() { async getData() {
const response = await http.get(`/config/roles?page=${this.page}&pageSize=${this.pageSize}`); try {
this.data = response.body.data ?? [] const response = await http.get(`/config/roles?page=${this.page}&pageSize=${this.pageSize}`);
this.total_data = response.body.total_data ?? 0 this.data = response.body.data ?? []
this.total_data = response.body.total_data ?? 0
} catch (e) {
console.error(e);
}
} }
async create(data) { async create(data) {
return await http.post('/users').send(data) try {
return await http.post('/users').send(data)
} catch (e) {
console.error(e);
}
} }
async update(id, data) { async update(id, data) {
return await http.put('/users/' + id).send(data); try {
return await http.put('/users/' + id).send(data);
} catch (e) {
console.error(e);
}
} }
async delete(id) { async delete(id) {
return await http.del('/users/' + id); try {
return await http.del('/users/' + id);
} catch (e) {
console.error(e);
}
} }
} }

View File

@ -25,42 +25,62 @@ export class Subcategory {
} }
async getData() { async getData() {
const response = await http.get(`/product/sub-categories?page=${this.page}&pageSize=${this.pageSize}`); try {
this.data = response.body.data.map((item, idx) => { const response = await http.get(`/product/sub-categories?page=${this.page}&pageSize=${this.pageSize}`);
this.data = response.body.data.map((item, idx) => {
item.key = idx; item.key = idx;
item.categoryName = item.category.name; item.categoryName = item.category.name;
return item return item
}) ?? [] }) ?? []
this.total_data = response.body.total_data ?? 0 this.total_data = response.body.total_data ?? 0
} catch (e) {
console.error(e);
}
} }
async getDataSubCategories() { async getDataSubCategories() {
const response = await http.get(`/product/sub-categories?page=${this.pageSubCategories}&pageSize=${this.pageSizeSubCategories}`); try {
this.dataSubCategories = response.body.data.map((item, idx) => { const response = await http.get(`/product/sub-categories?page=${this.pageSubCategories}&pageSize=${this.pageSizeSubCategories}`);
this.dataSubCategories = response.body.data.map((item, idx) => {
item.key = idx; item.key = idx;
return item return item
}) ?? [] }) ?? []
this.total_dataSubCategories = response.body.count ?? 0 this.total_dataSubCategories = response.body.count ?? 0
} catch (e) {
console.error(e);
}
} }
async create(data) { async create(data) {
const response = await http.post('/product/sub-categories').send(data); try {
await this.getData(); const response = await http.post('/product/sub-categories').send(data);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
async update(id, data) { async update(id, data) {
const response = await http.put(`/product/sub-categories/${id}`).send(data); try {
await this.getData(); const response = await http.put(`/product/sub-categories/${id}`).send(data);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
async delete(id) { async delete(id) {
const response = await http.del(`/product/${id}`); try {
await this.getData(); const response = await http.del(`/product/${id}`);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
} }

View File

@ -27,39 +27,62 @@ export class Supplier {
} }
async getData() { async getData() {
const response = await http.get(`/users/supplier?page=${this.page}&pageSize=${this.pageSize}`); try {
//console.log(response) const response = await http.get(`/users/supplier?page=${this.page}&pageSize=${this.pageSize}`);
this.data = response.body.data ?? [] this.data = response.body.data ?? []
this.total_data = response.body.count ?? 0 this.total_data = response.body.count ?? 0
} catch (e) {
console.error(e);
}
} }
async create(data) { async create(data) {
const response = await http.post('/users/supplier').send(data); try {
await this.getData(); const response = await http.post('/users/supplier').send(data);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
async createTransaction(data) { async createTransaction(data) {
const response = await http.post('/transaction/add-saldo-supplier').send(data); try {
await this.getData(); const response = await http.post('/transaction/add-saldo-supplier').send(data);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
async update(id, data) { async update(id, data) {
const response = await http.put(`/users/supplier/${id}`).send(data); try {
await this.getData(); const response = await http.put(`/users/supplier/${id}`).send(data);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
async delete(id) { async delete(id) {
const response = await http.del(`/product/${id}`); try {
await this.getData(); const response = await http.del(`/product/${id}`);
return response; await this.getData();
return response;
} catch (e) {
console.error(e)
}
} }
async changeStatus(id, status) { async changeStatus(id, status) {
const response = await http.get(`/users/supplier/${id}/${status}`); try {
await this.getData(); const response = await http.get(`/users/supplier/${id}/${status}`);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
} }

View File

@ -30,61 +30,96 @@ export class Transaction {
} }
async getData() { async getData() {
const response = await http.get(`/product/by-categories?categories=${this.filterCategory}&page=${this.page}&pageSize=${this.pageSize}`); try {
const response = await http.get(`/product/by-categories?categories=${this.filterCategory}&page=${this.page}&pageSize=${this.pageSize}`);
this.data = response.body.data ?? [] this.data = response.body.data ?? []
this.total_data = response.body.total_data ?? 0 this.total_data = response.body.total_data ?? 0
} catch (e) {
console.error(e);
}
} }
async getDataSubCategories() { async getDataSubCategories() {
const response = await http.get(`/product/sub-categories?page=${this.pageSubCategories}&pageSize=${this.pageSizeSubCategories}`); try {
this.dataSubCategories = response.body.data ?? [] const response = await http.get(`/product/sub-categories?page=${this.pageSubCategories}&pageSize=${this.pageSizeSubCategories}`);
this.total_dataSubCategories = response.body.count ?? 0 this.dataSubCategories = response.body.data ?? []
this.total_dataSubCategories = response.body.count ?? 0
} catch (e) {
console.error(e);
}
} }
async getDataCategories() { async getDataCategories() {
const response = await http.get(`/product/categories?page=${this.pageCategories}&pageSize=${this.pageSizeCategories}`); try {
const response = await http.get(`/product/categories?page=${this.pageCategories}&pageSize=${this.pageSizeCategories}`);
this.dataCategories = response.body.data ?? [] this.dataCategories = response.body.data ?? []
this.total_dataCategories = response.body.total_data ?? 0 this.total_dataCategories = response.body.total_data ?? 0
if (this.dataCategories.length > 0) { if (this.dataCategories.length > 0) {
this.filterCategory = this.dataCategories[0].id this.filterCategory = this.dataCategories[0].id
}
} catch (e) {
console.error(e);
} }
} }
async getDataHistoryTransaction() { async getDataHistoryTransaction() {
const response = await http.get(`/transaction/history?page=${this.pageHistoryTransaction}`); try {
const response = await http.get(`/transaction/history?page=${this.pageHistoryTransaction}`);
this.dataHistoryTransaction = response.body.data ?? [] this.dataHistoryTransaction = response.body.data ?? []
this.total_dataHistoryTransaction = response.body.total_data ?? 0 this.total_dataHistoryTransaction = response.body.total_data ?? 0
} catch (e) {
console.error(e);
}
} }
async create(data) { async create(data) {
const response = await http.post('/product').send(data); try {
await this.getData(); const response = await http.post('/product').send(data);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
async update(id, data) { async update(id, data) {
const response = await http.put(`/product/${id}`).send(data); try {
await this.getData(); const response = await http.put(`/product/${id}`).send(data);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
async delete(id) { async delete(id) {
const response = await http.del(`/product/${id}`); try {
await this.getData(); const response = await http.del(`/product/${id}`);
return response; await this.getData();
return response;
} catch (e) {
console.error(e);
}
} }
async distribute(data) { async distribute(data) {
const response = await http.post('/transaction/distribute').send(data); try {
return response; const response = await http.post('/transaction/distribute').send(data);
return response;
} catch (e) {
console.error(e);
}
} }
async distributeAdmin(data) { async distributeAdmin(data) {
const response = await http.post('/transaction/distribute-admin').send(data); try {
return response; const response = await http.post('/transaction/distribute-admin').send(data);
return response;
} catch (e) {
console.error(e);
}
} }
} }

View File

@ -11,7 +11,11 @@ export class User {
@action @action
async getData() { async getData() {
this.data = (await http.get('/user')).body.data; try {
this.data = (await http.get('/user')).body.data;
} catch (e) {
console.error(e);
}
} }
} }