From b56f55e62bca3f05c87b0704c3d0a014c9bed763 Mon Sep 17 00:00:00 2001 From: syns2191 Date: Tue, 31 Dec 2024 03:41:40 +0700 Subject: [PATCH 1/5] fix: gauzy server database migration files --- packages/core/src/lib/bootstrap/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/lib/bootstrap/index.ts b/packages/core/src/lib/bootstrap/index.ts index 05265c7194..b8de65b77e 100644 --- a/packages/core/src/lib/bootstrap/index.ts +++ b/packages/core/src/lib/bootstrap/index.ts @@ -507,7 +507,7 @@ export function getMigrationsConfig() { const migrationsDir = path.resolve( __dirname, isElectron - ? './../database/migrations/*.ts' // Only .ts if Electron + ? './../database/migrations/*.js' // Only .ts if Electron : './../database/migrations/*{.ts,.js}' // Otherwise .ts or .js ); console.log('Migration migrationsDir: ->', migrationsDir); From 0f2403a62c3087894b340d943e58620b6ffdbceb Mon Sep 17 00:00:00 2001 From: "Rahul R." Date: Tue, 31 Dec 2024 11:52:15 +0530 Subject: [PATCH 2/5] chore: regenerate @gauzy/plugin-job-proposal library using updated NX generator --- packages/plugins/job-proposal/.eslintrc.json | 25 ---- .../plugins/job-proposal/eslint.config.js | 19 +++ packages/plugins/job-proposal/jest.config.ts | 1 - .../src/lib/job-proposal.plugin.ts | 18 +++ .../employee-proposal-template.controller.ts | 128 +++++++++++++++--- .../employee-proposal-template.entity.ts | 27 +++- .../employee-proposal-template.module.ts | 6 +- .../employee-proposal-template.service.ts | 50 ++++--- .../lib/proposal-template/repository/index.ts | 2 - ...m-employee-proposal-template.repository.ts | 2 +- .../src/lib/proposal/proposal.entity.ts | 34 +++++ .../src/lib/proposal/proposal.module.ts | 19 ++- .../src/lib/proposal/proposal.service.ts | 11 +- .../src/lib/proposal/repository/index.ts | 2 - packages/plugins/job-proposal/tsconfig.json | 5 +- 15 files changed, 263 insertions(+), 86 deletions(-) delete mode 100644 packages/plugins/job-proposal/.eslintrc.json create mode 100644 packages/plugins/job-proposal/eslint.config.js delete mode 100644 packages/plugins/job-proposal/src/lib/proposal-template/repository/index.ts delete mode 100644 packages/plugins/job-proposal/src/lib/proposal/repository/index.ts diff --git a/packages/plugins/job-proposal/.eslintrc.json b/packages/plugins/job-proposal/.eslintrc.json deleted file mode 100644 index fb3030b074..0000000000 --- a/packages/plugins/job-proposal/.eslintrc.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "extends": ["../../../.eslintrc.json"], - "ignorePatterns": ["!**/*"], - "overrides": [ - { - "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], - "rules": {} - }, - { - "files": ["*.ts", "*.tsx"], - "rules": {} - }, - { - "files": ["*.js", "*.jsx"], - "rules": {} - }, - { - "files": ["*.json"], - "parser": "jsonc-eslint-parser", - "rules": { - "@nx/dependency-checks": "error" - } - } - ] -} diff --git a/packages/plugins/job-proposal/eslint.config.js b/packages/plugins/job-proposal/eslint.config.js new file mode 100644 index 0000000000..ba4f5d8daa --- /dev/null +++ b/packages/plugins/job-proposal/eslint.config.js @@ -0,0 +1,19 @@ +const baseConfig = require('../../../.eslintrc.json'); + +module.exports = [ + ...baseConfig, + { + files: ['**/*.json'], + rules: { + '@nx/dependency-checks': [ + 'error', + { + ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'] + } + ] + }, + languageOptions: { + parser: require('jsonc-eslint-parser') + } + } +]; diff --git a/packages/plugins/job-proposal/jest.config.ts b/packages/plugins/job-proposal/jest.config.ts index 08832151d7..df9c572da6 100644 --- a/packages/plugins/job-proposal/jest.config.ts +++ b/packages/plugins/job-proposal/jest.config.ts @@ -1,4 +1,3 @@ -/* eslint-disable */ export default { displayName: 'plugin-job-proposal', preset: '../../../jest.preset.js', diff --git a/packages/plugins/job-proposal/src/lib/job-proposal.plugin.ts b/packages/plugins/job-proposal/src/lib/job-proposal.plugin.ts index d72f938983..7a4146bd63 100644 --- a/packages/plugins/job-proposal/src/lib/job-proposal.plugin.ts +++ b/packages/plugins/job-proposal/src/lib/job-proposal.plugin.ts @@ -8,9 +8,26 @@ import { EmployeeProposalTemplate } from './proposal-template/employee-proposal- import { ProposalSeederService } from './proposal/proposal-seeder.service'; @Plugin({ + /** + * An array of modules that will be imported and registered with the plugin. + */ imports: [ProposalModule, EmployeeProposalTemplateModule], + /** + * An array of Entity classes. The plugin (or ORM) will + * register these entities for use within the application. + */ entities: [Proposal, EmployeeProposalTemplate], + /** + * A callback that receives the main plugin configuration object and allows + * custom modifications before returning the final configuration. + * + * @param {ApplicationPluginConfig} config - The initial plugin configuration object. + * @returns {ApplicationPluginConfig} - The modified plugin configuration object. + * + * In this example, we're adding a custom relation field (`proposals`) to the `Tag` entity. + */ configuration: (config: ApplicationPluginConfig) => { + // Add a new 'proposals' tag to the 'Tag' entity config.customFields.Tag.push({ name: 'proposals', type: 'relation', @@ -21,6 +38,7 @@ import { ProposalSeederService } from './proposal/proposal-seeder.service'; entity: Proposal, inverseSide: (it: Proposal) => it.tags }); + return config; } }) diff --git a/packages/plugins/job-proposal/src/lib/proposal-template/employee-proposal-template.controller.ts b/packages/plugins/job-proposal/src/lib/proposal-template/employee-proposal-template.controller.ts index fc576fc562..65cb0552f9 100644 --- a/packages/plugins/job-proposal/src/lib/proposal-template/employee-proposal-template.controller.ts +++ b/packages/plugins/job-proposal/src/lib/proposal-template/employee-proposal-template.controller.ts @@ -1,5 +1,5 @@ import { Body, Controller, Get, HttpStatus, Param, Patch, Post, Put, Query, UseGuards } from '@nestjs/common'; -import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; +import { ApiBody, ApiResponse, ApiTags, ApiOperation, ApiQuery, ApiParam } from '@nestjs/swagger'; import { UpdateResult } from 'typeorm'; import { ID, IEmployeeProposalTemplate, IPagination, PermissionsEnum } from '@gauzy/contracts'; import { @@ -26,11 +26,35 @@ export class EmployeeProposalTemplateController extends CrudController} The newly created proposal template. */ + @ApiOperation({ + summary: 'Create employee proposal template', + description: 'Creates a new employee proposal template in the database.' + }) + @ApiResponse({ + status: 201, + description: 'The proposal template has been successfully created.', + type: () => CreateProposalTemplateDTO + }) + @ApiBody({ + type: CreateProposalTemplateDTO, + required: true, + description: 'Payload to create a new proposal template.' + }) @Post('/') @UseValidationPipe({ whitelist: true, transform: true }) - async create(@Body() entity: CreateProposalTemplateDTO): Promise { + async create( + @Body() entity: CreateProposalTemplateDTO + ): Promise { return await this.employeeProposalTemplateService.create(entity); } /** * UPDATE employee proposal template * - * @param entity - * @returns + * Updates an existing `EmployeeProposalTemplate` in the database. + * + * @param {ID} id - The unique identifier of the proposal template. + * @param {UpdateProposalTemplateDTO} entity - The DTO containing updated data. + * @returns {Promise} The updated proposal template or a TypeORM UpdateResult. */ + @ApiOperation({ + summary: 'Update employee proposal template', + description: 'Updates an existing employee proposal template by ID.' + }) + @ApiBody({ + type: UpdateProposalTemplateDTO, + required: true, + description: 'Payload to update a proposal template.' + }) + @ApiResponse({ + status: 200, + description: 'The proposal template has been successfully updated.', + type: () => UpdateProposalTemplateDTO + }) @Put('/:id') @UseValidationPipe({ whitelist: true, transform: true }) async update( diff --git a/packages/plugins/job-proposal/src/lib/proposal-template/employee-proposal-template.entity.ts b/packages/plugins/job-proposal/src/lib/proposal-template/employee-proposal-template.entity.ts index 586bcd59f6..c7001711bd 100644 --- a/packages/plugins/job-proposal/src/lib/proposal-template/employee-proposal-template.entity.ts +++ b/packages/plugins/job-proposal/src/lib/proposal-template/employee-proposal-template.entity.ts @@ -13,32 +13,53 @@ import { MikroOrmEmployeeProposalTemplateRepository } from './repository/mikro-o @MultiORMEntity('employee_proposal_template', { mikroOrmRepository: () => MikroOrmEmployeeProposalTemplateRepository }) export class EmployeeProposalTemplate extends TenantOrganizationBaseEntity implements IEmployeeProposalTemplate { + /** + * The name/title of the proposal template (e.g., "General Proposal", "Technical Proposal"). + */ @ApiProperty({ type: () => String }) - @ColumnIndex() + @ColumnIndex() // Adds an index on the 'name' column for faster queries @MultiORMColumn() name?: string; + /** + * The main content or body of the proposal template. + * Marked as 'text' type, and set to nullable for optional usage. + * Also, 'fulltext: true' enables full-text search if supported by the database. + */ @ApiProperty({ type: () => String }) @ColumnIndex({ fulltext: true }) @MultiORMColumn({ type: 'text', nullable: true }) content?: string; + /** + * Indicates if this template is the default template for the employee/tenant combination. + * Defaults to 'false' when newly created. + */ @ApiProperty({ type: () => Boolean }) @ColumnIndex() @MultiORMColumn({ default: false }) isDefault?: boolean; /* - |-------------------------------------------------------------------------- + |---------------------------------------------------------------------- | @ManyToOne - |-------------------------------------------------------------------------- + |---------------------------------------------------------------------- */ + + /** + * Many-to-one relationship linking this template to a specific employee. + * If the employee is deleted, this template is deleted as well (cascade). + */ @MultiORMManyToOne(() => Employee, { /** Database cascade action on delete. */ onDelete: 'CASCADE' }) employee?: IEmployee; + /** + * Stores the UUID of the linked employee. + * This is automatically populated via `@RelationId` from the `employee` relation. + */ @ApiProperty({ type: () => String }) @RelationId((it: EmployeeProposalTemplate) => it.employee) @ColumnIndex() diff --git a/packages/plugins/job-proposal/src/lib/proposal-template/employee-proposal-template.module.ts b/packages/plugins/job-proposal/src/lib/proposal-template/employee-proposal-template.module.ts index 8600129d0c..588c52580b 100644 --- a/packages/plugins/job-proposal/src/lib/proposal-template/employee-proposal-template.module.ts +++ b/packages/plugins/job-proposal/src/lib/proposal-template/employee-proposal-template.module.ts @@ -6,7 +6,8 @@ import { RolePermissionModule } from '@gauzy/core'; import { EmployeeProposalTemplateController } from './employee-proposal-template.controller'; import { EmployeeProposalTemplate } from './employee-proposal-template.entity'; import { EmployeeProposalTemplateService } from './employee-proposal-template.service'; -import { TypeOrmEmployeeProposalTemplateRepository } from './repository'; +import { MikroOrmEmployeeProposalTemplateRepository } from './repository/mikro-orm-employee-proposal-template.repository'; +import { TypeOrmEmployeeProposalTemplateRepository } from './repository/type-orm-employee-proposal-template.repository'; @Module({ imports: [ @@ -16,7 +17,6 @@ import { TypeOrmEmployeeProposalTemplateRepository } from './repository'; CqrsModule ], controllers: [EmployeeProposalTemplateController], - providers: [EmployeeProposalTemplateService, TypeOrmEmployeeProposalTemplateRepository], - exports: [] + providers: [EmployeeProposalTemplateService, TypeOrmEmployeeProposalTemplateRepository, MikroOrmEmployeeProposalTemplateRepository], }) export class EmployeeProposalTemplateModule { } diff --git a/packages/plugins/job-proposal/src/lib/proposal-template/employee-proposal-template.service.ts b/packages/plugins/job-proposal/src/lib/proposal-template/employee-proposal-template.service.ts index d733eef75b..9b86ab3ec0 100644 --- a/packages/plugins/job-proposal/src/lib/proposal-template/employee-proposal-template.service.ts +++ b/packages/plugins/job-proposal/src/lib/proposal-template/employee-proposal-template.service.ts @@ -1,8 +1,9 @@ -import { Injectable } from '@nestjs/common'; -import { ID, IEmployeeProposalTemplate, IEmployeeProposalTemplateMakeDefaultInput } from '@gauzy/contracts'; +import { Injectable, NotFoundException } from '@nestjs/common'; +import { ID, IEmployeeProposalTemplate, IEmployeeProposalTemplateMakeDefaultInput, IPagination } from '@gauzy/contracts'; import { PaginationParams, TenantAwareCrudService } from '@gauzy/core'; import { EmployeeProposalTemplate } from './employee-proposal-template.entity'; -import { MikroOrmEmployeeProposalTemplateRepository, TypeOrmEmployeeProposalTemplateRepository } from './repository'; +import { MikroOrmEmployeeProposalTemplateRepository } from './repository/mikro-orm-employee-proposal-template.repository'; +import { TypeOrmEmployeeProposalTemplateRepository } from './repository/type-orm-employee-proposal-template.repository'; @Injectable() export class EmployeeProposalTemplateService extends TenantAwareCrudService { @@ -16,32 +17,43 @@ export class EmployeeProposalTemplateService extends TenantAwareCrudService} The updated proposal template. */ - async makeDefault(id: ID, input: IEmployeeProposalTemplateMakeDefaultInput): Promise { - const proposalTemplate: IEmployeeProposalTemplate = await this.findOneByIdString(id); + public async makeDefault( + id: ID, + input: IEmployeeProposalTemplateMakeDefaultInput + ): Promise { + const proposalTemplate = await this.findOneByIdString(id); + + if (!proposalTemplate) { + throw new NotFoundException(`Proposal template with ID ${id} not found`); + } + + // Update the isDefault property on the target template proposalTemplate.isDefault = input.isDefault; + // Reset `isDefault` to false on all templates matching these fields const { organizationId, tenantId, employeeId } = proposalTemplate; - await super.update( - { organizationId, tenantId, employeeId }, - { - isDefault: false - } - ); + // Update the isDefault property on all templates matching these fields + await super.update({ organizationId, tenantId, employeeId }, { isDefault: false }); - return await super.save(proposalTemplate); + // Save and return the updated template + return super.save(proposalTemplate); } /** - * Finds proposal templates entities that match given find options. + * Finds all proposal templates matching the given pagination params. * - * @param params - Pagination parameters. - * @returns The list of proposal templates. + * @param {PaginationParams} [params] - Pagination parameters. + * @returns {Promise>} Paginated result. */ - async findAll(params?: PaginationParams) { - return await super.findAll(params); + public async findAll( + params?: PaginationParams + ): Promise> { + // Directly return the result of `super.findAll`. + return super.findAll(params); } } diff --git a/packages/plugins/job-proposal/src/lib/proposal-template/repository/index.ts b/packages/plugins/job-proposal/src/lib/proposal-template/repository/index.ts deleted file mode 100644 index bf3f1a64d5..0000000000 --- a/packages/plugins/job-proposal/src/lib/proposal-template/repository/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './mikro-orm-employee-proposal-template.repository'; -export * from './type-orm-employee-proposal-template.repository'; diff --git a/packages/plugins/job-proposal/src/lib/proposal-template/repository/type-orm-employee-proposal-template.repository.ts b/packages/plugins/job-proposal/src/lib/proposal-template/repository/type-orm-employee-proposal-template.repository.ts index f9a7f51d78..3e4807952e 100644 --- a/packages/plugins/job-proposal/src/lib/proposal-template/repository/type-orm-employee-proposal-template.repository.ts +++ b/packages/plugins/job-proposal/src/lib/proposal-template/repository/type-orm-employee-proposal-template.repository.ts @@ -1,5 +1,5 @@ -import { InjectRepository } from '@nestjs/typeorm'; import { Injectable } from '@nestjs/common'; +import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { EmployeeProposalTemplate } from '../employee-proposal-template.entity'; diff --git a/packages/plugins/job-proposal/src/lib/proposal/proposal.entity.ts b/packages/plugins/job-proposal/src/lib/proposal/proposal.entity.ts index fec1912a68..dd89e372f4 100644 --- a/packages/plugins/job-proposal/src/lib/proposal/proposal.entity.ts +++ b/packages/plugins/job-proposal/src/lib/proposal/proposal.entity.ts @@ -18,27 +18,47 @@ import { MikroOrmProposalRepository } from './repository/mikro-orm-proposal.repo @MultiORMEntity('proposal', { mikroOrmRepository: () => MikroOrmProposalRepository }) export class Proposal extends TenantOrganizationBaseEntity implements IProposal, Taggable { + /** + * The URL of the posted job associated with this proposal. + * This property is optional and can be null if there is no direct job post link. + */ @ApiPropertyOptional({ type: () => String }) @IsOptional() @ColumnIndex() @MultiORMColumn({ nullable: true }) jobPostUrl?: string; + /** + * Represents an optional date related to the value or pricing of the proposal. + * Can be used to track when the value or estimate was determined. + */ @ApiPropertyOptional({ type: () => Date }) @IsOptional() @MultiORMColumn({ nullable: true }) valueDate?: Date; + /** + * The content or description of the job posting to which this proposal relates. + * This field is required, as proposals typically reference a specific job post. + */ @ApiProperty({ type: () => String }) @IsNotEmpty() @MultiORMColumn() jobPostContent?: string; + /** + * The main body or content of the proposal being submitted. + * This field is required to ensure the proposal includes some meaningful text. + */ @ApiProperty({ type: () => String }) @IsNotEmpty() @MultiORMColumn() proposalContent?: string; + /** + * The status of the proposal (e.g., 'SENT', 'ACCEPTED'). + * Enum-based property to enforce valid statuses defined by ProposalStatusEnum. + */ @ApiProperty({ type: () => String, enum: ProposalStatusEnum }) @IsEnum(ProposalStatusEnum) @MultiORMColumn() @@ -50,7 +70,12 @@ export class Proposal extends TenantOrganizationBaseEntity implements IProposal, |-------------------------------------------------------------------------- */ /** + * Represents a many-to-one relationship to the `Employee` entity. * + * The `employeeId` field is the relation ID: + * - Decorated with `@IsUUID()` to enforce UUID format + * - Uses `@RelationId(...)` to automatically set `employeeId` from `employee` + * - Marked as nullable in the database */ @MultiORMManyToOne(() => Employee, { /** Indicates if relation column value can be nullable or not. */ @@ -62,6 +87,9 @@ export class Proposal extends TenantOrganizationBaseEntity implements IProposal, @JoinColumn() employee?: IEmployee; + /** + * The UUID representing the linked `Employee` record. + */ @ApiProperty({ type: () => String }) @IsUUID() @RelationId((it: Proposal) => it.employee) @@ -69,8 +97,14 @@ export class Proposal extends TenantOrganizationBaseEntity implements IProposal, employeeId?: ID; /** + * Defines a many-to-one relationship with the `OrganizationContact` entity. * + * - The `organizationContactId` field is generated by the `@RelationId` decorator, + * ensuring the ID is populated automatically based on the associated entity. + * - Decorators such as `@IsOptional()` and `@IsUUID()` ensure optional or UUID + * validation where appropriate. */ + @MultiORMManyToOne(() => OrganizationContact, { /** Indicates if relation column value can be nullable or not. */ nullable: true, diff --git a/packages/plugins/job-proposal/src/lib/proposal/proposal.module.ts b/packages/plugins/job-proposal/src/lib/proposal/proposal.module.ts index 51cef78af9..4d805b4c50 100644 --- a/packages/plugins/job-proposal/src/lib/proposal/proposal.module.ts +++ b/packages/plugins/job-proposal/src/lib/proposal/proposal.module.ts @@ -8,9 +8,13 @@ import { ProposalController } from './proposal.controller'; import { ProposalService } from './proposal.service'; import { CommandHandlers } from './commands/handlers'; import { ProposalSeederService } from './proposal-seeder.service'; -import { TypeOrmProposalRepository } from './repository'; +import { TypeOrmProposalRepository } from './repository/type-orm-proposal.repository'; +import { MikroOrmProposalRepository } from './repository/mikro-orm-proposal.repository'; @Module({ + controllers: [ + ProposalController + ], imports: [ TypeOrmModule.forFeature([Proposal]), MikroOrmModule.forFeature([Proposal]), @@ -18,8 +22,15 @@ import { TypeOrmProposalRepository } from './repository'; SeederModule, CqrsModule ], - controllers: [ProposalController], - providers: [ProposalService, ProposalSeederService, TypeOrmProposalRepository, ...CommandHandlers], - exports: [ProposalSeederService] + providers: [ + ProposalService, + ProposalSeederService, + TypeOrmProposalRepository, + MikroOrmProposalRepository, + ...CommandHandlers + ], + exports: [ + ProposalSeederService + ] }) export class ProposalModule {} diff --git a/packages/plugins/job-proposal/src/lib/proposal/proposal.service.ts b/packages/plugins/job-proposal/src/lib/proposal/proposal.service.ts index d70662909a..10aa2dedf1 100644 --- a/packages/plugins/job-proposal/src/lib/proposal/proposal.service.ts +++ b/packages/plugins/job-proposal/src/lib/proposal/proposal.service.ts @@ -5,7 +5,8 @@ import { IPagination } from '@gauzy/contracts'; import { isPostgres } from '@gauzy/config'; import { TenantAwareCrudService } from '@gauzy/core'; import { Proposal } from './proposal.entity'; -import { MikroOrmProposalRepository, TypeOrmProposalRepository } from './repository'; +import { MikroOrmProposalRepository } from './repository/mikro-orm-proposal.repository'; +import { TypeOrmProposalRepository } from './repository/type-orm-proposal.repository'; @Injectable() export class ProposalService extends TenantAwareCrudService { @@ -23,20 +24,20 @@ export class ProposalService extends TenantAwareCrudService { * @returns A paginated list of proposals. */ async findAll(filter?: FindManyOptions): Promise> { - return await this.pagination(filter); + return this.pagination(filter); } /** * Paginates data based on the provided filter options. * - * @param filter The filter options for pagination. + * @param {FindManyOptions} filter - The filter options for pagination. * @returns The paginated data. */ public async pagination(filter: FindManyOptions) { // Check if 'where' property exists in the filter if (!('where' in filter)) { // If 'where' property is missing, return paginated data without any modification - return await super.paginate(filter); + return super.paginate(filter); } const { where } = filter; @@ -68,6 +69,6 @@ export class ProposalService extends TenantAwareCrudService { } // Return the paginated data after applying any modifications - return await super.paginate(filter); + return super.paginate(filter); } } diff --git a/packages/plugins/job-proposal/src/lib/proposal/repository/index.ts b/packages/plugins/job-proposal/src/lib/proposal/repository/index.ts deleted file mode 100644 index 080ca6c873..0000000000 --- a/packages/plugins/job-proposal/src/lib/proposal/repository/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './mikro-orm-proposal.repository'; -export * from './type-orm-proposal.repository'; diff --git a/packages/plugins/job-proposal/tsconfig.json b/packages/plugins/job-proposal/tsconfig.json index 3f13a7802c..2d92716e86 100644 --- a/packages/plugins/job-proposal/tsconfig.json +++ b/packages/plugins/job-proposal/tsconfig.json @@ -1,13 +1,12 @@ { "extends": "../../../tsconfig.json", "compilerOptions": { - "module": "commonjs", "forceConsistentCasingInFileNames": true, "strict": false, "noImplicitOverride": false, - "noPropertyAccessFromIndexSignature": false, "noImplicitReturns": false, - "noFallthroughCasesInSwitch": false + "noFallthroughCasesInSwitch": false, + "noPropertyAccessFromIndexSignature": false }, "files": [], "include": [], From a37ff0c699921995903166e3b883eea89341a70c Mon Sep 17 00:00:00 2001 From: "Rahul R." Date: Tue, 31 Dec 2024 12:17:38 +0530 Subject: [PATCH 3/5] fix: suggestion by coderabbitai --- packages/contracts/src/lib/proposal.model.ts | 4 ++-- .../job-proposal/src/lib/proposal/proposal.entity.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/contracts/src/lib/proposal.model.ts b/packages/contracts/src/lib/proposal.model.ts index 8b0a37917d..720ac8b681 100644 --- a/packages/contracts/src/lib/proposal.model.ts +++ b/packages/contracts/src/lib/proposal.model.ts @@ -15,8 +15,8 @@ export enum ProposalStatusEnum { export interface IProposalBase extends IBasePerTenantAndOrganizationEntityModel, ITaggable { jobPostUrl?: string; valueDate?: Date; - jobPostContent?: string; - proposalContent?: string; + jobPostContent: string; + proposalContent: string; status?: ProposalStatusEnum; } diff --git a/packages/plugins/job-proposal/src/lib/proposal/proposal.entity.ts b/packages/plugins/job-proposal/src/lib/proposal/proposal.entity.ts index dd89e372f4..7921132711 100644 --- a/packages/plugins/job-proposal/src/lib/proposal/proposal.entity.ts +++ b/packages/plugins/job-proposal/src/lib/proposal/proposal.entity.ts @@ -44,7 +44,7 @@ export class Proposal extends TenantOrganizationBaseEntity implements IProposal, @ApiProperty({ type: () => String }) @IsNotEmpty() @MultiORMColumn() - jobPostContent?: string; + jobPostContent: string; /** * The main body or content of the proposal being submitted. @@ -53,12 +53,12 @@ export class Proposal extends TenantOrganizationBaseEntity implements IProposal, @ApiProperty({ type: () => String }) @IsNotEmpty() @MultiORMColumn() - proposalContent?: string; + proposalContent: string; /** - * The status of the proposal (e.g., 'SENT', 'ACCEPTED'). - * Enum-based property to enforce valid statuses defined by ProposalStatusEnum. - */ + * The status of the proposal (e.g., 'SENT', 'ACCEPTED'). + * Enum-based property to enforce valid statuses defined by ProposalStatusEnum. + */ @ApiProperty({ type: () => String, enum: ProposalStatusEnum }) @IsEnum(ProposalStatusEnum) @MultiORMColumn() From b9545485d94b2208f42cc74119ab81fb24870845 Mon Sep 17 00:00:00 2001 From: "Rahul R." Date: Tue, 31 Dec 2024 12:24:29 +0530 Subject: [PATCH 4/5] chore: regenerate @gauzy/plugin-integration-ai library updated by NX generator --- .../plugins/integration-ai/.eslintrc.json | 25 ------------------- .../plugins/integration-ai/eslint.config.js | 19 ++++++++++++++ .../plugins/integration-ai/jest.config.ts | 1 - packages/plugins/integration-ai/tsconfig.json | 5 ++-- 4 files changed, 21 insertions(+), 29 deletions(-) delete mode 100644 packages/plugins/integration-ai/.eslintrc.json create mode 100644 packages/plugins/integration-ai/eslint.config.js diff --git a/packages/plugins/integration-ai/.eslintrc.json b/packages/plugins/integration-ai/.eslintrc.json deleted file mode 100644 index fb3030b074..0000000000 --- a/packages/plugins/integration-ai/.eslintrc.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "extends": ["../../../.eslintrc.json"], - "ignorePatterns": ["!**/*"], - "overrides": [ - { - "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], - "rules": {} - }, - { - "files": ["*.ts", "*.tsx"], - "rules": {} - }, - { - "files": ["*.js", "*.jsx"], - "rules": {} - }, - { - "files": ["*.json"], - "parser": "jsonc-eslint-parser", - "rules": { - "@nx/dependency-checks": "error" - } - } - ] -} diff --git a/packages/plugins/integration-ai/eslint.config.js b/packages/plugins/integration-ai/eslint.config.js new file mode 100644 index 0000000000..ba4f5d8daa --- /dev/null +++ b/packages/plugins/integration-ai/eslint.config.js @@ -0,0 +1,19 @@ +const baseConfig = require('../../../.eslintrc.json'); + +module.exports = [ + ...baseConfig, + { + files: ['**/*.json'], + rules: { + '@nx/dependency-checks': [ + 'error', + { + ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'] + } + ] + }, + languageOptions: { + parser: require('jsonc-eslint-parser') + } + } +]; diff --git a/packages/plugins/integration-ai/jest.config.ts b/packages/plugins/integration-ai/jest.config.ts index 4256d307d8..86b94650aa 100644 --- a/packages/plugins/integration-ai/jest.config.ts +++ b/packages/plugins/integration-ai/jest.config.ts @@ -1,4 +1,3 @@ -/* eslint-disable */ export default { displayName: 'plugin-integration-ai', preset: '../../../jest.preset.js', diff --git a/packages/plugins/integration-ai/tsconfig.json b/packages/plugins/integration-ai/tsconfig.json index 3f13a7802c..2d92716e86 100644 --- a/packages/plugins/integration-ai/tsconfig.json +++ b/packages/plugins/integration-ai/tsconfig.json @@ -1,13 +1,12 @@ { "extends": "../../../tsconfig.json", "compilerOptions": { - "module": "commonjs", "forceConsistentCasingInFileNames": true, "strict": false, "noImplicitOverride": false, - "noPropertyAccessFromIndexSignature": false, "noImplicitReturns": false, - "noFallthroughCasesInSwitch": false + "noFallthroughCasesInSwitch": false, + "noPropertyAccessFromIndexSignature": false }, "files": [], "include": [], From ca545bd97da2971c95069da60589e509b76f3d2a Mon Sep 17 00:00:00 2001 From: "Rahul R." Date: Tue, 31 Dec 2024 13:26:19 +0530 Subject: [PATCH 5/5] fix: user organization for me user --- .../dto/find-me-user-organization.dto.ts | 2 +- .../user-organization.controller.ts | 3 ++- .../user-organization.services.ts | 20 ++++++++++++++----- packages/core/src/lib/user/user.service.ts | 9 ++------- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/packages/core/src/lib/user-organization/dto/find-me-user-organization.dto.ts b/packages/core/src/lib/user-organization/dto/find-me-user-organization.dto.ts index 317ac419d9..44d8c42a41 100644 --- a/packages/core/src/lib/user-organization/dto/find-me-user-organization.dto.ts +++ b/packages/core/src/lib/user-organization/dto/find-me-user-organization.dto.ts @@ -7,4 +7,4 @@ import { FindMeQueryDTO } from "../../user/dto"; */ export class FindMeUserOrganizationDTO extends IntersectionType( PickType(FindMeQueryDTO, ['includeEmployee'] as const), -) { } +) {} diff --git a/packages/core/src/lib/user-organization/user-organization.controller.ts b/packages/core/src/lib/user-organization/user-organization.controller.ts index 99c69ab5a8..99cce81830 100644 --- a/packages/core/src/lib/user-organization/user-organization.controller.ts +++ b/packages/core/src/lib/user-organization/user-organization.controller.ts @@ -1,6 +1,7 @@ import { Controller, HttpStatus, Get, Query, UseGuards, HttpCode, Delete, Param } from '@nestjs/common'; import { CommandBus } from '@nestjs/cqrs'; import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger'; +import { parseToBoolean } from '@gauzy/common'; import { IUserOrganization, IPagination, ID } from '@gauzy/contracts'; import { CrudController, PaginationParams } from './../core/crud'; import { UUIDValidationPipe } from './../shared/pipes'; @@ -42,7 +43,7 @@ export class UserOrganizationController extends CrudController @Query() params: PaginationParams, @Query() query: FindMeUserOrganizationDTO ): Promise> { - return await this.userOrganizationService.findUserOrganizations(params, query.includeEmployee); + return await this.userOrganizationService.findUserOrganizations(params, parseToBoolean(query.includeEmployee)); } /** diff --git a/packages/core/src/lib/user-organization/user-organization.services.ts b/packages/core/src/lib/user-organization/user-organization.services.ts index a0038678e4..745615dc3e 100644 --- a/packages/core/src/lib/user-organization/user-organization.services.ts +++ b/packages/core/src/lib/user-organization/user-organization.services.ts @@ -42,8 +42,8 @@ export class UserOrganizationService extends TenantAwareCrudService organization.user) // Filter out user organizations without a user object - .map((organization: IUserOrganization) => organization.user.id); + .filter((organization: IUserOrganization) => organization?.user) // Filter out user organizations without a user object + .map((organization: IUserOrganization) => organization?.user?.id) || []; // Fetch all employee details in bulk for the extracted user IDs const employees = await this.employeeService.findEmployeesByUserIds(userIds, tenantId); @@ -51,13 +51,23 @@ export class UserOrganizationService extends TenantAwareCrudService(); employees.forEach((employee: Employee) => { - employeeMap.set(employee.userId, employee); + // If user ID is available, add employee details to the map + if (employee.userId) { + // Add employee details to the map + employeeMap.set(employee.userId, employee); + } }); // Merge employee details into each user organization object const itemsWithEmployees = items.map((organization: UserOrganization) => { - const employee = employeeMap.get(organization.user.id); - return { ...organization, user: { ...organization.user, employee } }; + // If user ID is available, fetch employee details + if (organization.user.id) { + // Fetch employee details using the user ID + const employee = employeeMap.get(organization.user.id); + return { ...organization, user: { ...organization.user, employee } }; + } + // If user ID is not available, return the original organization object + return { ...organization }; }); // Return paginated result with employee details diff --git a/packages/core/src/lib/user/user.service.ts b/packages/core/src/lib/user/user.service.ts index 15d9bacd50..d822b3c4e2 100644 --- a/packages/core/src/lib/user/user.service.ts +++ b/packages/core/src/lib/user/user.service.ts @@ -115,14 +115,9 @@ export class UserService extends TenantAwareCrudService { console.log('findMe found User with Id:', user.id); - // If 'includeEmployee' is set to true, fetch employee details associated with the user. + // Fetch employee details if 'includeEmployee' is true if (options.includeEmployee) { - const relations: any = {}; - - // Include organization relation if 'includeOrganization' is true - if (options.includeOrganization) { - relations.organization = true; - } + const relations = options.includeOrganization ? { organization: true } : []; employee = await this._employeeService.findOneByUserId(user.id, { relations }); }