Skip to content

Commit

Permalink
Merge pull request #62 from TIVMOF/feat/bank-account-page-backend
Browse files Browse the repository at this point in the history
feat: New enpoint for bank account info
  • Loading branch information
TIVMOF authored Jan 24, 2025
2 parents 9ec1126 + e957e3b commit a8b936e
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 218 deletions.
94 changes: 85 additions & 9 deletions pi-bank-backend/api/BankService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { BankAccountRepository as BankAccountDao } from "../gen/pi-bank-backend/
import { CardRepository as CardDao } from "../gen/pi-bank-backend/dao/card/CardRepository";
import { TransactionRepository as TransactionDao } from "../gen/pi-bank-backend/dao/transaction/TransactionRepository";
import { UserRepository as UserDao } from "../gen/pi-bank-backend/dao/user/UserRepository";
import { CardTypeRepository as CardTypeDao } from "../gen/pi-bank-backend/dao/Settings/CardTypeRepository"
import { CardTypeRepository as CardTypeDao } from "../gen/pi-bank-backend/dao/Settings/CardTypeRepository";
import { BankAccountTypeRepository as BankAccountTypeDao } from "../gen/pi-bank-backend/dao/Settings/BankAccountTypeRepository";
import { BankAccountStatusRepository as BankAccountStatusDao } from "../gen/pi-bank-backend/dao/Settings/BankAccountStatusRepository";
import { CurrencyRepository as CurrencyDao } from "../../codbex-currencies/gen/codbex-currencies/dao/Currencies/CurrencyRepository";
import { CountryRepository as CountryDao } from "../../codbex-countries/gen/codbex-countries/dao/Countries/CountryRepository";

Expand All @@ -15,6 +17,8 @@ class BankService {
private readonly transactionDao;
private readonly userDao;
private readonly cardTypeDao;
private readonly bankAccountTypeDao;
private readonly bankAccountStatusDao;
private readonly currencyDao;
private readonly countryDao;

Expand All @@ -24,6 +28,8 @@ class BankService {
this.transactionDao = new TransactionDao();
this.userDao = new UserDao();
this.cardTypeDao = new CardTypeDao();
this.bankAccountTypeDao = new BankAccountTypeDao();
this.bankAccountStatusDao = new BankAccountStatusDao();
this.currencyDao = new CurrencyDao();
this.countryDao = new CountryDao();
}
Expand Down Expand Up @@ -349,29 +355,99 @@ class BankService {
userBankAccounts.forEach(bankAccount => {
allCards.forEach(card => {
if (card.BankAccount === bankAccount.Id) {
userCards.push(card);
const expirationDate = new Date(card.ExpirationDate);

const month = (expirationDate.getMonth() + 1).toString().padStart(2, '0');
const year = expirationDate.getFullYear().toString().slice(-2);

const formattedDate = `${month}/${year}`;

const cardTypeName = this.cardTypeDao.findById(card.CardType).Name;
const bankAccount = this.bankAccountDao.findById(card.BankAccount);
const currencyCode = this.currencyDao.findById(bankAccount.Currency).Code;

userCards.push({
"CardNumber": card.CardNumber,
"ExpirationDate": formattedDate,
"CardType": cardTypeName,
"Balance": bankAccount.Amount,
"BankAccount": bankAccount.Id,
"Currency": currencyCode
});
}
})
})

const finalizaedUserCards = userCards.map(card => {
response.setStatus(response.OK);
return { "UserCards": userCards };

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

@Get("/bankAccountInfo/:bankAccountId")
public getBankAccountInfo(_: any, ctx: any) {
const bankAccountId = ctx.pathParameters.bankAccountId;

const bankAccount = this.bankAccountDao.findById(bankAccountId);

if (!bankAccount) {
response.setStatus(response.NOT_FOUND);
return { message: "Bank Account with that ID doesn't exist!" };
}

try {
const creationDate = new Date(bankAccount.CreationDate);

const date = creationDate.getDate();
const month = (creationDate.getMonth() + 1).toString().padStart(2, '0');
const year = creationDate.getFullYear().toString();

const formattedCreationDate = `${date}/${month}/${year}`;

const bankAccountInfo = {
"IBAN": bankAccount.IBAN,
"User": this.userDao.findById(bankAccount.User).Name,
"Amount": bankAccount.Amount,
"Currency": this.currencyDao.findById(bankAccount.Currency).Code,
"Type": this.bankAccountTypeDao.findById(bankAccount.Type).Name,
"Status": this.bankAccountStatusDao.findById(bankAccount.Status).Name,
"CreationDate": formattedCreationDate
}
const bankAccountCards = this.cardDao.findAll({
$filter: {
equals: { BankAccount: bankAccountId }
}
})

const finalizedBankAccountCards = bankAccountCards.map(card => {
const expirationDate = new Date(card.ExpirationDate);

const month = (expirationDate.getMonth() + 1).toString().padStart(2, '0');
const year = expirationDate.getFullYear().toString().slice(-2);

const formattedDate = `${month}/${year}`;
const formattedExpirationDate = `${month}/${year}`;

const cardTypeName = this.cardTypeDao.findById(card.CardType).Name;
const currencyCode = this.currencyDao.findById(bankAccount.Currency).Code;

return {
"CardNumber": card.CardNumber,
"ExpirationDate": formattedDate,
"CardType": this.cardTypeDao.findById(card.CardType).Name,
"Balance": this.bankAccountDao.findById(card.BankAccount).Amount
"ExpirationDate": formattedExpirationDate,
"CardType": cardTypeName,
"Balance": bankAccount.Amount,
"CV": card.CV,
"Currency": currencyCode
}
});
})

response.setStatus(response.OK);
return { "UserCards": finalizaedUserCards };
return {
"BankAccount": bankAccountInfo,
"BankAccountCards": finalizedBankAccountCards
};

} catch (e: any) {
response.setStatus(response.BAD_REQUEST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ class BankAccountService {
}

private validateEntity(entity: any): void {
if (entity.Name?.length > 500) {
throw new ValidationError(`The 'Name' exceeds the maximum length of [500] characters`);
}
if (entity.IBAN === null || entity.IBAN === undefined) {
throw new ValidationError(`The 'IBAN' property is required, provide a valid value`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { EntityUtils } from "../utils/EntityUtils";

export interface BankAccountEntity {
readonly Id: number;
Name?: string;
IBAN: string;
User?: number;
Amount: number;
Expand All @@ -17,7 +16,6 @@ export interface BankAccountEntity {
}

export interface BankAccountCreateEntity {
readonly Name?: string;
readonly IBAN: string;
readonly User?: number;
readonly Amount: number;
Expand All @@ -34,7 +32,6 @@ export interface BankAccountEntityOptions {
$filter?: {
equals?: {
Id?: number | number[];
Name?: string | string[];
IBAN?: string | string[];
User?: number | number[];
Amount?: number | number[];
Expand All @@ -45,7 +42,6 @@ export interface BankAccountEntityOptions {
};
notEquals?: {
Id?: number | number[];
Name?: string | string[];
IBAN?: string | string[];
User?: number | number[];
Amount?: number | number[];
Expand All @@ -56,7 +52,6 @@ export interface BankAccountEntityOptions {
};
contains?: {
Id?: number;
Name?: string;
IBAN?: string;
User?: number;
Amount?: number;
Expand All @@ -67,7 +62,6 @@ export interface BankAccountEntityOptions {
};
greaterThan?: {
Id?: number;
Name?: string;
IBAN?: string;
User?: number;
Amount?: number;
Expand All @@ -78,7 +72,6 @@ export interface BankAccountEntityOptions {
};
greaterThanOrEqual?: {
Id?: number;
Name?: string;
IBAN?: string;
User?: number;
Amount?: number;
Expand All @@ -89,7 +82,6 @@ export interface BankAccountEntityOptions {
};
lessThan?: {
Id?: number;
Name?: string;
IBAN?: string;
User?: number;
Amount?: number;
Expand All @@ -100,7 +92,6 @@ export interface BankAccountEntityOptions {
};
lessThanOrEqual?: {
Id?: number;
Name?: string;
IBAN?: string;
User?: number;
Amount?: number;
Expand Down Expand Up @@ -144,11 +135,6 @@ export class BankAccountRepository {
id: true,
autoIncrement: true,
},
{
name: "Name",
column: "BANKACCOUNT_NAME",
type: "VARCHAR",
},
{
name: "IBAN",
column: "BANKACCOUNT_PROPERTY3",
Expand Down
54 changes: 2 additions & 52 deletions pi-bank-backend/gen/pi-bank-backend/pi-bank-backend.openapi
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,6 @@ paths:
notEquals:
Id: 33
contains:
Name: "abcd"
IBAN: "abcd"
greaterThan:
Id: 0
Expand All @@ -701,7 +700,6 @@ paths:
value:
$filter:
contains:
Name: "abcd"
IBAN: "abcd"
countWithGreaterThan:
summary: Count with Greater Than
Expand Down Expand Up @@ -766,7 +764,6 @@ paths:
notEquals:
Id: 33
contains:
Name: "abcd"
IBAN: "abcd"
greaterThan:
Id: 0
Expand All @@ -789,7 +786,6 @@ paths:
value:
$filter:
contains:
Name: "abcd"
IBAN: "abcd"
searchWithGreaterThan:
summary: Search with Greater Than
Expand Down Expand Up @@ -3182,10 +3178,6 @@ components:
Id:
type: integer
format: int32
Name:
type: string
minLength: 0
maxLength: 500
IBAN:
type: string
minLength: 0
Expand Down Expand Up @@ -3223,17 +3215,6 @@ components:
items:
type: integer
format: int32
Name:
oneOf:
- type: string
minLength: 0
maxLength: 500
- type: array
items:
type: string
format: double
minLength: 0
maxLength: 500
IBAN:
oneOf:
- type: string
Expand Down Expand Up @@ -3298,17 +3279,6 @@ components:
items:
type: integer
format: int32
Name:
oneOf:
- type: string
minLength: 0
maxLength: 500
- type: array
items:
type: string
format: double
minLength: 0
maxLength: 500
IBAN:
oneOf:
- type: string
Expand Down Expand Up @@ -3366,10 +3336,6 @@ components:
type: object
properties:
Id:
Name:
type: string
minLength: 0
maxLength: 500
IBAN:
type: string
minLength: 0
Expand All @@ -3386,10 +3352,6 @@ components:
Id:
type: integer
format: int32
Name:
type: string
minLength: 0
maxLength: 500
IBAN:
type: string
minLength: 0
Expand All @@ -3416,10 +3378,6 @@ components:
Id:
type: integer
format: int32
Name:
type: string
minLength: 0
maxLength: 500
IBAN:
type: string
minLength: 0
Expand All @@ -3446,10 +3404,6 @@ components:
Id:
type: integer
format: int32
Name:
type: string
minLength: 0
maxLength: 500
IBAN:
type: string
minLength: 0
Expand All @@ -3476,10 +3430,6 @@ components:
Id:
type: integer
format: int32
Name:
type: string
minLength: 0
maxLength: 500
IBAN:
type: string
minLength: 0
Expand All @@ -3502,12 +3452,12 @@ components:
CreationDate:
$select:
type: array
example: ["Id", "Name", "IBAN", "User", "Amount", "Currency", "Type", "Status", "CreationDate"]
example: ["Id", "IBAN", "User", "Amount", "Currency", "Type", "Status", "CreationDate"]
items:
type: string
$sort:
- type: string
example: "Id,Name,IBAN,User,Amount,Currency,Type,Status,CreationDate"
example: "Id,IBAN,User,Amount,Currency,Type,Status,CreationDate"
$order:
type: string
enum: ["asc", "desc"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@
"nullable": true,
"name": "BANKACCOUNT_ID"
},
{
"type": "VARCHAR",
"length": 500,
"nullable": true,
"name": "BANKACCOUNT_NAME"
},
{
"type": "VARCHAR",
"length": 20,
Expand Down
Loading

0 comments on commit a8b936e

Please sign in to comment.