File tree Expand file tree Collapse file tree 10 files changed +58
-39
lines changed Expand file tree Collapse file tree 10 files changed +58
-39
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 151151 "aurelia-validation" : " ^1.1.1" ,
152152 "bluebird" : " ^3.5.0" ,
153153 "bootstrap" : " ^4.0.0" ,
154+ "class-transformer" : " ^0.1.9" ,
154155 "i18next-browser-languagedetector" : " ^2.0.0" ,
155156 "isomorphic-fetch" : " ^2.2.1" ,
156157 "jquery" : " ^3.2.1" ,
157158 "moment" : " ^2.18.1" ,
158159 "normalize.css" : " ^8.0.0" ,
159- "popper.js" : " ^1.12.9"
160+ "popper.js" : " ^1.12.9" ,
161+ "reflect-metadata" : " ^0.1.12"
160162 }
161163}
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}
Original file line number Diff line number Diff line change @@ -1745,6 +1745,10 @@ clap@^1.0.9:
17451745 dependencies :
17461746 chalk "^1.1.3"
17471747
1748+ class-transformer@^0.1.9 :
1749+ version "0.1.9"
1750+ resolved "https://registry.yarnpkg.com/class-transformer/-/class-transformer-0.1.9.tgz#29977c528233ca014e6fd9523327ebd31d11ca54"
1751+
17481752class-utils@^0.3.5 :
17491753 version "0.3.6"
17501754 resolved "https://registry.yarnpkg.com/class-utils/-/class-utils-0.3.6.tgz#f93369ae8b9a7ce02fd41faad0ca83033190c463"
@@ -8188,6 +8192,10 @@ reduce-function-call@^1.0.1:
81888192 dependencies :
81898193 balanced-match "^0.4.2"
81908194
8195+ reflect-metadata@^0.1.12 :
8196+ version "0.1.12"
8197+ resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.12.tgz#311bf0c6b63cd782f228a81abe146a2bfa9c56f2"
8198+
81918199regenerate@^1.2.1 :
81928200 version "1.3.3"
81938201 resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.3.3.tgz#0c336d3980553d755c39b586ae3b20aa49c82b7f"
You can’t perform that action at this time.
0 commit comments