Skip to content

Commit

Permalink
Updated utils.js
Browse files Browse the repository at this point in the history
  • Loading branch information
moksha-hub authored Dec 18, 2024
1 parent 9864626 commit 5d7ff03
Showing 1 changed file with 50 additions and 54 deletions.
104 changes: 50 additions & 54 deletions src/api/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,66 +69,62 @@ export async function getBrowsedRelationships(
return [];

Check failure on line 69 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L69

Expected indentation of 2 tabs but found 8 spaces (indent)
}

Check failure on line 70 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L70

Expected indentation of 1 tab but found 4 spaces (indent)

try {
const relationshipsResults = [];

for (const relationship of relationships) {
let relEntity;

if (
entity.bbid === relationship.sourceBbid &&
relationship.target.type.toLowerCase() === browsedEntityType.toLowerCase()
) {
relEntity = relationship.target;
} else if (
relationship.source.type.toLowerCase() === browsedEntityType.toLowerCase()
) {
relEntity = relationship.source;
}
const relationshipsResults = [];

Check failure on line 72 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L72

Expected indentation of 1 tab but found 4 spaces (indent)

for (const relationship of relationships) {

Check failure on line 74 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L74

Expected indentation of 1 tab but found 4 spaces (indent)
let relEntity;

Check failure on line 75 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L75

Expected indentation of 2 tabs but found 8 spaces (indent)

if (

Check failure on line 77 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L77

Expected indentation of 2 tabs but found 8 spaces (indent)
entity.bbid === relationship.sourceBbid &&

Check failure on line 78 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L78

Expected indentation of 3 tabs but found 12 spaces (indent)
relationship.target.type.toLowerCase() === browsedEntityType.toLowerCase()
) {

Check failure on line 80 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L80

Expected indentation of 2 tabs but found 8 spaces (indent)
relEntity = relationship.target;

Check failure on line 81 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L81

Expected indentation of 3 tabs but found 12 spaces (indent)
} else if (

Check failure on line 82 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L82

Expected indentation of 2 tabs but found 8 spaces (indent)

Check failure on line 82 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L82

Closing curly brace appears on the same line as the subsequent block (brace-style)
relationship.source.type.toLowerCase() === browsedEntityType.toLowerCase()

Check failure on line 83 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L83

Expected indentation of 3 tabs but found 12 spaces (indent)
) {

Check failure on line 84 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L84

Expected indentation of 2 tabs but found 8 spaces (indent)
relEntity = relationship.source;

Check failure on line 85 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L85

Expected indentation of 3 tabs but found 12 spaces (indent)
}

Check failure on line 86 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L86

Expected indentation of 2 tabs but found 8 spaces (indent)

if (relEntity) {

Check failure on line 88 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L88

Expected indentation of 2 tabs but found 8 spaces (indent)
try {

Check failure on line 89 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L89

Expected indentation of 3 tabs but found 12 spaces (indent)
const loadedRelEntity = await loadEntity(orm, relEntity, fetchRelated);

Check failure on line 90 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L90

Expected indentation of 4 tabs but found 16 spaces (indent)

Check failure on line 90 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L90

Unexpected `await` inside a loop (no-await-in-loop)
const formattedRelEntity = getEntityInfoMethod(loadedRelEntity);

Check failure on line 91 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L91

Expected indentation of 4 tabs but found 16 spaces (indent)

if (relEntity) {
try {
const loadedRelEntity = await loadEntity(orm, relEntity, fetchRelated);
const formattedRelEntity = getEntityInfoMethod(loadedRelEntity);

if (!filterRelationshipMethod(formattedRelEntity)) {
continue;
}

relationshipsResults.push({
entity: formattedRelEntity,
relationships: [
{
relationshipType: _get(relationship, 'type.label', null),
relationshipTypeID: _get(relationship, 'type.id', null),
},
],
});
} catch (err) {
console.error(
`Error loading entity for relationship: ${err.message}`,
err
);
if (!filterRelationshipMethod(formattedRelEntity)) {

Check failure on line 93 in src/api/helpers/utils.js

View workflow job for this annotation

GitHub Actions / ESLint

src/api/helpers/utils.js#L93

Expected indentation of 4 tabs but found 16 spaces (indent)
continue;
}

relationshipsResults.push({
entity: formattedRelEntity,
relationships: [
{
relationshipType: _get(relationship, 'type.label', null),
relationshipTypeID: _get(relationship, 'type.id', null),
},
],
});
} catch (err) {
console.error(
`Error loading entity for relationship: ${err.message}`,
err
);
}
}
}

return relationshipsResults.reduce((accumulator, relationship) => {
const entityAlreadyExists = accumulator.find(
(rel) => rel.entity.bbid === relationship.entity.bbid
);
return relationshipsResults.reduce((accumulator, relationship) => {
const entityAlreadyExists = accumulator.find(
(rel) => rel.entity.bbid === relationship.entity.bbid
);

if (entityAlreadyExists) {
entityAlreadyExists.relationships.push(...relationship.relationships);
} else {
accumulator.push(relationship);
}
if (entityAlreadyExists) {
entityAlreadyExists.relationships.push(...relationship.relationships);
} else {
accumulator.push(relationship);
}

return accumulator;
}, []);
} catch (err) {
console.error(`Error processing relationships: ${err.message}`, err);
throw new Error('Failed to fetch browsed relationships.');
}
return accumulator;
}, []);
}


0 comments on commit 5d7ff03

Please sign in to comment.