Skip to content

Commit

Permalink
IMN-865 - Fixing descriptor attributes conversion in BFF (#1048)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecamellini authored Oct 2, 2024
1 parent 3516308 commit 8c891e6
Showing 1 changed file with 35 additions and 32 deletions.
67 changes: 35 additions & 32 deletions packages/backend-for-frontend/src/api/catalogApiConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,19 @@ export function toBffCatalogDescriptorEService(

export function toBffCatalogApiDescriptorAttribute(
attributes: attributeRegistryApi.Attribute[],
descriptorAttributes: catalogApi.Attribute[]
): bffApi.DescriptorAttribute[] {
return descriptorAttributes.map((attribute) => {
const foundAttribute = attributes.find((att) => att.id === attribute.id);
if (!foundAttribute) {
throw attributeNotExists(unsafeBrandId(attribute.id));
}
attribute: catalogApi.Attribute
): bffApi.DescriptorAttribute {
const foundAttribute = attributes.find((att) => att.id === attribute.id);
if (!foundAttribute) {
throw attributeNotExists(unsafeBrandId(attribute.id));
}

return {
id: attribute.id,
name: foundAttribute.name,
description: foundAttribute.description,
explicitAttributeVerification: attribute.explicitAttributeVerification,
};
});
return {
id: attribute.id,
name: foundAttribute.name,
description: foundAttribute.description,
explicitAttributeVerification: attribute.explicitAttributeVerification,
};
}

export function toBffCatalogApiDescriptorDoc(
Expand Down Expand Up @@ -287,29 +285,34 @@ export function toDescriptorWithOnlyAttributes(
};
}

function toBffCatalogApiDescriptorAttributeGroups(
attributes: attributeRegistryApi.Attribute[],
descriptorAttributesGroups: catalogApi.Attribute[][]
): bffApi.DescriptorAttribute[][] {
return descriptorAttributesGroups.map((attributeGroup) =>
attributeGroup.map((attribute) =>
toBffCatalogApiDescriptorAttribute(attributes, attribute)
)
);
}

export function toBffCatalogApiDescriptorAttributes(
attributes: attributeRegistryApi.Attribute[],
descriptor: catalogApi.EServiceDescriptor
): bffApi.DescriptorAttributes {
return {
certified: [
toBffCatalogApiDescriptorAttribute(
attributes,
descriptor.attributes.certified.flat()
),
],
declared: [
toBffCatalogApiDescriptorAttribute(
attributes,
descriptor.attributes.declared.flat()
),
],
verified: [
toBffCatalogApiDescriptorAttribute(
attributes,
descriptor.attributes.verified.flat()
),
],
certified: toBffCatalogApiDescriptorAttributeGroups(
attributes,
descriptor.attributes.certified
),
declared: toBffCatalogApiDescriptorAttributeGroups(
attributes,
descriptor.attributes.declared
),
verified: toBffCatalogApiDescriptorAttributeGroups(
attributes,
descriptor.attributes.verified
),
};
}

Expand Down

0 comments on commit 8c891e6

Please sign in to comment.