diff --git a/src/components/molecules/MoleculeTransactionTable.vue b/src/components/molecules/MoleculeTransactionTable.vue
index 3d8ab8e..fd5a3f3 100644
--- a/src/components/molecules/MoleculeTransactionTable.vue
+++ b/src/components/molecules/MoleculeTransactionTable.vue
@@ -11,7 +11,7 @@
- {{ transaction.type }}
+ {{ transaction.label }}
{{ DateService.toString(transaction.date) }}
diff --git a/src/components/services/bank.service.ts b/src/components/services/bank.service.ts
new file mode 100644
index 0000000..1e0b115
--- /dev/null
+++ b/src/components/services/bank.service.ts
@@ -0,0 +1,54 @@
+import { AppwriteService } from './appwrite.service';
+import { IAccount } from '../../interfaces/account.interface';
+import { Databases, Models, Query } from 'appwrite';
+import { ITransaction } from '../../interfaces/transaction.interface';
+
+const DATABASE_ID = '62dfd5787755e7ed9fcd';
+const ACCOUNTS_COLLECTION_ID = '62dfd6ca06197f9baa86';
+const TRANSACTIONS_COLLECTION_ID = '62dfd81b7671727b27cd';
+const DEPOSIT_LABEL = 'Bargeldeinzahlung';
+const SALARY_LABEL = 'Gehalt';
+const WITHDRAW_LABEL = 'Bargeldauszahlung';
+const sdk = AppwriteService.getSDK();
+
+export const BankService = {
+ async getAccountDetails(accountNumber: string): Promise {
+ const database = new Databases(sdk, DATABASE_ID);
+ const accountDocument = await database.listDocuments(
+ ACCOUNTS_COLLECTION_ID, [Query.equal('accountNumber', accountNumber)], 1);
+ const transactionDocuments = await database.listDocuments(
+ TRANSACTIONS_COLLECTION_ID, [Query.equal('accountNumber', accountNumber)], 100, 0, undefined, undefined, ['$createdAt'], ['DESC']);
+ const account: IAccount = {
+ accountNumber: accountDocument.documents[0].accountNumber,
+ firstName: accountDocument.documents[0].firstName,
+ lastName: accountDocument.documents[0].lastName,
+ balance: accountDocument.documents[0].balance,
+ transactions: transactionDocuments.documents.map(transaction => ({
+ label: transaction.label,
+ amount: transaction.amount,
+ date: new Date(transaction.$createdAt * 1000),
+ })),
+ };
+ return account;
+ },
+ async addTransaction(accountNumber: string, amount: number, type: TransactionType): Promise {
+ const database = new Databases(sdk, DATABASE_ID);
+ const accountDocument = await database.listDocuments(
+ ACCOUNTS_COLLECTION_ID, [Query.equal('accountNumber', accountNumber)], 1);
+ const transactionDocument = await database.createDocument(TRANSACTIONS_COLLECTION_ID, 'unique()', {
+ accountNumber: accountNumber,
+ label: type === TransactionType.DEPOSIT ? DEPOSIT_LABEL : (type === TransactionType.SALARY ? SALARY_LABEL : WITHDRAW_LABEL),
+ amount: (type === TransactionType.WITHDRAW ? -amount : amount),
+ });
+ await database.updateDocument(ACCOUNTS_COLLECTION_ID, accountDocument.documents[0].$id, {
+ balance: accountDocument.documents[0].balance + (type === TransactionType.WITHDRAW ? -amount : amount),
+ });
+ return { label: transactionDocument.label, amount: transactionDocument.amount, date: new Date(transactionDocument.$createdAt * 1000) };
+ },
+};
+
+export enum TransactionType {
+ DEPOSIT,
+ SALARY,
+ WITHDRAW,
+}
\ No newline at end of file
diff --git a/src/components/services/date.service.ts b/src/components/services/date.service.ts
index 7a4a187..d263e41 100644
--- a/src/components/services/date.service.ts
+++ b/src/components/services/date.service.ts
@@ -6,6 +6,7 @@ export class DateService {
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
+ second: '2-digit',
});
}
}
\ No newline at end of file
diff --git a/src/components/views/BankView.vue b/src/components/views/BankView.vue
index 9e7dfdc..e43f725 100644
--- a/src/components/views/BankView.vue
+++ b/src/components/views/BankView.vue
@@ -1,15 +1,18 @@
-
- {{ CurrencyService.toString(balance) }}
- Kontoinhaber: John Doe
- Kontonummer: 0000123456
+
+ {{ CurrencyService.toString(accountDetails.balance) }}
+ Kontoinhaber: {{ `${accountDetails.firstName} ${accountDetails.lastName}` }}
+ Kontonummer: {{ accountDetails.accountNumber }}
-
+
|