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

✨ Deel + sage hris integrations #663

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -13,6 +13,7 @@ import { NamelyConnectionService } from './services/namely/namely.service';
import { PayfitConnectionService } from './services/payfit/payfit.service';
import { ServiceRegistry } from './services/registry.service';
import { RipplingConnectionService } from './services/rippling/rippling.service';
import { SageConnectionService } from './services/sage/sage.service';

@Module({
imports: [WebhookModule, BullQueueModule],
Expand All @@ -30,6 +31,7 @@ import { RipplingConnectionService } from './services/rippling/rippling.service'
FactorialConnectionService,
NamelyConnectionService,
BamboohrConnectionService,
SageConnectionService,
],
exports: [HrisConnectionsService],
})
Expand Down
143 changes: 143 additions & 0 deletions packages/api/src/@core/connections/hris/services/sage/sage.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { PrismaService } from '@@core/@core-services/prisma/prisma.service';
import { RetryHandler } from '@@core/@core-services/request-retry/retry.handler';
import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service';
import { ConnectionUtils } from '@@core/connections/@utils';
import {
AbstractBaseConnectionService,
OAuthCallbackParams,
PassthroughInput,
RefreshParams,
} from '@@core/connections/@utils/types';
import { PassthroughResponse } from '@@core/passthrough/types';
import { Injectable } from '@nestjs/common';
import {
AuthStrategy,
CONNECTORS_METADATA,
DynamicApiUrl,
providerToType,
} from '@panora/shared';
import { v4 as uuidv4 } from 'uuid';
import { ServiceRegistry } from '../registry.service';

@Injectable()
export class SageConnectionService extends AbstractBaseConnectionService {
private readonly type: string;

constructor(
protected prisma: PrismaService,
private logger: LoggerService,
protected cryptoService: EncryptionService,
private registry: ServiceRegistry,
private connectionUtils: ConnectionUtils,
private cService: ConnectionsStrategiesService,
private retryService: RetryHandler,
) {
super(prisma, cryptoService);
this.logger.setContext(SageConnectionService.name);
this.registry.registerService('sage', this);
this.type = providerToType('sage', 'hris', AuthStrategy.oauth2);
}

async passthrough(
input: PassthroughInput,
connectionId: string,
): Promise<PassthroughResponse> {
try {
const { headers } = input;
const config = await this.constructPassthrough(input, connectionId);

const connection = await this.prisma.connections.findUnique({
where: {
id_connection: connectionId,
},
});

config.headers = {
...config.headers,
...headers,
'X-Auth-Token': this.cryptoService.decrypt(connection.access_token),
};

return await this.retryService.makeRequest(
{
method: config.method,
url: config.url,
data: config.data,
headers: config.headers,
},
'hris.sage.passthrough',
config.linkedUserId,
);
} catch (error) {
throw error;
}
}
Comment on lines +43 to +76
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove Redundant Catch Block in passthrough Method.

The catch block that only rethrows the original error is redundant and can be removed for clarity.

-    try {
-      const { headers } = input;
-      const config = await this.constructPassthrough(input, connectionId);
-      const connection = await this.prisma.connections.findUnique({
-        where: {
-          id_connection: connectionId,
-        },
-      });
-      config.headers = {
-        ...config.headers,
-        ...headers,
-        'X-Auth-Token': this.cryptoService.decrypt(connection.access_token),
-      };
-      return await this.retryService.makeRequest(
-        {
-          method: config.method,
-          url: config.url,
-          data: config.data,
-          headers: config.headers,
-        },
-        'hris.sage.passthrough',
-        config.linkedUserId,
-      );
-    } catch (error) {
-      throw error;
-    }
+    const { headers } = input;
+    const config = await this.constructPassthrough(input, connectionId);
+    const connection = await this.prisma.connections.findUnique({
+      where: {
+        id_connection: connectionId,
+      },
+    });
+    config.headers = {
+      ...config.headers,
+      ...headers,
+      'X-Auth-Token': this.cryptoService.decrypt(connection.access_token),
+    };
+    return await this.retryService.makeRequest(
+      {
+        method: config.method,
+        url: config.url,
+        data: config.data,
+        headers: config.headers,
+      },
+      'hris.sage.passthrough',
+      config.linkedUserId,
+    );
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async passthrough(
input: PassthroughInput,
connectionId: string,
): Promise<PassthroughResponse> {
try {
const { headers } = input;
const config = await this.constructPassthrough(input, connectionId);
const connection = await this.prisma.connections.findUnique({
where: {
id_connection: connectionId,
},
});
config.headers = {
...config.headers,
...headers,
'X-Auth-Token': this.cryptoService.decrypt(connection.access_token),
};
return await this.retryService.makeRequest(
{
method: config.method,
url: config.url,
data: config.data,
headers: config.headers,
},
'hris.sage.passthrough',
config.linkedUserId,
);
} catch (error) {
throw error;
}
}
async passthrough(
input: PassthroughInput,
connectionId: string,
): Promise<PassthroughResponse> {
const { headers } = input;
const config = await this.constructPassthrough(input, connectionId);
const connection = await this.prisma.connections.findUnique({
where: {
id_connection: connectionId,
},
});
config.headers = {
...config.headers,
...headers,
'X-Auth-Token': this.cryptoService.decrypt(connection.access_token),
};
return await this.retryService.makeRequest(
{
method: config.method,
url: config.url,
data: config.data,
headers: config.headers,
},
'hris.sage.passthrough',
config.linkedUserId,
);
}
Tools
Biome

[error] 74-74: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)


async handleCallback(opts: OAuthCallbackParams) {
try {
const { linkedUserId, projectId, body } = opts;
const { api_key, subdomain } = body;
const isNotUnique = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'sage',
vertical: 'hris',
},
});

let db_res;
const connection_token = uuidv4();
const BASE_API_URL = (
CONNECTORS_METADATA['hris']['sage'].urls.apiUrl as DynamicApiUrl
)(subdomain);

if (isNotUnique) {
db_res = await this.prisma.connections.update({
where: {
id_connection: isNotUnique.id_connection,
},
data: {
access_token: this.cryptoService.encrypt(api_key),
account_url: BASE_API_URL,
status: 'valid',
created_at: new Date(),
},
});
} else {
db_res = await this.prisma.connections.create({
data: {
id_connection: uuidv4(),
connection_token: connection_token,
provider_slug: 'sage',
vertical: 'hris',
token_type: 'basic',
account_url: BASE_API_URL,
access_token: this.cryptoService.encrypt(api_key),
status: 'valid',
created_at: new Date(),
projects: {
connect: { id_project: projectId },
},
linked_users: {
connect: {
id_linked_user: await this.connectionUtils.getLinkedUserId(
projectId,
linkedUserId,
),
},
},
},
});
}
return db_res;
} catch (error) {
throw error;
}
}
Comment on lines +78 to +138
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove Redundant Catch Block in handleCallback Method.

The catch block that only rethrows the original error is redundant and can be removed for clarity.

-    try {
-      const { linkedUserId, projectId, body } = opts;
-      const { api_key, subdomain } = body;
-      const isNotUnique = await this.prisma.connections.findFirst({
-        where: {
-          id_linked_user: linkedUserId,
-          provider_slug: 'sage',
-          vertical: 'hris',
-        },
-      });
-      let db_res;
-      const connection_token = uuidv4();
-      const BASE_API_URL = (
-        CONNECTORS_METADATA['hris']['sage'].urls.apiUrl as DynamicApiUrl
-      )(subdomain);
-      if (isNotUnique) {
-        db_res = await this.prisma.connections.update({
-          where: {
-            id_connection: isNotUnique.id_connection,
-          },
-          data: {
-            access_token: this.cryptoService.encrypt(api_key),
-            account_url: BASE_API_URL,
-            status: 'valid',
-            created_at: new Date(),
-          },
-        });
-      } else {
-        db_res = await this.prisma.connections.create({
-          data: {
-            id_connection: uuidv4(),
-            connection_token: connection_token,
-            provider_slug: 'sage',
-            vertical: 'hris',
-            token_type: 'basic',
-            account_url: BASE_API_URL,
-            access_token: this.cryptoService.encrypt(api_key),
-            status: 'valid',
-            created_at: new Date(),
-            projects: {
-              connect: { id_project: projectId },
-            },
-            linked_users: {
-              connect: {
-                id_linked_user: await this.connectionUtils.getLinkedUserId(
-                  projectId,
-                  linkedUserId,
-                ),
-              },
-            },
-          },
-        });
-      }
-      return db_res;
-    } catch (error) {
-      throw error;
-    }
+    const { linkedUserId, projectId, body } = opts;
+    const { api_key, subdomain } = body;
+    const isNotUnique = await this.prisma.connections.findFirst({
+      where: {
+        id_linked_user: linkedUserId,
+        provider_slug: 'sage',
+        vertical: 'hris',
+      },
+    });
+    let db_res;
+    const connection_token = uuidv4();
+    const BASE_API_URL = (
+      CONNECTORS_METADATA['hris']['sage'].urls.apiUrl as DynamicApiUrl
+    )(subdomain);
+    if (isNotUnique) {
+      db_res = await this.prisma.connections.update({
+        where: {
+          id_connection: isNotUnique.id_connection,
+        },
+        data: {
+          access_token: this.cryptoService.encrypt(api_key),
+          account_url: BASE_API_URL,
+          status: 'valid',
+          created_at: new Date(),
+        },
+      });
+    } else {
+      db_res = await this.prisma.connections.create({
+        data: {
+          id_connection: uuidv4(),
+          connection_token: connection_token,
+          provider_slug: 'sage',
+          vertical: 'hris',
+          token_type: 'basic',
+          account_url: BASE_API_URL,
+          access_token: this.cryptoService.encrypt(api_key),
+          status: 'valid',
+          created_at: new Date(),
+          projects: {
+            connect: { id_project: projectId },
+          },
+          linked_users: {
+            connect: {
+              id_linked_user: await this.connectionUtils.getLinkedUserId(
+                projectId,
+                linkedUserId,
+              ),
+            },
+          },
+        },
+      });
+    }
+    return db_res;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async handleCallback(opts: OAuthCallbackParams) {
try {
const { linkedUserId, projectId, body } = opts;
const { api_key, subdomain } = body;
const isNotUnique = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'sage',
vertical: 'hris',
},
});
let db_res;
const connection_token = uuidv4();
const BASE_API_URL = (
CONNECTORS_METADATA['hris']['sage'].urls.apiUrl as DynamicApiUrl
)(subdomain);
if (isNotUnique) {
db_res = await this.prisma.connections.update({
where: {
id_connection: isNotUnique.id_connection,
},
data: {
access_token: this.cryptoService.encrypt(api_key),
account_url: BASE_API_URL,
status: 'valid',
created_at: new Date(),
},
});
} else {
db_res = await this.prisma.connections.create({
data: {
id_connection: uuidv4(),
connection_token: connection_token,
provider_slug: 'sage',
vertical: 'hris',
token_type: 'basic',
account_url: BASE_API_URL,
access_token: this.cryptoService.encrypt(api_key),
status: 'valid',
created_at: new Date(),
projects: {
connect: { id_project: projectId },
},
linked_users: {
connect: {
id_linked_user: await this.connectionUtils.getLinkedUserId(
projectId,
linkedUserId,
),
},
},
},
});
}
return db_res;
} catch (error) {
throw error;
}
}
async handleCallback(opts: OAuthCallbackParams) {
const { linkedUserId, projectId, body } = opts;
const { api_key, subdomain } = body;
const isNotUnique = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'sage',
vertical: 'hris',
},
});
let db_res;
const connection_token = uuidv4();
const BASE_API_URL = (
CONNECTORS_METADATA['hris']['sage'].urls.apiUrl as DynamicApiUrl
)(subdomain);
if (isNotUnique) {
db_res = await this.prisma.connections.update({
where: {
id_connection: isNotUnique.id_connection,
},
data: {
access_token: this.cryptoService.encrypt(api_key),
account_url: BASE_API_URL,
status: 'valid',
created_at: new Date(),
},
});
} else {
db_res = await this.prisma.connections.create({
data: {
id_connection: uuidv4(),
connection_token: connection_token,
provider_slug: 'sage',
vertical: 'hris',
token_type: 'basic',
account_url: BASE_API_URL,
access_token: this.cryptoService.encrypt(api_key),
status: 'valid',
created_at: new Date(),
projects: {
connect: { id_project: projectId },
},
linked_users: {
connect: {
id_linked_user: await this.connectionUtils.getLinkedUserId(
projectId,
linkedUserId,
),
},
},
},
});
}
return db_res;
}
Tools
Biome

[error] 136-136: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)


handleTokenRefresh?(opts: RefreshParams): Promise<any> {
throw new Error('Method not implemented.');
}
Comment on lines +140 to +142
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider Implementing the handleTokenRefresh Method.

The handleTokenRefresh method is currently not implemented and throws an error. If this is intentional, consider adding a comment to clarify its future purpose.

Would you like assistance in implementing this method or opening a GitHub issue to track this task?

}
31 changes: 24 additions & 7 deletions packages/api/src/@core/utils/types/original/original.hris.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
/* INPUT */

import { GustoBenefitOutput } from '@hris/benefit/services/gusto/types';
import { DeelCompanyOutput } from '@hris/company/services/deel/types';
import { GustoCompanyOutput } from '@hris/company/services/gusto/types';
import { DeelEmployeeOutput } from '@hris/employee/services/deel/types';
import { GustoEmployeeOutput } from '@hris/employee/services/gusto/types';
import { SageEmployeeOutput } from '@hris/employee/services/sage/types';
import { GustoEmployerbenefitOutput } from '@hris/employerbenefit/services/gusto/types';
import { DeelEmploymentOutput } from '@hris/employment/services/deel/types';
import { GustoEmploymentOutput } from '@hris/employment/services/gusto/types';
import { DeelGroupOutput } from '@hris/group/services/deel/types';
import { GustoGroupOutput } from '@hris/group/services/gusto/types';
import { SageGroupOutput } from '@hris/group/services/sage/types';
import { DeelLocationOutput } from '@hris/location/services/deel/types';
import { GustoLocationOutput } from '@hris/location/services/gusto/types';
import { SageTimeoffOutput } from '@hris/timeoff/services/sage/types';
import { SageTimeoffbalanceOutput } from '@hris/timeoffbalance/services/sage/types';

/* bankinfo */
export type OriginalBankInfoInput = any;
Expand Down Expand Up @@ -79,13 +88,16 @@ export type OriginalBankInfoOutput = any;
export type OriginalBenefitOutput = GustoBenefitOutput;

/* company */
export type OriginalCompanyOutput = GustoCompanyOutput;
export type OriginalCompanyOutput = GustoCompanyOutput | DeelCompanyOutput;

/* dependent */
export type OriginalDependentOutput = any;

/* employee */
export type OriginalEmployeeOutput = GustoEmployeeOutput;
export type OriginalEmployeeOutput =
| GustoEmployeeOutput
| SageEmployeeOutput
| DeelEmployeeOutput;

/* employeepayrollrun */
export type OriginalEmployeePayrollRunOutput = any;
Expand All @@ -94,13 +106,18 @@ export type OriginalEmployeePayrollRunOutput = any;
export type OriginalEmployerBenefitOutput = GustoEmployerbenefitOutput;

/* employment */
export type OriginalEmploymentOutput = GustoEmploymentOutput;
export type OriginalEmploymentOutput =
| GustoEmploymentOutput
| DeelEmploymentOutput;

/* group */
export type OriginalGroupOutput = GustoGroupOutput;
export type OriginalGroupOutput =
| GustoGroupOutput
| DeelGroupOutput
| SageGroupOutput;

/* location */
export type OriginalLocationOutput = GustoLocationOutput;
export type OriginalLocationOutput = GustoLocationOutput | DeelLocationOutput;

/* paygroup */
export type OriginalPayGroupOutput = any;
Expand All @@ -109,10 +126,10 @@ export type OriginalPayGroupOutput = any;
export type OriginalPayrollRunOutput = any;

/* timeoff */
export type OriginalTimeoffOutput = any;
export type OriginalTimeoffOutput = SageTimeoffOutput;

/* timeoffbalance */
export type OriginalTimeoffBalanceOutput = any;
export type OriginalTimeoffBalanceOutput = SageTimeoffbalanceOutput;

/* timesheetentry */
export type OriginalTimesheetentryOutput = any;
Expand Down
15 changes: 15 additions & 0 deletions packages/api/src/hris/@lib/@utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ export class Utils {
}
}

async getGroupUuidFromRemoteId(id: string, connection_id: string) {
try {
const res = await this.prisma.hris_groups.findFirst({
where: {
remote_id: id,
id_connection: connection_id,
},
});
if (!res) return;
return res.id_hris_group;
} catch (error) {
throw error;
}
}
Comment on lines +38 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant catch block.

The catch block that only rethrows the original error is unnecessary and can be removed for clarity.

-    } catch (error) {
-      throw error;
-    }
+    }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async getGroupUuidFromRemoteId(id: string, connection_id: string) {
try {
const res = await this.prisma.hris_groups.findFirst({
where: {
remote_id: id,
id_connection: connection_id,
},
});
if (!res) return;
return res.id_hris_group;
} catch (error) {
throw error;
}
}
async getGroupUuidFromRemoteId(id: string, connection_id: string) {
try {
const res = await this.prisma.hris_groups.findFirst({
where: {
remote_id: id,
id_connection: connection_id,
},
});
if (!res) return;
return res.id_hris_group;
}
}
Tools
Biome

[error] 49-49: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)


async getEmployerBenefitUuidFromRemoteId(id: string, connection_id: string) {
try {
const res = await this.prisma.hris_employer_benefits.findFirst({
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/hris/company/company.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { CoreUnification } from '@@core/@core-services/unification/core-unificat
import { GustoCompanyMapper } from './services/gusto/mappers';
import { GustoService } from './services/gusto';
import { Utils } from '@hris/@lib/@utils';
import { DeelService } from './services/deel';
import { DeelCompanyMapper } from './services/deel/mappers';
@Module({
controllers: [CompanyController],
providers: [
Expand All @@ -20,8 +22,10 @@ import { Utils } from '@hris/@lib/@utils';
ServiceRegistry,
IngestDataService,
GustoCompanyMapper,
DeelCompanyMapper,
/* PROVIDERS SERVICES */
GustoService,
DeelService,
],
exports: [SyncService],
})
Expand Down
72 changes: 72 additions & 0 deletions packages/api/src/hris/company/services/deel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { EnvironmentService } from '@@core/@core-services/environment/environment.service';
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { PrismaService } from '@@core/@core-services/prisma/prisma.service';
import { ApiResponse } from '@@core/utils/types';
import { SyncParam } from '@@core/utils/types/interface';
import { HrisObject } from '@hris/@lib/@types';
import { ICompanyService } from '@hris/company/types';
import { Injectable } from '@nestjs/common';
import axios from 'axios';
import { ServiceRegistry } from '../registry.service';
import { DeelCompanyOutput } from './types';
import { DesunifyReturnType } from '@@core/utils/types/desunify.input';
import { OriginalCompanyOutput } from '@@core/utils/types/original/original.hris';

@Injectable()
export class DeelService implements ICompanyService {
constructor(
private prisma: PrismaService,
private logger: LoggerService,
private cryptoService: EncryptionService,
private env: EnvironmentService,
private registry: ServiceRegistry,
) {
this.logger.setContext(
HrisObject.company.toUpperCase() + ':' + DeelService.name,
);
this.registry.registerService('deel', this);
}
Comment on lines +16 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use template literals for string concatenation.

Instead of using string concatenation with +, prefer using template literals for better readability and performance.

-    this.logger.setContext(
-      HrisObject.company.toUpperCase() + ':' + DeelService.name,
-    );
+    this.logger.setContext(
+      `${HrisObject.company.toUpperCase()}:${DeelService.name}`,
+    );
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Injectable()
export class DeelService implements ICompanyService {
constructor(
private prisma: PrismaService,
private logger: LoggerService,
private cryptoService: EncryptionService,
private env: EnvironmentService,
private registry: ServiceRegistry,
) {
this.logger.setContext(
HrisObject.company.toUpperCase() + ':' + DeelService.name,
);
this.registry.registerService('deel', this);
}
@Injectable()
export class DeelService implements ICompanyService {
constructor(
private prisma: PrismaService,
private logger: LoggerService,
private cryptoService: EncryptionService,
private env: EnvironmentService,
private registry: ServiceRegistry,
) {
this.logger.setContext(
`${HrisObject.company.toUpperCase()}:${DeelService.name}`,
);
this.registry.registerService('deel', this);
}
Tools
Biome

[error] 26-26: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


addCompany(
companyData: DesunifyReturnType,
linkedUserId: string,
): Promise<ApiResponse<OriginalCompanyOutput>> {
throw new Error('Method not implemented.');
}
Comment on lines +31 to +36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement the addCompany method.

The addCompany method is currently not implemented. Consider implementing this method or providing a clear reason for its absence.

Do you need help implementing this method, or should I open a GitHub issue to track this task?


async sync(data: SyncParam): Promise<ApiResponse<DeelCompanyOutput[]>> {
try {
const { linkedUserId } = data;

const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'deel',
vertical: 'hris',
},
});

const resp = await axios.get(
`${connection.account_url}/rest/v2/legal-entities`,
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.cryptoService.decrypt(
connection.access_token,
)}`,
},
},
);
this.logger.log(`Synced deel companys !`);

return {
data: resp.data.data,
message: 'Deel companys retrieved',
statusCode: 200,
};
} catch (error) {
throw error;
}
}
Comment on lines +38 to +71
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant catch clause.

The catch clause that only rethrows the original error is redundant and can be removed to simplify the code.

-    } catch (error) {
-      throw error;
-    }
+    }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async sync(data: SyncParam): Promise<ApiResponse<DeelCompanyOutput[]>> {
try {
const { linkedUserId } = data;
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'deel',
vertical: 'hris',
},
});
const resp = await axios.get(
`${connection.account_url}/rest/v2/legal-entities`,
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.cryptoService.decrypt(
connection.access_token,
)}`,
},
},
);
this.logger.log(`Synced deel companys !`);
return {
data: resp.data.data,
message: 'Deel companys retrieved',
statusCode: 200,
};
} catch (error) {
throw error;
}
}
async sync(data: SyncParam): Promise<ApiResponse<DeelCompanyOutput[]>> {
try {
const { linkedUserId } = data;
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'deel',
vertical: 'hris',
},
});
const resp = await axios.get(
`${connection.account_url}/rest/v2/legal-entities`,
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.cryptoService.decrypt(
connection.access_token,
)}`,
},
},
);
this.logger.log(`Synced deel companys !`);
return {
data: resp.data.data,
message: 'Deel companys retrieved',
statusCode: 200,
};
}
}
Tools
Biome

[error] 69-69: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)

}
Loading
Loading