ver 2
This commit is contained in:
@@ -4,8 +4,8 @@ import { useRouter } from 'vue-router';
|
||||
|
||||
// Создаем экземпляр axios
|
||||
const api = axios.create({
|
||||
baseURL: 'https://luminic.space/api/v1',
|
||||
// baseURL: 'http://localhost:8000/api/v1',
|
||||
baseURL: 'https://luminic.space/api/',
|
||||
// baseURL: 'http://localhost:8082/api',
|
||||
});
|
||||
|
||||
// Устанавливаем токен из localStorage при каждом запуске
|
||||
@@ -19,7 +19,7 @@ api.interceptors.response.use(
|
||||
|
||||
(response) => response,
|
||||
(error) => {
|
||||
if (error.response && error.response.status === 401) {
|
||||
if (error.response && error.response.status === 403) {
|
||||
localStorage.removeItem('token');
|
||||
const router = useRouter();
|
||||
router.push('/login');
|
||||
|
||||
@@ -4,25 +4,32 @@ import {format} from "date-fns";
|
||||
// Импортируете настроенный экземпляр axios
|
||||
|
||||
export const getBudgetInfos = async () => {
|
||||
try {
|
||||
|
||||
let response = await apiClient.get('/budgets/');
|
||||
|
||||
let response = await apiClient.get('/budgets');
|
||||
let budgetInfos = response.data;
|
||||
budgetInfos.forEach((budgetInfo: Budget) => {
|
||||
budgetInfo.dateFrom = new Date(budgetInfo.dateFrom);
|
||||
budgetInfo.dateTo = new Date(budgetInfo.dateTo);
|
||||
// budgetInfo.plannedExpenses.forEach(e => {
|
||||
// e.date = new Date(e.date)
|
||||
// })
|
||||
//
|
||||
// budgetInfo.plannedIncomes.forEach(e => {
|
||||
// e.date = new Date(e.date)
|
||||
// })
|
||||
//
|
||||
// budgetInfo.transactions.forEach(e => {
|
||||
// e.date = new Date(e.date)
|
||||
// })
|
||||
budgetInfo.plannedExpenses?.forEach(e => {
|
||||
e.date = new Date(e.date)
|
||||
})
|
||||
|
||||
budgetInfo.plannedIncomes?.forEach(e => {
|
||||
e.date = new Date(e.date)
|
||||
})
|
||||
|
||||
budgetInfo.transactions?.forEach(e => {
|
||||
e.date = new Date(e.date)
|
||||
})
|
||||
})
|
||||
return budgetInfos
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
throw e
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export const getBudgetTransactions = async (budgetId, transactionType, categoryType) => {
|
||||
@@ -66,18 +73,50 @@ export const getBudgetInfo = async (budget_id: number) => {
|
||||
|
||||
};
|
||||
|
||||
|
||||
export const getWarns = async (budgetId: string, hidden: Boolean = null) => {
|
||||
let url = `/budgets/${budgetId}/warns`
|
||||
if (hidden) {
|
||||
url += `?hidden=${hidden}`
|
||||
}
|
||||
let warns = await apiClient.get(url);
|
||||
return warns.data
|
||||
}
|
||||
|
||||
export const hideWarnRequest = async (budgetId: string, warnId: string) => {
|
||||
await apiClient.post(`/budgets/${budgetId}/warns/${warnId}/hide`);
|
||||
}
|
||||
|
||||
export const updateBudgetCategoryRequest = async (budget_id, category: BudgetCategory) => {
|
||||
await apiClient.put('/budgets/' + budget_id + '/category', category);
|
||||
return await apiClient.post('/budgets/' + budget_id + '/categories/' + category.category.id + "/limit", {"limit": category.currentLimit}).then(i => i.data);
|
||||
}
|
||||
|
||||
export const createBudget = async (budget: Budget, createRecurrent: Boolean) => {
|
||||
budget.dateFrom = format(budget.dateFrom, 'yyyy-MM-dd')
|
||||
budget.dateTo = format(budget.dateTo, 'yyyy-MM-dd')
|
||||
let data = {
|
||||
budget: budget,
|
||||
createRecurrent: createRecurrent
|
||||
|
||||
try {
|
||||
|
||||
let budgetToCreate = JSON.parse(JSON.stringify(budget));
|
||||
budgetToCreate.dateFrom = format(budget.dateFrom, 'yyyy-MM-dd')
|
||||
budgetToCreate.dateTo = format(budget.dateTo, 'yyyy-MM-dd')
|
||||
let data = {
|
||||
budget: budgetToCreate,
|
||||
createRecurrent: createRecurrent
|
||||
}
|
||||
await apiClient.post('/budgets/', data);
|
||||
|
||||
} catch (e){
|
||||
console.error(e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const deleteBudgetRequest = async (budgetId: string) => {
|
||||
try {
|
||||
// throw Error("test")
|
||||
let response = await apiClient.delete(`/budgets/${budgetId}`);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
}
|
||||
await apiClient.post('/budgets', data);
|
||||
budget.dateFrom = format(budget.dateFrom, 'dd.mm.yy')
|
||||
budget.dateTo = format(budget.dateTo, 'dd.mm.yy')
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import {Category} from "@/models/Category"; // Импортируете нас
|
||||
export const getCategories = async (type = null) => {
|
||||
|
||||
type = type ? type : ''
|
||||
return await apiClient.get('/categories/?type=' + type);
|
||||
return await apiClient.get('/categories?type=' + type);
|
||||
};
|
||||
|
||||
export const getCategoryTypes = async () => {
|
||||
|
||||
@@ -7,9 +7,10 @@ export const getTransaction = async (transactionId: int) => {
|
||||
return await apiClient.post(`/transactions/${transactionId}`,);
|
||||
}
|
||||
|
||||
export const getTransactions = async (transaction_type = null, category_type = null, category_id = null, user_id = null, limit = null, offset = null) => {
|
||||
export const getTransactions = async (transaction_type = null, category_type = null, category_id = null, user_id = null, is_child = null, limit = null, offset = null) => {
|
||||
const params = {};
|
||||
|
||||
console.log(is_child)
|
||||
// Add the parameters to the params object if they are not null
|
||||
if (transaction_type) {
|
||||
params.transaction_type = transaction_type;
|
||||
@@ -25,6 +26,9 @@ export const getTransactions = async (transaction_type = null, category_type = n
|
||||
if (user_id) {
|
||||
params.user_id = user_id
|
||||
}
|
||||
if (is_child!=null){
|
||||
params.is_child = is_child
|
||||
}
|
||||
if (limit) {
|
||||
params.limit = limit
|
||||
}
|
||||
@@ -33,22 +37,25 @@ export const getTransactions = async (transaction_type = null, category_type = n
|
||||
}
|
||||
|
||||
// Use axios to make the GET request, passing the params as the second argument
|
||||
return await apiClient.get('/transactions/', {
|
||||
return await apiClient.get('/transactions', {
|
||||
params: params
|
||||
});
|
||||
}
|
||||
|
||||
export const createTransactionRequest = async (transaction: Transaction) => {
|
||||
transaction.date = format(transaction.date, 'yyyy-MM-dd')
|
||||
let transactionResponse = await apiClient.post('/transactions', transaction);
|
||||
console.log(transaction.date)
|
||||
let transactionResponse = await apiClient.post('/transactions', transaction);
|
||||
|
||||
transaction.date = new Date(transaction.date);
|
||||
return transactionResponse.data
|
||||
};
|
||||
|
||||
export const updateTransactionRequest = async (transaction: Transaction) => {
|
||||
const id = transaction.id
|
||||
transaction.date = format(transaction.date, 'yyyy-MM-dd')
|
||||
// console.log(transaction.isDone)
|
||||
// transaction.date = transaction.date.setHours(0,0,0,0)
|
||||
transaction.date = format(transaction.date, "yyyy-MM-dd")
|
||||
|
||||
const response = await apiClient.put(`/transactions/${id}`, transaction);
|
||||
transaction = response.data
|
||||
transaction.date = new Date(transaction.date);
|
||||
@@ -56,15 +63,15 @@ export const updateTransactionRequest = async (transaction: Transaction) => {
|
||||
return transaction
|
||||
};
|
||||
|
||||
export const setTransactionDoneRequest = async (transaction: Transaction) => {
|
||||
const id = transaction.id
|
||||
// transaction.date = format(transaction.date, 'yyyy-MM-dd')
|
||||
const response = await apiClient.put(`/transactions/${id}/done`, transaction);
|
||||
transaction = response.data
|
||||
transaction.date = new Date(transaction.date);
|
||||
|
||||
return transaction
|
||||
};
|
||||
// export const setTransactionDoneRequest = async (transaction: Transaction) => {
|
||||
// const id = transaction.id
|
||||
// // transaction.date = format(transaction.date, 'yyyy-MM-dd')
|
||||
// const response = await apiClient.patch(`/transactions/${id}/set-done`, transaction);
|
||||
// // transaction = response.data
|
||||
// // transaction.date = new Date(transaction.date);
|
||||
//
|
||||
// // return transaction
|
||||
// };
|
||||
|
||||
export const deleteTransactionRequest = async (id: number) => {
|
||||
return await apiClient.delete(`/transactions/${id}`);
|
||||
@@ -74,7 +81,7 @@ export const getTransactionTypes = async () => {
|
||||
return await apiClient.get('/transactions/types');
|
||||
}
|
||||
|
||||
export const getTransactionCategoriesSums = async () => {
|
||||
export const getTransactionCategoriesSums = async () => {
|
||||
let response = await apiClient.get('/transactions/categories/_calc_sums');
|
||||
return response.data;
|
||||
}
|
||||
7
src/services/userService.ts
Normal file
7
src/services/userService.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import apiClient from '@/services/axiosSetup';
|
||||
|
||||
|
||||
export const getUsers = async () => {
|
||||
let users = await apiClient.get('/users/');
|
||||
return users.data;
|
||||
}
|
||||
Reference in New Issue
Block a user