File tree Expand file tree Collapse file tree 8 files changed +47
-38
lines changed Expand file tree Collapse file tree 8 files changed +47
-38
lines changed Original file line number Diff line number Diff line change @@ -313,6 +313,8 @@ this.routeGeneratorService.navigateByRouteNames(
313313```
314314
315315## Class transfomer (model handling)
316+ We have included the [ class transformer] ( https://github.com/typestack/class-transformer ) which helps creating models (` src/app/models/* ` ). This transformation can be done
317+ in both direction (rest to model, model to rest).
316318
317319## Dialog service
318320There is a custom dialog implementation for simpler useage of elements in dialogs.
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ import LanguageDetector from 'i18next-browser-languagedetector';
3434/**
3535 * Polyfills
3636 */
37+ import 'reflect-metadata' ;
3738import 'utils/polyfills.utils' ;
3839
3940// Fontawesome setup
Original file line number Diff line number Diff line change 11
2+ import { Expose } from 'class-transformer' ;
3+
24export class UserModel {
3- constructor (
4- public avatarUrl : string ,
5- public login : string ,
6- public htmlUrl : string
7- ) { }
5+
6+ @Expose ( { name : 'avatar_url' } )
7+ public avatarUrl : string = '' ;
8+
9+ public login : string = '' ;
10+
11+ @Expose ( { name : 'html_url' } )
12+ public htmlUrl : string = '' ;
813
914 public getLogin ( ) : string {
1015 return this . login ;
Original file line number Diff line number Diff line change 11import { autoinject } from 'aurelia-framework' ;
2- import { UserService } from './../../services/user.service' ;
2+ import { UserRestService } from './../../services/rest /user.service' ;
33import { UserModel } from './../../models/user.model' ;
44
55@autoinject
@@ -8,10 +8,10 @@ export class UsersViewModel {
88 public users : Array < UserModel > = [ ] ;
99
1010 constructor (
11- private userService : UserService
11+ private userRestService : UserRestService
1212 ) { }
1313
1414 public async activate ( ) : Promise < void > {
15- this . users = await this . userService . getUsers ( ) ;
15+ this . users = await this . userRestService . getUsers ( ) ;
1616 }
1717}
Original file line number Diff line number Diff line change 1+ import { autoinject } from 'aurelia-framework' ;
2+ import { plainToClass } from 'class-transformer' ;
3+
4+ import { RestClient } from './rest-client.service' ;
5+ import { UserModel } from './../../models/user.model' ;
6+
7+ export interface IUser {
8+ avatar_url : string ;
9+ login : string ;
10+ html_url : string ;
11+ }
12+
13+ @autoinject
14+ export class UserRestService {
15+
16+ constructor (
17+ private restClient : RestClient ,
18+ ) {
19+ this . restClient
20+ . useAPI ( )
21+ . withResource ( 'users' ) ;
22+ }
23+
24+ public async getUsers ( ) : Promise < UserModel [ ] > {
25+ const users = await this . restClient . findAll < IUser [ ] > ( ) ;
26+
27+ return plainToClass ( UserModel , users ) ;
28+ }
29+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11{
22 "NAME" : " Development" ,
3- "API_MAIN_URL" : " https://api" ,
3+ "API_MAIN_URL" : " https://api.github.com/ " ,
44 "API_UAM_URL" : " https://api" ,
55 "LOG_LEVEL" : " debug"
66}
Original file line number Diff line number Diff line change 11{
22 "NAME" : " Production" ,
3- "API_MAIN_URL" : " https://api" ,
3+ "API_MAIN_URL" : " https://api.github.com/ " ,
44 "API_UAM_URL" : " https://api" ,
55 "LOG_LEVEL" : " error"
66}
You can’t perform that action at this time.
0 commit comments