Skip to content

Commit

Permalink
Merge pull request #231 from glutengo/bug/issue-230
Browse files Browse the repository at this point in the history
Fix bug regarding pkType refs #230
  • Loading branch information
Angelo Manganiello authored May 28, 2021
2 parents eb0e62b + e5d2be3 commit 058b1da
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

# [2.0.0](https://github.com/jhipster/generator-jhipster-nodejs/tree/v2.0.0) - xx/xx/2021 released date

- Support JHipster primary key type [issue #230](https://github.com/jhipster/generator-jhipster-nodejs/issues/230)
- Entity name duplicated into app.module.ts imports every time entity updated [issue #219](https://github.com/jhipster/generator-jhipster-nodejs/issues/219)

# [2.0.0-beta.1](https://github.com/jhipster/generator-jhipster-nodejs/tree/v2.0.0-beta.1) - 08/04/2021 released date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Account', () => {
};

const testUserAuthenticated: any = {
id: '601d70b6ec992423f8d531bd',
id: 42,
login: 'userlogged',
email: '[email protected]',
password: 'userloggedPassword',
Expand Down
2 changes: 1 addition & 1 deletion generators/server/templates/server/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"eslint-plugin-prettier": "3.3.1",
"jest": "25.2.3",
"nodemon": "1.19.1",
"prettier": "1.17.0",
"prettier": "1.19.0",
"rimraf": "3.0.2",
"sonarqube-scanner": "2.5.0",
"supertest": "6.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ export abstract class BaseEntity {

<%_ if (databaseType === 'mongodb') { _%>
@ObjectIdColumn({ name: '_id' })
<%_ } else { _%>
id?: string;
<%_ } else if (getPkType(databaseType) === 'UUID') { _%>
@PrimaryGeneratedColumn('uuid')
id?: string;
<%_ } else { _%>
@PrimaryGeneratedColumn()
id?: number;
<%_ } _%>
id?: string;

@Column({ nullable: true })
createdBy?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface Payload {

id: string;
id: <%= getPkType(databaseType) === 'Long' ? 'number' : 'string' %>;
username: string;
authorities?: string[];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import { UserService } from '../service/user.service';
import { UserDTO } from './dto/user.dto';
import { FindManyOptions } from 'typeorm';

<%_
const userIdType = getPkType(databaseType) === 'Long' ? 'number' : 'string';
_%>


@Injectable()
export class AuthService {
Expand Down Expand Up @@ -51,7 +55,7 @@ export class AuthService {
return await this.findUserWithAuthById(payload.id);
}
async findUserWithAuthById(userId: string): Promise<UserDTO | undefined> {
async findUserWithAuthById(userId: <%= userIdType %>): Promise<UserDTO | undefined> {
<%_ if (databaseType === 'mongodb') { _%>
const userDTO: UserDTO = await this.userService.findById(userId);
<%_ } else { _%>
Expand All @@ -60,7 +64,7 @@ export class AuthService {
return userDTO;
}
async getAccount(userId: string): Promise<UserDTO | undefined> {
async getAccount(userId: <%= userIdType %>): Promise<UserDTO | undefined> {
const userDTO: UserDTO = await this.findUserWithAuthById(userId);
if (!userDTO) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

/**
* A DTO base objct.
* A DTO base object.
*/
export class BaseDTO {

id?: string;
id?:<%_ if (getPkType(databaseType) === 'Long') { _%>number<%_ } else { _%>string<%_ } _%>;

createdBy?: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { FindManyOptions, FindOneOptions } from 'typeorm';
export class UserService {
constructor(@InjectRepository(UserRepository) private userRepository: UserRepository) {}

async findById(id: string): Promise<UserDTO | undefined> {
async findById(id: <%= getPkType(databaseType) === 'Long' ? 'number' : 'string' %>): Promise<UserDTO | undefined> {
const result = await this.userRepository.findOne(id);
return UserMapper.fromEntityToDTO(this.flatAuthorities(result))
}
Expand Down

0 comments on commit 058b1da

Please sign in to comment.