From 318a7212981aa3d7c9ae3731b4acfd0bf188c9e1 Mon Sep 17 00:00:00 2001 From: RAHUL RATHORE Date: Mon, 26 Jun 2023 16:25:35 +0530 Subject: [PATCH 1/4] fix(refactor): time off policy module imports --- .../time-off-policy.controller.ts | 28 +++++++++---------- .../time-off-policy/time-off-policy.module.ts | 22 +++++++++------ .../time-off-policy.service.ts | 6 ++-- packages/core/src/user/user.module.ts | 12 +++++--- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/packages/core/src/time-off-policy/time-off-policy.controller.ts b/packages/core/src/time-off-policy/time-off-policy.controller.ts index aa6a5b1cbad..77d19b43087 100644 --- a/packages/core/src/time-off-policy/time-off-policy.controller.ts +++ b/packages/core/src/time-off-policy/time-off-policy.controller.ts @@ -39,7 +39,7 @@ export class TimeOffPolicyController extends CrudController { /** * GET all time off policies using pagination - * + * */ @UseGuards(PermissionGuard) @Permissions(PermissionsEnum.POLICY_VIEW) @@ -53,9 +53,9 @@ export class TimeOffPolicyController extends CrudController { /** * GET all time off policies - * - * @param data - * @returns + * + * @param data + * @returns */ @ApiOperation({ summary: 'Find all policies.' }) @ApiResponse({ @@ -82,9 +82,9 @@ export class TimeOffPolicyController extends CrudController { /** * CREATE time off policy - * - * @param entity - * @returns + * + * @param entity + * @returns */ @ApiOperation({ summary: 'Create new record' }) @ApiResponse({ @@ -102,15 +102,15 @@ export class TimeOffPolicyController extends CrudController { async create( @Body() entity: ITimeOffPolicyCreateInput, ): Promise { - return this.timeOffPolicyService.create(entity); + return await this.timeOffPolicyService.create(entity); } /** * UPDATE time off policy by id - * - * @param id - * @param entity - * @returns + * + * @param id + * @param entity + * @returns */ @ApiOperation({ summary: 'Update record' }) @ApiResponse({ @@ -131,9 +131,9 @@ export class TimeOffPolicyController extends CrudController { @Permissions(PermissionsEnum.POLICY_EDIT) @Put(':id') async update( - @Param('id', UUIDValidationPipe) id: string, + @Param('id', UUIDValidationPipe) id: ITimeOffPolicy['id'], @Body() entity: ITimeOffPolicyUpdateInput ): Promise { - return this.timeOffPolicyService.update(id, entity); + return await this.timeOffPolicyService.update(id, entity); } } diff --git a/packages/core/src/time-off-policy/time-off-policy.module.ts b/packages/core/src/time-off-policy/time-off-policy.module.ts index c271544521e..e4a04c11d5f 100644 --- a/packages/core/src/time-off-policy/time-off-policy.module.ts +++ b/packages/core/src/time-off-policy/time-off-policy.module.ts @@ -3,10 +3,9 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { RouterModule } from 'nest-router'; import { TimeOffPolicyService } from './time-off-policy.service'; import { TimeOffPolicy } from './time-off-policy.entity'; -import { Employee } from '../employee/employee.entity'; import { TimeOffPolicyController } from './time-off-policy.controller'; -import { User } from '../user/user.entity'; -import { UserService } from '../user/user.service'; +import { EmployeeModule } from './../employee/employee.module'; +import { UserModule } from './../user/user.module'; import { TenantModule } from '../tenant/tenant.module'; import { TaskModule } from '../tasks/task.module'; @@ -15,12 +14,19 @@ import { TaskModule } from '../tasks/task.module'; RouterModule.forRoutes([ { path: 'time-off-policy', module: TimeOffPolicyModule }, ]), - TypeOrmModule.forFeature([User, TimeOffPolicy, Employee]), + TypeOrmModule.forFeature([ + TimeOffPolicy + ]), TenantModule, - TaskModule, + UserModule, + EmployeeModule, + TaskModule ], controllers: [TimeOffPolicyController], - providers: [TimeOffPolicyService, UserService], - exports: [TypeOrmModule, UserService], + providers: [TimeOffPolicyService], + exports: [ + TypeOrmModule, + TimeOffPolicyService + ], }) -export class TimeOffPolicyModule {} +export class TimeOffPolicyModule { } diff --git a/packages/core/src/time-off-policy/time-off-policy.service.ts b/packages/core/src/time-off-policy/time-off-policy.service.ts index 88d5349b09d..d37422d1bda 100644 --- a/packages/core/src/time-off-policy/time-off-policy.service.ts +++ b/packages/core/src/time-off-policy/time-off-policy.service.ts @@ -1,13 +1,13 @@ import { Injectable, BadRequestException } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { In, Repository } from 'typeorm'; -import { TimeOffPolicy } from './time-off-policy.entity'; -import { TenantAwareCrudService } from './../core/crud'; -import { Employee } from '../employee/employee.entity'; import { ITimeOffPolicyCreateInput, ITimeOffPolicyUpdateInput } from '@gauzy/contracts'; +import { TimeOffPolicy } from './time-off-policy.entity'; +import { TenantAwareCrudService } from './../core/crud'; +import { Employee } from '../employee/employee.entity'; @Injectable() export class TimeOffPolicyService extends TenantAwareCrudService { diff --git a/packages/core/src/user/user.module.ts b/packages/core/src/user/user.module.ts index 6eebc466368..936cc4909f0 100644 --- a/packages/core/src/user/user.module.ts +++ b/packages/core/src/user/user.module.ts @@ -16,15 +16,19 @@ import { TaskModule } from './../tasks/task.module'; @Module({ imports: [ - RouterModule.forRoutes([{ path: '/user', module: UserModule }]), - forwardRef(() => TypeOrmModule.forFeature([User])), + RouterModule.forRoutes([ + { path: '/user', module: UserModule } + ]), + forwardRef(() => TypeOrmModule.forFeature([ + User + ])), forwardRef(() => TenantModule), + forwardRef(() => TaskModule), CqrsModule, FactoryResetModule, - forwardRef(() => TaskModule), ], controllers: [UserController], providers: [UserService, ...CommandHandlers], exports: [TypeOrmModule, UserService], }) -export class UserModule {} +export class UserModule { } From decaf2927ab93cf68696ee532c4e8d732342b44c Mon Sep 17 00:00:00 2001 From: RAHUL RATHORE Date: Mon, 26 Jun 2023 16:31:24 +0530 Subject: [PATCH 2/4] fix(refactor): employee recurring expense module imports --- .../employee-recurring-expense.module.ts | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/core/src/employee-recurring-expense/employee-recurring-expense.module.ts b/packages/core/src/employee-recurring-expense/employee-recurring-expense.module.ts index 4138f10821e..7f0fd377773 100644 --- a/packages/core/src/employee-recurring-expense/employee-recurring-expense.module.ts +++ b/packages/core/src/employee-recurring-expense/employee-recurring-expense.module.ts @@ -7,8 +7,7 @@ import { EmployeeRecurringExpenseController } from './employee-recurring-expense import { EmployeeRecurringExpense } from './employee-recurring-expense.entity'; import { EmployeeRecurringExpenseService } from './employee-recurring-expense.service'; import { QueryHandlers } from './queries/handlers'; -import { User } from '../user/user.entity'; -import { UserService } from '../user/user.service'; +import { UserModule } from './../user/user.module'; import { TenantModule } from '../tenant/tenant.module'; import { TaskModule } from '../tasks/task.module'; @@ -20,18 +19,23 @@ import { TaskModule } from '../tasks/task.module'; module: EmployeeRecurringExpenseModule, }, ]), - TypeOrmModule.forFeature([EmployeeRecurringExpense, User]), + TypeOrmModule.forFeature([ + EmployeeRecurringExpense + ]), CqrsModule, TenantModule, - TaskModule, + UserModule, + TaskModule ], controllers: [EmployeeRecurringExpenseController], providers: [ EmployeeRecurringExpenseService, ...QueryHandlers, - UserService, - ...CommandHandlers, + ...CommandHandlers + ], + exports: [ + TypeOrmModule, + EmployeeRecurringExpenseService ], - exports: [EmployeeRecurringExpenseService], }) -export class EmployeeRecurringExpenseModule {} +export class EmployeeRecurringExpenseModule { } From e58bd2415e5dd79e75306412eff7fadcca226613 Mon Sep 17 00:00:00 2001 From: Badal Khatri Date: Tue, 27 Jun 2023 08:54:19 +0530 Subject: [PATCH 3/4] fix: seed:all --- packages/core/src/core/seeds/seeder.module.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/core/src/core/seeds/seeder.module.ts b/packages/core/src/core/seeds/seeder.module.ts index 6a539001377..43d9783a7ac 100644 --- a/packages/core/src/core/seeds/seeder.module.ts +++ b/packages/core/src/core/seeds/seeder.module.ts @@ -1,8 +1,11 @@ import { DynamicModule, Module } from '@nestjs/common'; import { getDynamicPluginsModules } from '@gauzy/plugin'; -import { ConfigModule } from '@gauzy/config'; +import { ConfigModule, environment } from '@gauzy/config'; import { SeedDataService } from './seed-data.service'; import { DatabaseModule } from './../../database/database.module'; +import { HeaderResolver, I18nModule } from 'nestjs-i18n'; +import { LanguagesEnum } from '@gauzy/contracts'; +import * as path from 'path'; /** * Import and provide seeder classes. @@ -12,7 +15,7 @@ import { DatabaseModule } from './../../database/database.module'; @Module({ imports: [ConfigModule], providers: [SeedDataService], - exports: [SeedDataService] + exports: [SeedDataService], }) export class SeederModule { static forPlugins(): DynamicModule { @@ -21,9 +24,17 @@ export class SeederModule { providers: [], imports: [ ...getDynamicPluginsModules(), - DatabaseModule + DatabaseModule, + I18nModule.forRoot({ + fallbackLanguage: LanguagesEnum.ENGLISH, + loaderOptions: { + path: path.resolve(__dirname, '../../i18n/'), + watch: !environment.production, + }, + resolvers: [new HeaderResolver(['language'])], + }), ], - exports: [] + exports: [], } as DynamicModule; } } From 2fe55f709642bc6f50b22ac4dd9e49404ef8a351 Mon Sep 17 00:00:00 2001 From: rahul-rocket Date: Thu, 29 Jun 2023 05:31:11 +0000 Subject: [PATCH 4/4] [MegaLinter] Apply linters automatic fixes --- packages/core/src/core/seeds/seeder.module.ts | 10 ++++----- .../employee-recurring-expense.module.ts | 21 +++++------------- .../time-off-policy.controller.ts | 22 +++++-------------- .../time-off-policy/time-off-policy.module.ts | 15 ++++--------- .../time-off-policy.service.ts | 12 +++------- packages/core/src/user/user.module.ts | 14 +++++------- 6 files changed, 29 insertions(+), 65 deletions(-) diff --git a/packages/core/src/core/seeds/seeder.module.ts b/packages/core/src/core/seeds/seeder.module.ts index 43d9783a7ac..71780b59e1f 100644 --- a/packages/core/src/core/seeds/seeder.module.ts +++ b/packages/core/src/core/seeds/seeder.module.ts @@ -15,7 +15,7 @@ import * as path from 'path'; @Module({ imports: [ConfigModule], providers: [SeedDataService], - exports: [SeedDataService], + exports: [SeedDataService] }) export class SeederModule { static forPlugins(): DynamicModule { @@ -29,12 +29,12 @@ export class SeederModule { fallbackLanguage: LanguagesEnum.ENGLISH, loaderOptions: { path: path.resolve(__dirname, '../../i18n/'), - watch: !environment.production, + watch: !environment.production }, - resolvers: [new HeaderResolver(['language'])], - }), + resolvers: [new HeaderResolver(['language'])] + }) ], - exports: [], + exports: [] } as DynamicModule; } } diff --git a/packages/core/src/employee-recurring-expense/employee-recurring-expense.module.ts b/packages/core/src/employee-recurring-expense/employee-recurring-expense.module.ts index 7f0fd377773..aa390a5b867 100644 --- a/packages/core/src/employee-recurring-expense/employee-recurring-expense.module.ts +++ b/packages/core/src/employee-recurring-expense/employee-recurring-expense.module.ts @@ -16,26 +16,17 @@ import { TaskModule } from '../tasks/task.module'; RouterModule.forRoutes([ { path: '/employee-recurring-expense', - module: EmployeeRecurringExpenseModule, - }, - ]), - TypeOrmModule.forFeature([ - EmployeeRecurringExpense + module: EmployeeRecurringExpenseModule + } ]), + TypeOrmModule.forFeature([EmployeeRecurringExpense]), CqrsModule, TenantModule, UserModule, TaskModule ], controllers: [EmployeeRecurringExpenseController], - providers: [ - EmployeeRecurringExpenseService, - ...QueryHandlers, - ...CommandHandlers - ], - exports: [ - TypeOrmModule, - EmployeeRecurringExpenseService - ], + providers: [EmployeeRecurringExpenseService, ...QueryHandlers, ...CommandHandlers], + exports: [TypeOrmModule, EmployeeRecurringExpenseService] }) -export class EmployeeRecurringExpenseModule { } +export class EmployeeRecurringExpenseModule {} diff --git a/packages/core/src/time-off-policy/time-off-policy.controller.ts b/packages/core/src/time-off-policy/time-off-policy.controller.ts index 77d19b43087..ee6e54a06bd 100644 --- a/packages/core/src/time-off-policy/time-off-policy.controller.ts +++ b/packages/core/src/time-off-policy/time-off-policy.controller.ts @@ -31,9 +31,7 @@ import { TimeOffPolicyService } from './time-off-policy.service'; @UseGuards(TenantPermissionGuard) @Controller() export class TimeOffPolicyController extends CrudController { - constructor( - private readonly timeOffPolicyService: TimeOffPolicyService - ) { + constructor(private readonly timeOffPolicyService: TimeOffPolicyService) { super(timeOffPolicyService); } @@ -45,9 +43,7 @@ export class TimeOffPolicyController extends CrudController { @Permissions(PermissionsEnum.POLICY_VIEW) @Get('pagination') @UsePipes(new ValidationPipe({ transform: true })) - async pagination( - @Query() filter: PaginationParams - ): Promise> { + async pagination(@Query() filter: PaginationParams): Promise> { return this.timeOffPolicyService.paginate(filter); } @@ -70,9 +66,7 @@ export class TimeOffPolicyController extends CrudController { @UseGuards(PermissionGuard) @Permissions(PermissionsEnum.POLICY_VIEW) @Get() - async findAll( - @Query('data', ParseJsonPipe) data: any - ): Promise> { + async findAll(@Query('data', ParseJsonPipe) data: any): Promise> { const { relations, findInput } = data; return this.timeOffPolicyService.findAll({ where: findInput, @@ -93,15 +87,12 @@ export class TimeOffPolicyController extends CrudController { }) @ApiResponse({ status: HttpStatus.BAD_REQUEST, - description: - 'Invalid input, The response body may contain clues as to what went wrong' + description: 'Invalid input, The response body may contain clues as to what went wrong' }) @UseGuards(PermissionGuard) @Permissions(PermissionsEnum.POLICY_EDIT) @Post() - async create( - @Body() entity: ITimeOffPolicyCreateInput, - ): Promise { + async create(@Body() entity: ITimeOffPolicyCreateInput): Promise { return await this.timeOffPolicyService.create(entity); } @@ -123,8 +114,7 @@ export class TimeOffPolicyController extends CrudController { }) @ApiResponse({ status: HttpStatus.BAD_REQUEST, - description: - 'Invalid input, The response body may contain clues as to what went wrong' + description: 'Invalid input, The response body may contain clues as to what went wrong' }) @HttpCode(HttpStatus.ACCEPTED) @UseGuards(PermissionGuard) diff --git a/packages/core/src/time-off-policy/time-off-policy.module.ts b/packages/core/src/time-off-policy/time-off-policy.module.ts index e4a04c11d5f..d6e84367f17 100644 --- a/packages/core/src/time-off-policy/time-off-policy.module.ts +++ b/packages/core/src/time-off-policy/time-off-policy.module.ts @@ -11,12 +11,8 @@ import { TaskModule } from '../tasks/task.module'; @Module({ imports: [ - RouterModule.forRoutes([ - { path: 'time-off-policy', module: TimeOffPolicyModule }, - ]), - TypeOrmModule.forFeature([ - TimeOffPolicy - ]), + RouterModule.forRoutes([{ path: 'time-off-policy', module: TimeOffPolicyModule }]), + TypeOrmModule.forFeature([TimeOffPolicy]), TenantModule, UserModule, EmployeeModule, @@ -24,9 +20,6 @@ import { TaskModule } from '../tasks/task.module'; ], controllers: [TimeOffPolicyController], providers: [TimeOffPolicyService], - exports: [ - TypeOrmModule, - TimeOffPolicyService - ], + exports: [TypeOrmModule, TimeOffPolicyService] }) -export class TimeOffPolicyModule { } +export class TimeOffPolicyModule {} diff --git a/packages/core/src/time-off-policy/time-off-policy.service.ts b/packages/core/src/time-off-policy/time-off-policy.service.ts index d37422d1bda..90ca43dd85c 100644 --- a/packages/core/src/time-off-policy/time-off-policy.service.ts +++ b/packages/core/src/time-off-policy/time-off-policy.service.ts @@ -1,10 +1,7 @@ import { Injectable, BadRequestException } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { In, Repository } from 'typeorm'; -import { - ITimeOffPolicyCreateInput, - ITimeOffPolicyUpdateInput -} from '@gauzy/contracts'; +import { ITimeOffPolicyCreateInput, ITimeOffPolicyUpdateInput } from '@gauzy/contracts'; import { TimeOffPolicy } from './time-off-policy.entity'; import { TenantAwareCrudService } from './../core/crud'; import { Employee } from '../employee/employee.entity'; @@ -37,15 +34,12 @@ export class TimeOffPolicyService extends TenantAwareCrudService relations: { user: true } - }) + }); policy.employees = employees; return this.policyRepository.save(policy); } - async update( - id: string, - entity: ITimeOffPolicyUpdateInput - ): Promise { + async update(id: string, entity: ITimeOffPolicyUpdateInput): Promise { try { await this.policyRepository.delete(id); const policy = new TimeOffPolicy(); diff --git a/packages/core/src/user/user.module.ts b/packages/core/src/user/user.module.ts index 936cc4909f0..4f9cbbacd76 100644 --- a/packages/core/src/user/user.module.ts +++ b/packages/core/src/user/user.module.ts @@ -16,19 +16,15 @@ import { TaskModule } from './../tasks/task.module'; @Module({ imports: [ - RouterModule.forRoutes([ - { path: '/user', module: UserModule } - ]), - forwardRef(() => TypeOrmModule.forFeature([ - User - ])), + RouterModule.forRoutes([{ path: '/user', module: UserModule }]), + forwardRef(() => TypeOrmModule.forFeature([User])), forwardRef(() => TenantModule), forwardRef(() => TaskModule), CqrsModule, - FactoryResetModule, + FactoryResetModule ], controllers: [UserController], providers: [UserService, ...CommandHandlers], - exports: [TypeOrmModule, UserService], + exports: [TypeOrmModule, UserService] }) -export class UserModule { } +export class UserModule {}