Skip to content

Commit

Permalink
chore(all-services): rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
yeshamavani committed Dec 10, 2024
1 parent 6d13f5b commit 0d40eba
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
9 changes: 6 additions & 3 deletions packages/archival/src/aws-s3/import-archive-data.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@loopback/core';
import {AnyObject} from '@loopback/repository';
import {HttpErrors} from '@loopback/rest';
// eslint-disable-next-line @typescript-eslint/naming-convention
import AWS from 'aws-sdk';
import {ImportDataExternalSystem} from '../types';

Expand All @@ -32,10 +33,10 @@ export class ImportArchiveDataProvider
Bucket: process.env.AWS_S3_BUCKET_NAME as string,
Key: fileName,
};
let data;
let s3Response;
try {
data = await s3.getObject(params).promise();
const csvData = data.Body!.toString('utf-8');
s3Response = await s3.getObject(params).promise();
const csvData = s3Response.Body!.toString('utf-8');

const jsonArray: AnyObject[] = await new Promise((resolve, reject) => {
const results: AnyObject[] = [];
Expand All @@ -48,6 +49,7 @@ export class ImportArchiveDataProvider
const headers = Object.keys(jsonArray[0]);
for (const entry of jsonArray) {
for (const key of headers) {
//sonarignore:start
const value = entry[key];
if (value === '') {
entry[key] = null;
Expand All @@ -58,6 +60,7 @@ export class ImportArchiveDataProvider
entry[key] = new Date(value);
} else entry[key] = value;
}
//sonarignore:end
}
return jsonArray;
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions packages/archival/src/mixins/archival.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
User,
} from '../types';

// NOSONAR - ignore camelCase naming convention
export function ArchivalRepositoryMixin<
T extends UserModifiableEntity,
ID,
Expand Down
21 changes: 12 additions & 9 deletions packages/archival/src/services/import-archived-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import {

@injectable({scope: BindingScope.TRANSIENT})
export class ImportArchivedDataService {
repo: AnyObject;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
repo: any;
constructor(
@repository(JobDetailsRepository)
public jobDetailsRepo: JobDetailsRepository,
Expand Down Expand Up @@ -59,7 +60,6 @@ export class ImportArchivedDataService {
const jobDetails = await this.jobDetailsRepo.findById(jobId);
const modelName = jobDetails.entity;
const filter = jobDetails.filterInquired;
const importData: AnyObject = {};

const archiveFilter: Filter<ArchiveMapping> =
await this.buildWhereConditionService.buildConditionForFetch(
Expand All @@ -69,7 +69,7 @@ export class ImportArchivedDataService {

const archivedEntries = await this.archivalMappingRepo.find(archiveFilter);

let data: AnyObject[] = [];
const data: AnyObject[] = [];

for (const entry of archivedEntries) {
const fileContent = await this.importArchiveData(entry.key);
Expand Down Expand Up @@ -105,26 +105,29 @@ export class ImportArchivedDataService {
status: JobStatus.SUCCESS,
result: JSON.stringify(allRecords),
});
this.processImportedData(allRecords);
await this.processImportedData(allRecords);
}

async getFilteredData() {}

// sonarignore:start
private async getRepositoryByModelName<T extends Entity>(
modelName: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): Promise<DefaultCrudRepository<T, any> | undefined> {
// Find all bindings with keys matching 'repositories.*'
const repositoryBindings =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.context.find<DefaultCrudRepository<any, any>>('repositories.*');

// Iterate through the bindings to find the matching repository
for (const binding of repositoryBindings) {
const repository = await this.context.get<
const repoName = await this.context.get<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
DefaultCrudRepository<any, any>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
>(binding.key as unknown as BindingKey<DefaultCrudRepository<any, any>>);
if (repository.entityClass.name === modelName) {
return repository as DefaultCrudRepository<T, any>;
if (repoName.entityClass.name === modelName) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return repoName as DefaultCrudRepository<T, any>;
}
}
// sonarignore:end
Expand Down
2 changes: 2 additions & 0 deletions packages/archival/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export type MixinBaseClass<T> = AbstractConstructor<T>;

export type ArchiveMixinBase<
T extends UserModifiableEntity,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
ID,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Relations,
> = MixinBaseClass<{
entityClass: typeof UserModifiableEntity & {
Expand Down

0 comments on commit 0d40eba

Please sign in to comment.