Skip to content

Commit d6eb006

Browse files
authored
Update FinancialInstitutionModel.js
1 parent 32d7924 commit d6eb006

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

models/FinancialInstitutionModel.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,47 @@ export class FinancialInstitutionModel {
77
public city: string,
88
public address: string,
99
public createdAt: Date
10-
) {}
10+
) {
11+
this.validate();
12+
}
13+
14+
// Validate the properties of the model
15+
private validate() {
16+
if (!this.id) throw new Error("ID is required.");
17+
if (!this.name) throw new Error("Name is required.");
18+
if (!this.type) throw new Error("Type is required.");
19+
if (!this.country) throw new Error("Country is required.");
20+
if (!this.city) throw new Error("City is required.");
21+
if (!this.address) throw new Error("Address is required.");
22+
}
23+
24+
// Format the full address
25+
public formatAddress(): string {
26+
return `${this.address}, ${this.city}, ${this.country}`;
27+
}
28+
29+
// Get a summary of the financial institution
30+
public getSummary(): string {
31+
return `${this.name} (${this.type}) - Located at: ${this.formatAddress()}`;
32+
}
33+
34+
// Compare two FinancialInstitutionModel instances by name
35+
public compareByName(other: FinancialInstitutionModel): number {
36+
return this.name.localeCompare(other.name);
37+
}
1138
}
39+
40+
// Example usage
41+
if (require.main === module) {
42+
const bank = new FinancialInstitutionModel(
43+
"1",
44+
"Global Bank",
45+
"Commercial",
46+
"USA",
47+
"New York",
48+
"123 Finance St",
49+
new Date()
50+
);
51+
52+
console.log(bank.getSummary());
53+
}

0 commit comments

Comments
 (0)