init
This commit is contained in:
27
src/services/budgetsService.ts
Normal file
27
src/services/budgetsService.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import apiClient from '@/plugins/axios';
|
||||
import {BudgetCategory} from "@/models/Budget";
|
||||
// Импортируете настроенный экземпляр axios
|
||||
|
||||
export const getBudgetInfo = async (budget_id: number) => {
|
||||
console.log('getBudgetInfo');
|
||||
let budgetInfo = await apiClient.get('/budgets/' + budget_id);
|
||||
budgetInfo = budgetInfo.data;
|
||||
|
||||
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 budgetInfo
|
||||
|
||||
};
|
||||
|
||||
export const updateBudgetCategoryRequest = async (budget_id, category: BudgetCategory) => {
|
||||
await apiClient.put('/budgets/' + budget_id + '/category', category);
|
||||
}
|
||||
25
src/services/categoryService.ts
Normal file
25
src/services/categoryService.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
// src/services/categoryService.ts
|
||||
import apiClient from '@/plugins/axios';
|
||||
import {Category} from "@/models/Category"; // Импортируете настроенный экземпляр axios
|
||||
|
||||
export const getCategories = async (type = null) => {
|
||||
|
||||
type = type ? type : ''
|
||||
return await apiClient.get('/categories/?type=' + type);
|
||||
};
|
||||
|
||||
export const getCategoryTypes = async () => {
|
||||
return await apiClient.get('/categories/types/');
|
||||
}
|
||||
|
||||
export const createCategory = async (category: Category) => {
|
||||
return await apiClient.post('/categories', category);
|
||||
};
|
||||
|
||||
export const updateCategory = async (id: number, category: any) => {
|
||||
return await apiClient.put(`/categories/${id}`, category);
|
||||
};
|
||||
|
||||
export const deleteCategory = async (id: number) => {
|
||||
return await apiClient.delete(`/categories/${id}`);
|
||||
};
|
||||
30
src/services/recurrentService.ts
Normal file
30
src/services/recurrentService.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
// src/services/recurrentyService.ts
|
||||
import apiClient from '@/plugins/axios';
|
||||
import { RecurrentPayment} from "@/models/Recurrent"; // Импортируете настроенный экземпляр axios
|
||||
|
||||
export const getRecurrentPayments = async () => {
|
||||
console.log('getRecurrentPayments');
|
||||
return await apiClient.get('/recurrents/');
|
||||
};
|
||||
|
||||
|
||||
export const saveRecurrentPayment = async (payment: RecurrentPayment) => {
|
||||
console.log('saveRecurrentPayment');
|
||||
return await apiClient.post('/recurrents/', payment)
|
||||
}
|
||||
//
|
||||
// export const getCategoryTypes = async () => {
|
||||
// return await apiClient.get('/categories/types/');
|
||||
// }
|
||||
//
|
||||
// export const createCategory = async (category: Category) => {
|
||||
// return await apiClient.post('/categories', category);
|
||||
// };
|
||||
//
|
||||
// export const updateCategory = async (id: number, category: any) => {
|
||||
// return await apiClient.put(`/categories/${id}`, category);
|
||||
// };
|
||||
//
|
||||
// export const deleteCategory = async (id: number) => {
|
||||
// return await apiClient.delete(`/categories/${id}`);
|
||||
// };
|
||||
49
src/services/transactionService.ts
Normal file
49
src/services/transactionService.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import apiClient from '@/plugins/axios';
|
||||
import {Transaction} from "@/models/Transaction";
|
||||
import {format} from "date-fns";
|
||||
// Импортируете настроенный экземпляр axios
|
||||
|
||||
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) => {
|
||||
const params = {};
|
||||
|
||||
// Add the parameters to the params object if they are not null
|
||||
if (transaction_type) {
|
||||
params.transaction_type = transaction_type;
|
||||
}
|
||||
|
||||
if (category_type) {
|
||||
params.category_type = category_type;
|
||||
}
|
||||
|
||||
if (category_id) {
|
||||
params.category_id = category_id;
|
||||
}
|
||||
|
||||
// Use axios to make the GET request, passing the params as the second argument
|
||||
return await apiClient.get('/transactions/', {
|
||||
params: params
|
||||
});
|
||||
}
|
||||
|
||||
export const createTransactionRequest = async (transaction: Transaction) => {
|
||||
transaction.date = format(transaction.date, 'yyyy-MM-dd')
|
||||
return await apiClient.post('/transactions', transaction);
|
||||
};
|
||||
|
||||
export const updateTransactionRequest = async (transaction: Transaction) => {
|
||||
const id = transaction.id
|
||||
transaction.date = format(transaction.date, 'yyyy-MM-dd')
|
||||
return await apiClient.put(`/transactions/${id}`, transaction);
|
||||
};
|
||||
|
||||
export const deleteTransactionRequest = async (id: number) => {
|
||||
return await apiClient.delete(`/transactions/${id}`);
|
||||
};
|
||||
|
||||
export const getTransactionTypes = async () => {
|
||||
return await apiClient.get('/transactions/types/');
|
||||
}
|
||||
Reference in New Issue
Block a user