Skip to content

Commit

Permalink
Fix bug regarding pkType fixes jhipster#230
Browse files Browse the repository at this point in the history
- Use getPkType(databaseType) instead of hardcoded type in NestJS backend
- Bump prettier version for optional chaining support
  • Loading branch information
Angelo Manganiello authored and glutengo committed May 28, 2021
2 parents 53d25ab + 71f554b commit d6ea066
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 12 deletions.
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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"commander": "2.20.0",
"ejs": "2.6.1",
"generator-jhipster": "7.0.0",
"lodash": "4.17.19",
"lodash": "4.17.21",
"meow": "5.0.0",
"semver": "6.1.1",
"shelljs": "0.8.4"
Expand Down

0 comments on commit d6ea066

Please sign in to comment.