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

Fix :: Integration Missing API (Hubstaff & AI) #6863

Merged
merged 3 commits into from
Sep 21, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export class GauzyAIService {
* @returns
*/
addIntegration(input: IIntegrationKeySecretPairInput): Observable<IIntegrationTenant> {
return this._http.post<IIntegrationTenant>(`${API_PREFIX}/integrations/gauzy-ai`, input);
return this._http.post<IIntegrationTenant>(`${API_PREFIX}/integration/gauzy-ai`, input);
}
}
2 changes: 0 additions & 2 deletions packages/core/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -380,7 +379,6 @@ if (environment.sentry && environment.sentry.dsn) {
FeatureModule,
ReportModule,
UpworkModule,
IntegrationAIModule,
ExpenseCategoriesModule,
ProductCategoryModule,
ProductTypeModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class IntegrationAIService {

const integration = await this._integrationService.findOneByOptions({
where: {
name: IntegrationEnum.GAUZY_AI
provider: IntegrationEnum.GAUZY_AI
}
});

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/integration/hubstaff/hubstaff.module.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand All @@ -27,6 +28,7 @@ import { HubstaffAuthorizationController } from './hubstaff-authorization.contro
UserModule,
OrganizationModule,
OrganizationProjectModule,
forwardRef(() => IntegrationModule),
IntegrationTenantModule,
IntegrationSettingModule,
IntegrationEntitySettingModule,
Expand Down
15 changes: 12 additions & 3 deletions packages/core/src/integration/hubstaff/hubstaff.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<T = any>(url: string, token: string): Promise<any> {
Expand Down Expand Up @@ -189,7 +191,6 @@ export class HubstaffService {
async addIntegration(
body: ICreateHubstaffIntegrationInput
): Promise<IIntegrationTenant> {

const tenantId = RequestContext.currentTenantId();
const { client_id, client_secret, code, redirect_uri, organizationId } = body;

Expand Down Expand Up @@ -221,16 +222,24 @@ 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'
}
}).pipe(
switchMap(({ data }) => this._commandBus.execute(
new IntegrationTenantCreateCommand({
name: IntegrationEnum.HUBSTAFF,
integration,
organizationId,
tenantId,
name: IntegrationEnum.HUBSTAFF,
entitySettings: entitySettings,
settings: [
{
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/integration/integration.module.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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: [
Expand All @@ -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 }
]
},
Expand All @@ -31,7 +33,8 @@ import { IntegrationTenantModule } from '../integration-tenant/integration-tenan
IntegrationTenantModule,
TenantModule,
UserModule,
HubstaffModule,
forwardRef(() => HubstaffModule),
forwardRef(() => IntegrationAIModule),
CqrsModule
],
controllers: [
Expand Down