Now able to upload and then view images attached to expenses. Will need to check if further changes need to be made to updating expenses. Minor structural changes here and there.
45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
/* eslint-disable */
|
|
import { useExpensesStore } from "src/stores/expense-store";
|
|
import { useTimesheetStore } from "src/stores/timesheet-store";
|
|
import { Expense } from "src/modules/timesheets/models/expense.models";
|
|
import { date } from "quasar";
|
|
|
|
export const useExpensesApi = () => {
|
|
const expenses_store = useExpensesStore();
|
|
const timesheet_store = useTimesheetStore();
|
|
|
|
const upsertExpense = async (expense: Expense, employee_email: string, file?: File): Promise<string> => {
|
|
if (file) {
|
|
const attachmentKey = await expenses_store.uploadAttachment(file);
|
|
|
|
if (!attachmentKey)
|
|
console.error('failed to upload attachment');
|
|
else {
|
|
expense.attachment_key = attachmentKey;
|
|
expense.attachment_name = file.name;
|
|
}
|
|
}
|
|
|
|
const success = await expenses_store.upsertExpense(expense, employee_email);
|
|
|
|
if (success) {
|
|
expenses_store.current_expense = new Expense(date.formatDate( new Date(), 'YYYY-MM-DD'));
|
|
timesheet_store.getTimesheetsByOptionalEmployeeEmail(employee_email);
|
|
return 'SUCCESS';
|
|
}
|
|
|
|
return 'INVALID_EXPENSE';
|
|
};
|
|
|
|
const deleteExpenseById = async (expense_id: number, employee_email?: string): Promise<void> => {
|
|
const success = await expenses_store.deleteExpenseById(expense_id);
|
|
if (success) {
|
|
timesheet_store.getTimesheetsByOptionalEmployeeEmail(employee_email);
|
|
}
|
|
};
|
|
|
|
return {
|
|
upsertExpense,
|
|
deleteExpenseById,
|
|
};
|
|
}; |