File tree Expand file tree Collapse file tree 1 file changed +43
-1
lines changed
Expand file tree Collapse file tree 1 file changed +43
-1
lines changed Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments