Skip to content

Commit

Permalink
feat: New endpoint to speed up app loading
Browse files Browse the repository at this point in the history
  • Loading branch information
TIVMOF committed Jan 21, 2025
1 parent d3abe85 commit a750832
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions pi-bank-backend/api/BankService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class BankService {
const sender = this.userDao.findById(senderBankAccount.User);

return {
"Reciever": reciever.Username,
"Receiver": reciever.Username,
"Sender": sender.Username,
"Amount": transaction.Amount,
"Date": formattedDate
Expand All @@ -187,8 +187,8 @@ class BankService {
}
}

@Get("/transactionItems/:userId")
public getTransactionItems(_: any, ctx: any) {
@Get("/userInteractions/:userId")
public getUserInteractions(_: any, ctx: any) {
const userId = ctx.pathParameters.userId;

const user = this.userDao.findById(userId);
Expand Down Expand Up @@ -227,15 +227,39 @@ class BankService {
return { message: "User doesn't have Transactions!" };
}

const allBankAccounts = this.bankAccountDao.findAll();
let userInteractions: any = [];

allBankAccounts.forEach(bankAccount => {
userTransactions.forEach(transaction => {
if (transaction.Sender === bankAccount.Id || transaction.Reciever === bankAccount.Id) {
const username = this.userDao.findById(bankAccount.User).Username;

userInteractions.push({
"Name:": username,
"IBAN": bankAccount.IBAN,
"BankAccountId": bankAccount.Id,
"Amount": bankAccount.Amount
})
}
})
})

userInteractions = Array.from(
new Set(userInteractions.map(interaction => JSON.stringify(interaction)))
).map(jsonString => JSON.parse(jsonString));

response.setStatus(response.OK);
return { "UserTransactions": userTransactions };
return userInteractions;

} catch (e: any) {
response.setStatus(response.BAD_REQUEST);
return { error: e.message };
}
}



@Get("/cards/:userId")
public getCards(_: any, ctx: any) {
const userId = ctx.pathParameters.userId;
Expand Down

0 comments on commit a750832

Please sign in to comment.