Skip to content

Commit 0ca2a33

Browse files
committed
fix(ts): fix TypeScript errors
1 parent 5556877 commit 0ca2a33

File tree

12 files changed

+62
-100
lines changed

12 files changed

+62
-100
lines changed

Diff for: templates/app/client/app/account(auth)/login/login.component.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export class LoginComponent {
3434
errors = {login: undefined};
3535
submitted = false;
3636
AuthService;
37-
<%_ if(filters.ngroute) { -%><% } %>
37+
<%_ if(filters.ngroute) { -%>
38+
Router;<% } %>
3839
<%_ if(filters.uirouter) { -%>
3940
StateService;<% } %>
4041

Diff for: templates/app/client/app/account(auth)/signup/signup.component.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import { Component } from '@angular/core';
33
<%_ if(filters.uirouter) { -%>
44
import { StateService } from 'ui-router-ng2';<% } %>
5-
<%_ if(filters.ngroute) { -%><% } %>
5+
<%_ if(filters.ngroute) { -%>
6+
import { Router } from '@angular/router';<% } %>
67
import { AuthService } from '../../../components/auth/auth.service';
7-
import {ANGULARCLASS_MATCH_CONTROL_DIRECTIVES} from '@angularclass/match-control';
88

99
<%_ if(filters.flow) { -%>
1010
type User = {
@@ -21,8 +21,7 @@ interface User {
2121

2222
@Component({
2323
selector: 'signup',
24-
template: require('./signup.<%=templateExt%>'),
25-
directives: [...ANGULARCLASS_MATCH_CONTROL_DIRECTIVES]
24+
template: require('./signup.<%=templateExt%>')
2625
})
2726
export class SignupComponent {
2827
user: User = {
@@ -33,14 +32,16 @@ export class SignupComponent {
3332
errors = {};
3433
submitted = false;
3534
AuthService;
36-
<%_ if(filters.ngroute) { -%><% } %>
35+
<%_ if(filters.ngroute) { -%>
36+
Router;<% } %>
3737
<%_ if(filters.uirouter) { -%>
3838
StateService;<% } %>
3939

40-
static parameters = [AuthService, <% if(filters.ngroute) { %><% } else { %>StateService<% } %>];
41-
constructor(_AuthService_: AuthService, <% if(filters.ngroute) { %><% } else { %>_StateService_: StateService<% } %>) {
40+
static parameters = [AuthService, <% if(filters.ngroute) { %>Router<% } else { %>StateService<% } %>];
41+
constructor(_AuthService_: AuthService, <% if(filters.ngroute) { %>router: Router<% } else { %>_StateService_: StateService<% } %>) {
4242
this.AuthService = _AuthService_;
43-
<%_ if(filters.ngroute) { -%><% } -%>
43+
<%_ if(filters.ngroute) { -%>
44+
this.Router = router;<% } -%>
4445
<%_ if(filters.uirouter) { -%>
4546
this.StateService = _StateService_;<% } -%>
4647
}

Diff for: templates/app/client/app/admin(auth)/admin.component.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class AdminComponent {
1212

1313
<%_ } _%>
1414
static parameters = [UserService];
15-
constructor(userService: UserService) {
15+
constructor(<%= private() %>userService: UserService) {
1616
this.userService = userService;
1717
// Use the user service to fetch all users
1818
this.userService.query().subscribe(users => {

Diff for: templates/app/client/app/app.constants.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<%_ if(filters.babel) { -%>
22
export default from '../../server/config/environment/shared';<% } %>
33
<%_ if(filters.ts) { -%>
4-
import shared from '../../server/config/environment/shared';
4+
import shared from '../../server/config/environment/shared.js';
55

66
export default shared;<% } %>

Diff for: templates/app/client/app/app.module.js

+3-50
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,9 @@
1-
// import angular from 'angular';
2-
// // import ngAnimate from 'angular-animate';
3-
// import ngCookies from 'angular-cookies';
4-
// import ngResource from 'angular-resource';
5-
// import ngSanitize from 'angular-sanitize';
6-
// <%_ if(filters.socketio) { _%>
7-
// import 'angular-socket-io';<% } %>
8-
// <%_ if(filters.ngroute) { _%>
9-
// const ngRoute = require('angular-route');<% } %>
10-
// <%_ if(filters.uirouter) { _%>
11-
// import uiRouter from 'angular-ui-router';<% } %>
12-
// <%_ if(filters.uibootstrap) { _%>
13-
// import uiBootstrap from 'angular-ui-bootstrap';<% } %>
14-
// // import ngMessages from 'angular-messages';
15-
// <%_ if(filters.auth) { _%>
16-
// // import ngValidationMatch from 'angular-validation-match';<% } %>
17-
18-
// import {routeConfig} from './app.config';
19-
20-
// <%_ if(filters.auth) { _%>
21-
// import _Auth from '../components/auth/auth.module';
22-
// import account from './account';
23-
// import admin from './admin';<% } %>
24-
// import navbar from '../components/navbar/navbar.component';
25-
// import footer from '../components/footer/footer.component';
26-
// import main from './main/main.component';
27-
// import constants from './app.constants';
28-
// import util from '../components/util/util.module';
29-
// <%_ if(filters.socketio) { _%>
30-
// import socket from '../components/socket/socket.service';<% } %>
31-
32-
// .config(routeConfig)
33-
// <%_ if(filters.auth) { _%>
34-
// .run(function($rootScope, $location, Auth) {
35-
// 'ngInject';
36-
// // Redirect to login if route requires auth and you're not logged in
37-
// $rootScope.$on('$stateChangeStart', function(event, next) {
38-
// Auth.isLoggedIn(function(loggedIn) {
39-
// if(next.authenticate && !loggedIn) {
40-
// $location.path('/login');
41-
// }
42-
// });
43-
// });
44-
// })<% } %>;
45-
46-
471
import {
482
NgModule,
493
ErrorHandler,
504
Injectable,
515
ApplicationRef,
6+
Provider,
527
} from '@angular/core';
538
import { BrowserModule } from '@angular/platform-browser';
549
import {
@@ -60,9 +15,7 @@ import {
6015
import {
6116
removeNgStyles,
6217
createNewHosts,
63-
disposeOldHosts,
6418
createInputTransfer,
65-
restoreInputValues,
6619
} from '@angularclass/hmr';
6720
<%_ if (filters.uirouter) { -%>
6821
import { UIRouterModule } from 'ui-router-ng2';<% } %>
@@ -79,7 +32,7 @@ import { AdminModule } from './admin/admin.module';
7932

8033
import constants from './app.constants';
8134

82-
let providers = [
35+
let providers: Provider[] = [
8336
provideAuth({
8437
// Allow using AuthHttp while not logged in
8538
noJwtError: true,
@@ -134,7 +87,7 @@ const appRoutes: Routes = [
13487
})
13588
export class AppModule {
13689
static parameters = [ApplicationRef];
137-
constructor(appRef/*: ApplicationRef*/) {
90+
constructor(<%= private() %>appRef: ApplicationRef) {
13891
this.appRef = appRef;
13992
}
14093

Diff for: templates/app/client/app/main/main.component.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ export class MainComponent implements OnInit<% if(filters.ws) { %>, OnDestroy<%
1515
<%_ if(filters.models) { -%>
1616
newThing = '';<% } %>
1717

18-
<%_ if(filters.babel) { -%>
19-
static parameters = [Http, SocketService];<% } %>
18+
static parameters = [Http, SocketService];
2019
constructor(<%= private() %>http: Http<% if(filters.ws) { %>, <%= private() %>socketService: SocketService<% } %>) {
2120
this.Http = http;
2221
<%_ if(filters.ws) { -%>

Diff for: templates/app/client/components/auth(auth)/auth.service.js

+18-16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Http } from '@angular/http';
66
import { Observable } from 'rxjs/Observable';
77
import 'rxjs/add/operator/toPromise';
88
import { safeCb, extractData } from '../util';
9-
import { userRoles } from '../../app/app.constants';
9+
import constants from '../../app/app.constants';
1010

1111
// @flow
1212
class User {
@@ -19,19 +19,19 @@ class User {
1919

2020
@Injectable()
2121
export class AuthService {
22-
_currentUser: User = {};
22+
_currentUser: User = new User();
2323
@Output() currentUserChanged = new EventEmitter(true);
24-
userRoles = userRoles || [];
24+
userRoles = constants.userRoles || [];
2525

2626
static parameters = [Http, AuthHttp, UserService];
27-
constructor(_Http_: Http, _AuthHttp_: AuthHttp, _UserService_: UserService) {
28-
this.Http = _Http_;
29-
this.AuthHttp = _AuthHttp_;
30-
this.UserService = _UserService_;
27+
constructor(<%= private() %>http: Http, <%= private() %>authHttp: AuthHttp, <%= private() %>userService: UserService) {
28+
this.Http = http;
29+
this.AuthHttp = authHttp;
30+
this.UserService = userService;
3131

3232
if(localStorage.getItem('id_token')) {
3333
this.UserService.get().toPromise()
34-
.then(user => {
34+
.then((user: User) => {
3535
this.currentUser = user;
3636
})
3737
.catch(err => {
@@ -48,7 +48,7 @@ export class AuthService {
4848
* @param {String} role - role to check against
4949
*/
5050
static hasRole(userRole, role) {
51-
return userRoles.indexOf(userRole) >= userRoles.indexOf(role);
51+
return constants.userRoles.indexOf(userRole) >= constants.userRoles.indexOf(role);
5252
}
5353

5454
get currentUser() {
@@ -78,7 +78,7 @@ export class AuthService {
7878
localStorage.setItem('id_token', res.token);
7979
return this.UserService.get().toPromise();
8080
})
81-
.then(user => {
81+
.then((user: User) => {
8282
this.currentUser = user;
8383
localStorage.setItem('user', JSON.stringify(user));
8484
safeCb(callback)(null, user);
@@ -98,7 +98,7 @@ export class AuthService {
9898
logout() {
9999
localStorage.removeItem('user');
100100
localStorage.removeItem('id_token');
101-
this.currentUser = {};
101+
this.currentUser = new User();
102102
return Promise.resolve();
103103
}
104104

@@ -115,7 +115,7 @@ export class AuthService {
115115
localStorage.setItem('id_token', data.token);
116116
return this.UserService.get().toPromise();
117117
})
118-
.then(_user => {
118+
.then((_user: User) => {
119119
this.currentUser = _user;
120120
return safeCb(callback)(null, _user);
121121
})
@@ -135,6 +135,7 @@ export class AuthService {
135135
*/
136136
changePassword(oldPassword, newPassword, callback) {
137137
return this.UserService.changePassword({id: this.currentUser._id}, oldPassword, newPassword)
138+
.toPromise()
138139
.then(() => safeCb(callback)(null))
139140
.catch(err => safeCb(callback)(err));
140141
}
@@ -145,7 +146,7 @@ export class AuthService {
145146
* @param {Function} [callback] - function(user)
146147
* @return {Promise}
147148
*/
148-
getCurrentUser(callback) {
149+
getCurrentUser(callback?) {
149150
safeCb(callback)(this.currentUser);
150151
return Promise.resolve(this.currentUser);
151152
}
@@ -161,9 +162,10 @@ export class AuthService {
161162

162163
/**
163164
* Checks if user is logged in
165+
* @param {function} [callback]
164166
* @returns {Promise}
165167
*/
166-
isLoggedIn(callback) {
168+
isLoggedIn(callback<% if(filters.ts) { %>?<% } %>) {
167169
let is = !!this.currentUser._id;
168170
safeCb(callback)(is);
169171
return Promise.resolve(is);
@@ -180,10 +182,10 @@ export class AuthService {
180182
/**
181183
* Check if a user is an admin
182184
*
183-
* @param {Function|*} callback - optional, function(is)
185+
* @param {Function|*} [callback] - optional, function(is)
184186
* @return {Promise}
185187
*/
186-
isAdmin(callback) {
188+
isAdmin(callback?) {
187189
return this.getCurrentUser().then(user => {
188190
var is = user.role === 'admin';
189191
safeCb(callback)(is);

Diff for: templates/app/client/components/auth(auth)/user.service.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,46 @@ import 'rxjs/add/operator/toPromise';
1010
// @flow
1111
type UserType = {
1212
// TODO: use Mongoose model
13-
name: string;
14-
email: string;
13+
id?: string;
14+
_id?: string;
15+
name?: string;
16+
email?: string;
17+
}
18+
19+
function handleError(err) {
20+
return Observable.throw(err.json().error || 'Server error');
1521
}
1622

1723
@Injectable()
1824
export class UserService {
1925
static parameters = [AuthHttp];
20-
constructor(authHttp: AuthHttp) {
26+
constructor(<%= private() %>authHttp: AuthHttp) {
2127
this.AuthHttp = authHttp;
2228
}
2329

24-
handleError(err) {
25-
Observable.throw(err.json().error || 'Server error');
26-
}
27-
2830
query(): Observable<UserType[]> {
2931
return this.AuthHttp.get('/api/users/')
3032
.map((res:Response) => res.json())
31-
.catch(this.handleError);
33+
.catch(handleError);
3234
}
33-
get(user = {id: 'me'}): Observable<UserType> {
35+
get(user: UserType = {id: 'me'}): Observable<UserType> {
3436
return this.AuthHttp.get(`/api/users/${user.id || user._id}`)
3537
.map((res:Response) => res.json())
36-
.catch(this.handleError);
38+
.catch(handleError);
3739
}
3840
create(user: UserType) {
3941
return this.AuthHttp.post('/api/users/', user)
4042
.map((res:Response) => res.json())
41-
.catch(this.handleError);
43+
.catch(handleError);
4244
}
4345
changePassword(user, oldPassword, newPassword) {
4446
return this.AuthHttp.put(`/api/users/${user.id || user._id}/password`, {oldPassword, newPassword})
4547
.map((res:Response) => res.json())
46-
.catch(this.handleError);
48+
.catch(handleError);
4749
}
4850
remove(user) {
4951
return this.AuthHttp.delete(`/api/users/${user.id || user._id}`)
5052
.map(() => user)
51-
.catch(this.handleError);
53+
.catch(handleError);
5254
}
5355
}

Diff for: templates/app/client/components/navbar/navbar.component.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class NavbarComponent {
2222
<%_ if(filters.auth) { -%>
2323

2424
static parameters = [AuthService<% if(filters.uirouter) { %>, StateService<% } else { %>, Router<% } %>];
25-
constructor(authService: AuthService<% if(filters.uirouter) { %>, stateService: StateService<% } else { %>, router: Router<% } %>) {
25+
constructor(<%= private() %>authService: AuthService<% if(filters.uirouter) { %>, <%= private() %>stateService: StateService<% } else { %>, <%= private() %>router: Router<% } %>) {
2626
this.AuthService = authService;
2727
<%_ if(filters.uirouter) { -%>
2828
this.StateService = stateService;<% } %>
@@ -32,7 +32,7 @@ export class NavbarComponent {
3232
this.reset();
3333

3434
this.AuthService.currentUserChanged.subscribe(user => {
35-
this.currentuser = user;
35+
this.currentUser = user;
3636
this.reset();
3737
});
3838
}

Diff for: templates/app/client/components/util.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ export function urlParse(url) {
4444
* @return {Boolean} - true if url is same origin
4545
*/
4646
export function isSameOrigin(url, origins) {
47-
url = Util.urlParse(url);
47+
url = urlParse(url);
4848
origins = (origins && [].concat(origins)) || [];
49-
origins = origins.map(Util.urlParse);
49+
origins = origins.map(urlParse);
5050
origins.push(window.location);
5151
origins = origins.filter(function(o) {
5252
let hostnameCheck = url.hostname === o.hostname;

Diff for: templates/app/server/api/user(auth)/user.controller.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function create(req, res) {
4747
<% if (filters.mongooseModels) { %>var newUser = new User(req.body);
4848
newUser.provider = 'local';
4949
newUser.role = 'user';
50-
newUser.save()<% }
50+
return newUser.save()<% }
5151
if (filters.sequelizeModels) { %>var newUser = User.build(req.body);
5252
newUser.setDataValue('provider', 'local');
5353
newUser.setDataValue('role', 'user');

0 commit comments

Comments
 (0)