diff --git a/apps/gauzy/src/app/@core/services/gauzy-ai/gauzy-ai.service.ts b/apps/gauzy/src/app/@core/services/gauzy-ai/gauzy-ai.service.ts index b4d81c85bee..72c65f3b884 100644 --- a/apps/gauzy/src/app/@core/services/gauzy-ai/gauzy-ai.service.ts +++ b/apps/gauzy/src/app/@core/services/gauzy-ai/gauzy-ai.service.ts @@ -19,6 +19,6 @@ export class GauzyAIService { * @returns */ addIntegration(input: IIntegrationKeySecretPairInput): Observable { - return this._http.post(`${API_PREFIX}/integrations/gauzy-ai`, input); + return this._http.post(`${API_PREFIX}/integration/gauzy-ai`, input); } } diff --git a/packages/core/src/app.module.ts b/packages/core/src/app.module.ts index 22457000237..82ef39424ce 100644 --- a/packages/core/src/app.module.ts +++ b/packages/core/src/app.module.ts @@ -85,7 +85,6 @@ import { OrganizationEmploymentTypeModule } from './organization-employment-type import { TimeTrackingModule } from './time-tracking/time-tracking.module'; import { ExpenseCategoriesModule } from './expense-categories/expense-categories.module'; import { UpworkModule } from './upwork/upwork.module'; -import { IntegrationAIModule } from './integration/gauzy-ai/integration-ai.module'; import { CandidateModule } from './candidate/candidate.module'; import { ProductCategoryModule } from './product-category/product-category.module'; import { ProductTypeModule } from './product-type/product-type.module'; @@ -380,7 +379,6 @@ if (environment.sentry && environment.sentry.dsn) { FeatureModule, ReportModule, UpworkModule, - IntegrationAIModule, ExpenseCategoriesModule, ProductCategoryModule, ProductTypeModule, diff --git a/packages/core/src/integration/gauzy-ai/integration-ai.module.ts b/packages/core/src/integration/gauzy-ai/integration-ai.module.ts index 54668b532bf..9281d1f3e61 100644 --- a/packages/core/src/integration/gauzy-ai/integration-ai.module.ts +++ b/packages/core/src/integration/gauzy-ai/integration-ai.module.ts @@ -1,4 +1,4 @@ -import { MiddlewareConsumer, Module, NestModule, RequestMethod } from '@nestjs/common'; +import { MiddlewareConsumer, Module, NestModule, RequestMethod, forwardRef } from '@nestjs/common'; import { CqrsModule } from '@nestjs/cqrs'; import { RouterModule } from 'nest-router'; import { GauzyAIModule } from '@gauzy/integration-ai'; @@ -13,12 +13,9 @@ import { EmployeeJobPostController } from './../../employee-job/employee-job.con @Module({ imports: [ - RouterModule.forRoutes([ - { path: '/integrations/gauzy-ai', module: IntegrationAIModule } - ]), TenantModule, UserModule, - IntegrationModule, + forwardRef(() => IntegrationModule), IntegrationTenantModule, CqrsModule, GauzyAIModule.forRoot() diff --git a/packages/core/src/integration/gauzy-ai/integration-ai.service.ts b/packages/core/src/integration/gauzy-ai/integration-ai.service.ts index ce582a356f8..ea297ec109d 100644 --- a/packages/core/src/integration/gauzy-ai/integration-ai.service.ts +++ b/packages/core/src/integration/gauzy-ai/integration-ai.service.ts @@ -28,7 +28,7 @@ export class IntegrationAIService { const integration = await this._integrationService.findOneByOptions({ where: { - name: IntegrationEnum.GAUZY_AI + provider: IntegrationEnum.GAUZY_AI } }); diff --git a/packages/core/src/integration/hubstaff/hubstaff.module.ts b/packages/core/src/integration/hubstaff/hubstaff.module.ts index c64df3b9c92..6282e9501b5 100644 --- a/packages/core/src/integration/hubstaff/hubstaff.module.ts +++ b/packages/core/src/integration/hubstaff/hubstaff.module.ts @@ -1,4 +1,4 @@ -import { Module } from '@nestjs/common'; +import { Module, forwardRef } from '@nestjs/common'; import { HttpModule } from '@nestjs/axios'; import { CqrsModule } from '@nestjs/cqrs'; import { HUBSTAFF_API_URL } from '@gauzy/integration-hubstaff'; @@ -9,6 +9,7 @@ import { TenantModule } from 'tenant/tenant.module'; import { OrganizationModule } from 'organization/organization.module'; import { IntegrationEntitySettingModule } from 'integration-entity-setting/integration-entity-setting.module'; import { IntegrationEntitySettingTiedModule } from 'integration-entity-setting-tied/integration-entity-setting-tied.module'; +import { IntegrationModule } from 'integration/integration.module'; import { IntegrationMapModule } from 'integration-map/integration-map.module'; import { IntegrationTenantModule } from 'integration-tenant/integration-tenant.module'; import { IntegrationSettingModule } from 'integration-setting/integration-setting.module'; @@ -27,6 +28,7 @@ import { HubstaffAuthorizationController } from './hubstaff-authorization.contro UserModule, OrganizationModule, OrganizationProjectModule, + forwardRef(() => IntegrationModule), IntegrationTenantModule, IntegrationSettingModule, IntegrationEntitySettingModule, diff --git a/packages/core/src/integration/hubstaff/hubstaff.service.ts b/packages/core/src/integration/hubstaff/hubstaff.service.ts index 13c5030ac3c..94e4c603983 100644 --- a/packages/core/src/integration/hubstaff/hubstaff.service.ts +++ b/packages/core/src/integration/hubstaff/hubstaff.service.ts @@ -68,6 +68,7 @@ import { } from 'integration-map/commands'; import { IntegrationTenantService } from 'integration-tenant/integration-tenant.service'; import { IntegrationTenantCreateCommand } from 'integration-tenant/commands'; +import { IntegrationService } from 'integration/integration.service'; @Injectable() export class HubstaffService { @@ -79,7 +80,8 @@ export class HubstaffService { private readonly _roleService: RoleService, private readonly _organizationService: OrganizationService, private readonly _userService: UserService, - private readonly _commandBus: CommandBus + private readonly _commandBus: CommandBus, + private readonly _integrationService: IntegrationService ) { } async fetchIntegration(url: string, token: string): Promise { @@ -189,7 +191,6 @@ export class HubstaffService { async addIntegration( body: ICreateHubstaffIntegrationInput ): Promise { - const tenantId = RequestContext.currentTenantId(); const { client_id, client_secret, code, redirect_uri, organizationId } = body; @@ -221,6 +222,13 @@ export class HubstaffService { : settingEntity ) as IIntegrationEntitySetting[]; + /** */ + const integration = await this._integrationService.findOneByOptions({ + where: { + provider: IntegrationEnum.HUBSTAFF + } + }); + const tokens$ = this._httpService.post(`${HUBSTAFF_AUTHORIZATION_URL}/access_tokens`, urlParams, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' @@ -228,9 +236,10 @@ export class HubstaffService { }).pipe( switchMap(({ data }) => this._commandBus.execute( new IntegrationTenantCreateCommand({ + name: IntegrationEnum.HUBSTAFF, + integration, organizationId, tenantId, - name: IntegrationEnum.HUBSTAFF, entitySettings: entitySettings, settings: [ { diff --git a/packages/core/src/integration/integration.module.ts b/packages/core/src/integration/integration.module.ts index b276b1a04ee..61702314a0e 100644 --- a/packages/core/src/integration/integration.module.ts +++ b/packages/core/src/integration/integration.module.ts @@ -1,4 +1,4 @@ -import { Module } from '@nestjs/common'; +import { Module, forwardRef } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { RouterModule } from 'nest-router'; import { CqrsModule } from '@nestjs/cqrs'; @@ -11,6 +11,7 @@ import { IntegrationService } from './integration.service'; import { IntegrationController } from './integration.controller'; import { CommandHandlers } from './commands/handlers'; import { IntegrationTenantModule } from '../integration-tenant/integration-tenant.module'; +import { IntegrationAIModule } from './gauzy-ai/integration-ai.module'; @Module({ imports: [ @@ -19,6 +20,7 @@ import { IntegrationTenantModule } from '../integration-tenant/integration-tenan path: '/integration', module: IntegrationModule, children: [ { path: '/hubstaff', module: HubstaffModule }, + { path: '/gauzy-ai', module: IntegrationAIModule }, { path: '/', module: IntegrationModule } ] }, @@ -31,7 +33,8 @@ import { IntegrationTenantModule } from '../integration-tenant/integration-tenan IntegrationTenantModule, TenantModule, UserModule, - HubstaffModule, + forwardRef(() => HubstaffModule), + forwardRef(() => IntegrationAIModule), CqrsModule ], controllers: [