Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update NestJS packages #415

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
with:
node-version: 18
cache: 'npm'
- run: npm install
working-directory: ${{github.workspace}}/generators/node-server/resources
- run: npm ci
- run: npm run test
- name: Run npm sonar:scanner
Expand Down
1 change: 0 additions & 1 deletion generators/node-server/entity-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const entityFiles = {
templates: [
'src/domain/_entityFileName_.entity.ts',
'src/module/_entityFileName_.module.ts',
'src/repository/_entityFileName_.repository.ts',
'src/service/_entityFileName_.service.ts',
'src/service/dto/_entityFileName_.dto.ts',
'src/service/mapper/_entityFileName_.mapper.ts',
Expand Down
2 changes: 0 additions & 2 deletions generators/node-server/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export const serverFiles = {
'src/web/rest/account.controller.ts',
'src/web/rest/public.user.controller.ts',
'src/web/rest/management.controller.ts',
'src/repository/user.repository.ts',
'src/repository/authority.repository.ts',
'src/module/user.module.ts',
'src/module/auth.module.ts',
'src/config/application-dev.yml',
Expand Down
32 changes: 16 additions & 16 deletions generators/node-server/resources/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"dependencies": {
"browser-sync-client": "3.0.2",
"@nestjs/common": "7.5.1",
"@nestjs/core": "7.5.1",
"@nestjs/jwt": "7.2.0",
"@nestjs/passport": "7.1.0",
"@nestjs/platform-express": "7.5.1",
"@nestjs/serve-static": "2.1.4",
"@nestjs/swagger": "4.8.0",
"@nestjs/typeorm": "7.1.4",
"@nestjs/common": "8.4.7",
"@nestjs/core": "8.4.7",
"@nestjs/jwt": "8.0.1",
"@nestjs/passport": "8.0.1",
"@nestjs/platform-express": "8.4.7",
"@nestjs/serve-static": "2.2.2",
"@nestjs/swagger": "5.2.1",
"@nestjs/typeorm": "8.1.4",
"bcrypt": "5.1.1",
"class-transformer": "0.5.1",
"class-validator": "0.13.1",
Expand All @@ -18,25 +18,25 @@
"express-session": "1.17.3",
"js-yaml": "4.1.0",
"jwt-decode": "3.1.1",
"mongodb": "6.2.0",
"mongodb": "5.9.1",
"mysql2": "2.2.5",
"pg": "8.4.2",
"oracledb": "5.0.0",
"mssql": "6.2.3",
"pg": "8.5.1",
"oracledb": "5.1.0",
"mssql": "9.1.1",
"passport": "0.4.1",
"passport-jwt": "4.0.0",
"passport-oauth2": "1.7.0",
"reflect-metadata": "0.1.14",
"rxjs": "6.6.3",
"rxjs": "7.8.1",
"mongodb-memory-server": "6.9.2",
"sqlite3": "5.1.6",
"swagger-ui-express": "5.0.0",
"typeorm": "0.2.45",
"typeorm-encrypted": "0.5.6"
"typeorm": "0.3.17",
"typeorm-encrypted": "0.8.0"
},
"devDependencies": {
"@jest/globals": "29.7.0",
"@nestjs/testing": "7.5.1",
"@nestjs/testing": "8.4.7",
"@types/bcrypt": "5.0.2",
"@types/express": "4.17.1",
"@types/express-serve-static-core": "4.17.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ export class CreateTables1570200270081 implements MigrationInterface {
if (queryRunner.isTransactionActive) {
await queryRunner.commitTransaction();
}


await queryRunner.connection.synchronize();
}
await queryRunner.connection.synchronize();
}

// eslint-disable-next-line
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%_ const UserEntity = user.persistClass %>
import { MigrationInterface, QueryRunner, getRepository } from 'typeorm';
import { MigrationInterface, QueryRunner } from 'typeorm';
<%_ if (authenticationType !== 'oauth2') { _%>
import { <%= UserEntity %> } from '../domain/user.entity';
import { transformPassword } from '../security';
Expand Down Expand Up @@ -68,7 +68,7 @@ export class SeedUsersRoles1570200490072 implements MigrationInterface {
// eslint-disable-next-line
public async up(queryRunner: QueryRunner): Promise<any> {

const authorityRepository = getRepository("<%- jhiTablePrefix %>_authority");
const authorityRepository = queryRunner.connection.getRepository("<%- jhiTablePrefix %>_authority");

<%_ if (authenticationType === 'oauth2') { _%>

Expand All @@ -79,7 +79,7 @@ export class SeedUsersRoles1570200490072 implements MigrationInterface {
const adminRole = await authorityRepository.save(this.role1);
const userRole = await authorityRepository.save(this.role2);

const userRepository = getRepository("<%- jhiTablePrefix %>_user");
const userRepository = queryRunner.connection.getRepository("<%- jhiTablePrefix %>_user");

this.user1.authorities= [adminRole, userRole];
this.user3.authorities= [adminRole, userRole];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { <%= entityClass %>Controller } from '../web/rest/<%= entityFileName %>.controller';
import { <%= entityClass %>Repository } from '../repository/<%= entityFileName %>.repository';
import { <%= entityClass %>Service } from '../service/<%= entityFileName %>.service';
import { <%= entityClass %> } from '../domain/<%= entityFileName %>.entity';


@Module({
imports: [TypeOrmModule.forFeature([<%= entityClass %>Repository])],
imports: [TypeOrmModule.forFeature([<%= entityClass %>])],
controllers: [<%= entityClass %>Controller],
providers: [<%= entityClass %>Service],
exports: [<%= entityClass %>Service],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import { UserOauth2Controller } from '../web/rest/user.oauth2.controller';
import { config } from '../config';
<%_ } _%>
import { TypeOrmModule } from '@nestjs/typeorm';
import { AuthorityRepository } from '../repository/authority.repository';
import { Authority } from '../domain/authority.entity';

import { PublicUserController } from '../web/rest/public.user.controller';
import { AccountController } from '../web/rest/account.controller';

@Module({
imports: [TypeOrmModule.forFeature([AuthorityRepository]),
imports: [TypeOrmModule.forFeature([Authority]),
UserModule,
PassportModule,
<%_ if (authenticationType === 'jwt') { _%>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Module } from '@nestjs/common';
import { UserController } from '../web/rest/user.controller';
import { ManagementController } from '../web/rest/management.controller';
import { UserRepository } from '../repository/user.repository';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserService } from '../service/user.service';
import { User } from '../domain/user.entity';

@Module({
imports: [TypeOrmModule.forFeature([UserRepository])],
imports: [TypeOrmModule.forFeature([User])],
controllers: [UserController, ManagementController],
providers: [UserService],
exports: [UserService],
Expand Down
4 changes: 0 additions & 4 deletions generators/node-server/templates/server/src/orm.config.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ _%>
synchronize: true,
entities: commonConf.ENTITIES,
migrations: commonConf.MIGRATIONS,
cli: commonConf.CLI,
migrationsRun: commonConf.MIGRATIONS_RUN,
};

Expand All @@ -58,7 +57,6 @@ _%>
synchronize: commonConf.SYNCRONIZE,
entities: commonConf.ENTITIES,
migrations: commonConf.MIGRATIONS,
cli: commonConf.CLI,
migrationsRun: commonConf.MIGRATIONS_RUN,
};
}
Expand All @@ -82,7 +80,6 @@ _%>
synchronize: true,
entities: commonConf.ENTITIES,
migrations: commonConf.MIGRATIONS,
cli: commonConf.CLI,
migrationsRun: commonConf.MIGRATIONS_RUN,
};
}
Expand All @@ -101,7 +98,6 @@ _%>
synchronize: commonConf.SYNCRONIZE,
entities: commonConf.ENTITIES,
migrations: commonConf.MIGRATIONS,
cli: commonConf.CLI,
migrationsRun: commonConf.MIGRATIONS_RUN,
};
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Injectable, HttpException, HttpStatus, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { FindManyOptions, FindOneOptions } from 'typeorm';
import { FindManyOptions, FindOneOptions, Repository } from 'typeorm';
import { <%= dtoClass %> } from '../service/dto/<%= entityFileName %>.dto';
import { <%= entityClass %>Mapper } from '../service/mapper/<%= entityFileName %>.mapper';
import { <%= entityClass %>Repository } from '../repository/<%= entityFileName %>.repository';
import { <%= entityClass %> } from '../domain/<%= entityFileName %>.entity';

const relationshipNames = [];
<%_
Expand All @@ -28,11 +28,11 @@ _%>
export class <%= entityClass %>Service {
logger = new Logger('<%= entityClass %>Service');

constructor(@InjectRepository(<%= entityClass %>Repository) private <%= entityInstance %>Repository: <%= entityClass %>Repository) {}
constructor(@InjectRepository(<%= entityClass %>) private <%= entityInstance %>Repository: Repository<<%= entityClass %>>) {}

async findById(id: <%= pkType %>): Promise<<%= dtoClass %> | undefined> {
const options = { relations: relationshipNames };
const result = await this.<%= entityInstance %>Repository.findOne(id, options);
const options = { where: { id: id }, relations: relationshipNames };
const result = await this.<%= entityInstance %>Repository.findOne(options);
return <%= entityClass %>Mapper.fromEntityToDTO(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { UserLoginDTO } from '../service/dto/user-login.dto';
import { Payload } from '../security/payload.interface';
import * as bcrypt from 'bcrypt';
<%_ } _%>
import { AuthorityRepository } from '../repository/authority.repository';
import { UserService } from '../service/user.service';
import { <%= user.dtoClass%> } from './dto/user.dto';
import { FindManyOptions } from 'typeorm';
import { FindManyOptions, Repository } from 'typeorm';
import { Authority } from '../domain/authority.entity';

<%_
const userIdType = user.primaryKey.tsType;
Expand All @@ -23,7 +23,7 @@ export class AuthService {
<%_ if (authenticationType === 'jwt') { _%>
private readonly jwtService: JwtService,
<%_ } _%>
@InjectRepository(AuthorityRepository) private authorityRepository: AuthorityRepository,
@InjectRepository(Authority) private authorityRepository: Repository<Authority>,
private userService: UserService,
) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import { InjectRepository } from '@nestjs/typeorm';
import { <%= user.persistClass %> } from '../domain/user.entity';
import { <%= user.dtoClass%> } from './dto/user.dto';
import { UserMapper } from './mapper/user.mapper';
import { UserRepository } from '../repository/user.repository';
import { FindManyOptions, FindOneOptions } from 'typeorm';
import { FindManyOptions, FindOneOptions, Repository } from 'typeorm';
import { transformPassword } from '../security';

@Injectable()
export class UserService {
constructor(@InjectRepository(UserRepository) private userRepository: UserRepository) {}
constructor(@InjectRepository(User) private userRepository: Repository<User>) {}

async findById(id: <%= user.primaryKey.tsType %>): Promise<<%= user.dtoClass%> | undefined> {
const result = await this.userRepository.findOne(id);
const result = await this.userRepository.findOneBy({ id });
return UserMapper.fromEntityToDTO(this.flatAuthorities(result))
}

Expand Down
Loading