Skip to content

Commit

Permalink
try fix auth react error
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelo Manganiello committed Dec 1, 2020
1 parent 245d6c3 commit 28757ff
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
6.8.0 CHANGED
-%>
import { browser, element, by, ExpectedConditions as ec } from 'protractor';

import { browser, <%_ if (!skipUserManagement) { _%> element, by, <%_ } _%> ExpectedConditions as ec } from 'protractor';
import { NavBarPage, SignInPage } from '../page-objects/jhi-page-objects';
<%_
let elementGetter = `getText()`;
Expand All @@ -28,7 +27,9 @@ if (enableTranslation) {
}
_%>

<%_ if (!skipUserManagement) { _%>
const expect = chai.expect;
<%_ } _%>

describe('administration', () => {
let navBarPage: NavBarPage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('<%= entityClass %> Controller', () => {
findAndCount: (): any => [entityMock, 0],
save: (): any => entityMock,
update: (): any => entityMock,
delete: (): any => entityMock
deleteById: (): any => entityMock
};


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, Logger } from '@nestjs/common';
import { Injectable, HttpException, HttpStatus, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { FindManyOptions, FindOneOptions } from 'typeorm';
import <%= entityClass %> from '../domain/<%= entityFileName %>.entity';
Expand All @@ -12,7 +12,7 @@ for (idx in relationships) {
const relationshipFieldName = relationships[idx].relationshipFieldName;
const relationshipFieldNamePlural = relationships[idx].relationshipFieldNamePlural;
const ownerSide = relationships[idx].ownerSide;
if (relationshipType === 'many-to-one') { _%>
relationshipNames.push('<%-relationshipFieldName %>');
<%_ } else if (relationshipType === 'many-to-many' && ownerSide === true) { _%>
Expand Down Expand Up @@ -49,8 +49,13 @@ export class <%= entityClass %>Service {
return await this.save(<%= asEntity(entityInstance) %>);
}

async delete(<%= asEntity(entityInstance) %>: <%= entityClass %>): Promise<<%= entityClass %> | undefined> {
return await this.<%= asEntity(entityInstance) %>Repository.remove(<%= asEntity(entityInstance) %>);
async deleteById(id: string): Promise<void | undefined> {
await this.<%= asEntity(entityInstance) %>Repository.delete(id);
const entityFind = await this.findById(id);
if (entityFind) {
throw new HttpException('Error, entity not deleted!', HttpStatus.NOT_FOUND);
}
return;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ export class <%= entityClass %>Controller {
status: 204,
description: 'The record has been successfully deleted.',
})
async remove(@Req() req: Request, @Param('id') id: string): Promise<<%= entityClass %>> {
async deleteById(@Req() req: Request, @Param('id') id: string): Promise<void> {
HeaderUtil.addEntityDeletedHeaders(req.res, '<%= entityClass %>', id);
const toDelete = await this.<%= asEntity(entityInstance) %>Service.findById(id);
return await this.<%= asEntity(entityInstance) %>Service.delete(toDelete);
return await this.<%= asEntity(entityInstance) %>Service.deleteById(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class SeedUsersRoles1570200490072 implements MigrationInterface {
};
<%_ } _%>

// eslint-disable-next-line
public async up(queryRunner: QueryRunner): Promise<any> {

const authorityRepository = getRepository("nhi_authority");
Expand Down
15 changes: 15 additions & 0 deletions generators/server/templates/server/src/service/auth.service.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export class AuthService {
return user;
}
async getAccount(userId: string): Promise<User | undefined> {
const user: any = await this.findUserWithAuthById(userId);
if (!user) {
return;
}
return user;
}
async changePassword(userLogin: string, currentClearTextPassword: string, newPassword: string): Promise<void> {
const userFind = await this.userService.findByfields({ where: { login: userLogin } });
if (!userFind) {
Expand Down Expand Up @@ -119,6 +127,13 @@ export class AuthService {
return loginUser;
}
getAccount(user: User): any {
if (!user) {
return;
}
return user;
}
<%_ } _%>

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class AccountController {
})
async getAccount(@Req() req: Request): Promise<any> {
const user: any = req.user;
return await this.authService.findUserWithAuthById(user.id);
return await this.authService.getAccount(user.id);
}
@Post('/account')
Expand Down Expand Up @@ -130,13 +130,9 @@ export class AccountController {
status: 200,
description: 'User retrieved',
})
getAccount(@Req() req: any): any | void {
getAccount(@Req() req: any): any {
const user: User = req.session.user;
if (user) {
return user;
}
return ;
return this.authService.getAccount(user);
}
<%_ } _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ export class UserOauth2Controller {
if (req.session && req.session.user) {
idTokenFromSession = req.session.user.idToken;
req.session.destroy();
return { idToken: idTokenFromSession, logoutUrl: oauth2Config.logoutUrl };
}
return { idToken: idTokenFromSession, logoutUrl: oauth2Config.logoutUrl };
return;
}

}
2 changes: 1 addition & 1 deletion test-integration/07-run-generated-app-sample.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ launchCurlOrProtractor() {
if [ "$1" = "build" ]; then
sleep 10
else
sleep 130
sleep 150
fi
retryCount=1
maxRetry=10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ entity BloodPressure {
}
entity Weight {
timestamp ZonedDateTime required
weight Double
weight Double required
}
entity Points {
date LocalDate required
Expand Down Expand Up @@ -63,3 +63,5 @@ relationship ManyToOne {
Points{user(login)} to User
}

paginate BloodPressure, Weight with infinite-scroll
paginate Points with pagination

0 comments on commit 28757ff

Please sign in to comment.