feat: stiching api profile and history transaction.js

This commit is contained in:
caturbgs
2021-12-15 20:36:48 +07:00
parent 6f743301e4
commit 28c42b3453
3 changed files with 97 additions and 21 deletions

View File

@@ -6,6 +6,7 @@ export class Authentication {
isLoggedIn = false;
isLoginLoading = false;
ctx;
profileData = {};
constructor(ctx) {
this.ctx = ctx;
@@ -49,6 +50,16 @@ export class Authentication {
}
}
async getProfile() {
try {
const response = await http.get('/auth/profile');
this.profileData = response.body.data;
} catch (e) {
console.error(e);
throw e;
}
}
logout() {
TokenUtil.clearAccessToken();
TokenUtil.persistToken();

View File

@@ -1,5 +1,5 @@
import { makeAutoObservable } from "mobx";
import { http } from "../utils/http";
import {makeAutoObservable} from "mobx";
import {http} from "../utils/http";
export class Transaction {
page = 0;
@@ -19,6 +19,11 @@ export class Transaction {
dataSubCategories = [];
total_dataSubCategories = 0;
pageHistoryTransaction = 0;
pageSizeHistoryTransaction = 10
dataHistoryTransaction = [];
total_dataHistoryTransaction = 0;
constructor(ctx) {
this.ctx = ctx;
makeAutoObservable(this);
@@ -47,6 +52,13 @@ export class Transaction {
}
}
async getDataHistoryTransaction() {
const response = await http.get(`/transaction/history?page=${this.pageHistoryTransaction}&pageSize=${this.pageSizeHistoryTransaction}`);
this.dataHistoryTransaction = response.body.data ?? []
this.total_dataHistoryTransaction = response.body.total_data ?? 0
}
async create(data) {
const response = await http.post('/product').send(data);
await this.getData();