TransactionEntity
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import { type Ref, defineComponent, inject, onMounted, ref } from 'vue';
|
||||
|
||||
import TransactionService from './transaction.service';
|
||||
import { type ITransaction } from '@/shared/model/transaction.model';
|
||||
import { useAlertService } from '@/shared/alert/alert.service';
|
||||
|
||||
export default defineComponent({
|
||||
compatConfig: { MODE: 3 },
|
||||
name: 'Transaction',
|
||||
setup() {
|
||||
const transactionService = inject('transactionService', () => new TransactionService());
|
||||
const alertService = inject('alertService', () => useAlertService(), true);
|
||||
|
||||
const transactions: Ref<ITransaction[]> = ref([]);
|
||||
|
||||
const isFetching = ref(false);
|
||||
|
||||
const clear = () => {};
|
||||
|
||||
const retrieveTransactions = async () => {
|
||||
isFetching.value = true;
|
||||
try {
|
||||
const res = await transactionService().retrieve();
|
||||
transactions.value = res.data;
|
||||
} catch (err) {
|
||||
alertService.showHttpError(err.response);
|
||||
} finally {
|
||||
isFetching.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleSyncList = () => {
|
||||
retrieveTransactions();
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
await retrieveTransactions();
|
||||
});
|
||||
|
||||
const removeId: Ref<number> = ref(null);
|
||||
const removeEntity = ref<any>(null);
|
||||
const prepareRemove = (instance: ITransaction) => {
|
||||
removeId.value = instance.id;
|
||||
removeEntity.value.show();
|
||||
};
|
||||
const closeDialog = () => {
|
||||
removeEntity.value.hide();
|
||||
};
|
||||
const removeTransaction = async () => {
|
||||
try {
|
||||
await transactionService().delete(removeId.value);
|
||||
const message = `A Transaction is deleted with identifier ${removeId.value}`;
|
||||
alertService.showInfo(message, { variant: 'danger' });
|
||||
removeId.value = null;
|
||||
retrieveTransactions();
|
||||
closeDialog();
|
||||
} catch (error) {
|
||||
alertService.showHttpError(error.response);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
transactions,
|
||||
handleSyncList,
|
||||
isFetching,
|
||||
retrieveTransactions,
|
||||
clear,
|
||||
removeId,
|
||||
removeEntity,
|
||||
prepareRemove,
|
||||
closeDialog,
|
||||
removeTransaction,
|
||||
};
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user