-
Notifications
You must be signed in to change notification settings - Fork 1
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
IMN-657 GET EService descriptor by ID #712
Changes from 8 commits
a02dc84
b6d1ce8
af35559
56a0277
b1ac408
8f82ffe
87effa8
6b080a5
107daaa
17be40e
6006856
33b8648
392cb8c
43848ef
480d433
5bb768c
dfba69b
6429d36
9cf1835
7dc73a2
846effd
98a7bad
748d8c6
9fe126b
9e9d46e
3d974f2
00e0562
1b30f5a
28954da
d3d4657
5ba6040
31c5dcd
11026a3
c41d3ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,211 @@ | ||||||
/* eslint-disable functional/immutable-data */ | ||||||
/* eslint-disable max-params */ | ||||||
import { DescriptorWithOnlyAttributes } from "pagopa-interop-agreement-lifecycle"; | ||||||
import { | ||||||
agreementApi, | ||||||
bffApi, | ||||||
catalogApi, | ||||||
tenantApi, | ||||||
attributeRegistryApi, | ||||||
} from "pagopa-interop-api-clients"; | ||||||
import { | ||||||
EServiceAttribute, | ||||||
tenantMailKind, | ||||||
unsafeBrandId, | ||||||
} from "pagopa-interop-models"; | ||||||
import { attributeNotExists } from "../../domain/errors.js"; | ||||||
import { agreementApiState } from "../agreementTypes.js"; | ||||||
import { descriptorApiState } from "../catalogTypes.js"; | ||||||
|
||||||
export function toEserviceCatalogProcessQueryParams( | ||||||
queryParams: bffApi.BffGetCatalogQueryParam | ||||||
): catalogApi.GetCatalogQueryParam { | ||||||
return { | ||||||
...queryParams, | ||||||
eservicesIds: [], | ||||||
name: queryParams.q, | ||||||
}; | ||||||
} | ||||||
|
||||||
export function toBffCatalogApiEService( | ||||||
eservice: catalogApi.EService, | ||||||
producerTenant: tenantApi.Tenant, | ||||||
hasCertifiedAttributes: boolean, | ||||||
isRequesterEqProducer: boolean, | ||||||
activeDescriptor?: catalogApi.EServiceDescriptor, | ||||||
agreement?: agreementApi.Agreement | ||||||
): bffApi.CatalogEService { | ||||||
const isUpgradable = (agreement: agreementApi.Agreement): boolean => { | ||||||
const eserviceDescriptor = eservice.descriptors.find( | ||||||
(e) => e.id === agreement.descriptorId | ||||||
); | ||||||
|
||||||
return ( | ||||||
eserviceDescriptor !== undefined && | ||||||
eservice.descriptors | ||||||
.filter((d) => Number(d.version) > Number(eserviceDescriptor.version)) | ||||||
.find( | ||||||
(d) => | ||||||
(d.state === descriptorApiState.PUBLISHED || | ||||||
d.state === descriptorApiState.SUSPENDED) && | ||||||
(agreement.state === agreementApiState.ACTIVE || | ||||||
agreement.state === agreementApiState.SUSPENDED) | ||||||
) !== undefined | ||||||
); | ||||||
}; | ||||||
|
||||||
const partialEnhancedEservice = { | ||||||
id: eservice.id, | ||||||
name: eservice.name, | ||||||
description: eservice.description, | ||||||
producer: { | ||||||
id: eservice.producerId, | ||||||
name: producerTenant.name, | ||||||
}, | ||||||
isMine: isRequesterEqProducer, | ||||||
hasCertifiedAttributes, | ||||||
}; | ||||||
|
||||||
return { | ||||||
...partialEnhancedEservice, | ||||||
...(activeDescriptor | ||||||
? { | ||||||
activeDescriptor: { | ||||||
id: activeDescriptor.id, | ||||||
version: activeDescriptor.version, | ||||||
audience: activeDescriptor.audience, | ||||||
state: activeDescriptor.state, | ||||||
}, | ||||||
} | ||||||
: {}), | ||||||
...(agreement | ||||||
? { | ||||||
agreement: { | ||||||
id: agreement.id, | ||||||
state: agreement.state, | ||||||
canBeUpgraded: isUpgradable(agreement), | ||||||
}, | ||||||
} | ||||||
: {}), | ||||||
}; | ||||||
} | ||||||
|
||||||
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)); | ||||||
} | ||||||
|
||||||
return { | ||||||
id: attribute.id, | ||||||
name: foundAttribute.name, | ||||||
description: foundAttribute.description, | ||||||
explicitAttributeVerification: attribute.explicitAttributeVerification, | ||||||
}; | ||||||
}); | ||||||
} | ||||||
|
||||||
export function toBffCatalogApiDescriptorInterface( | ||||||
AsterITA marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
document: catalogApi.EServiceDoc | ||||||
): bffApi.EServiceDoc { | ||||||
return { | ||||||
id: document.id, | ||||||
name: document.name, | ||||||
contentType: document.contentType, | ||||||
prettyName: document.prettyName, | ||||||
}; | ||||||
} | ||||||
|
||||||
export function toBffCatalogApiEserviceRiskAnalysis( | ||||||
riskAnalysis: catalogApi.EServiceRiskAnalysis | ||||||
): bffApi.EServiceRiskAnalysis { | ||||||
const answers: { [key: string]: string[] } = {}; | ||||||
|
||||||
riskAnalysis.riskAnalysisForm.singleAnswers | ||||||
.concat(riskAnalysis.riskAnalysisForm.multiAnswers) | ||||||
.map((answer) => ({ | ||||||
questionId: answer.questionId, | ||||||
answer: answer.value, | ||||||
})) | ||||||
.forEach((QA) => { | ||||||
if (answers[`${QA.questionId}`] && QA.answer) { | ||||||
answers[`${QA.questionId}`] = [ | ||||||
...answers[`${QA.questionId}`], | ||||||
QA.answer, | ||||||
]; | ||||||
} else { | ||||||
answers[`${QA.questionId}`] = []; | ||||||
} | ||||||
}); | ||||||
AsterITA marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
const riskAnalysisForm: bffApi.RiskAnalysisForm = { | ||||||
riskAnalysisId: riskAnalysis.id, | ||||||
version: riskAnalysis.riskAnalysisForm.version, | ||||||
answers, | ||||||
}; | ||||||
|
||||||
return { | ||||||
id: riskAnalysis.id, | ||||||
name: riskAnalysis.name, | ||||||
createdAt: riskAnalysis.createdAt, | ||||||
riskAnalysisForm, | ||||||
}; | ||||||
} | ||||||
|
||||||
export function toBffCatalogApiProducerDescriptorEService( | ||||||
eservice: catalogApi.EService, | ||||||
producer: tenantApi.Tenant | ||||||
): bffApi.ProducerDescriptorEService { | ||||||
const producerMail = producer.mails.find( | ||||||
(m) => m.kind === tenantMailKind.ContactEmail | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know the values are the same and that TS probably helps with this, but here you are comparing enums of different types:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Furthermore this commit move it to separate file |
||||||
); | ||||||
|
||||||
const notDraftDecriptor: bffApi.CompactDescriptor[] = | ||||||
AsterITA marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
eservice.descriptors.filter((d) => d.state !== descriptorApiState.DRAFT); | ||||||
|
||||||
const draftDescriptor: bffApi.CompactDescriptor | undefined = | ||||||
eservice.descriptors.find((d) => d.state === descriptorApiState.DRAFT); | ||||||
|
||||||
return { | ||||||
id: eservice.id, | ||||||
name: eservice.name, | ||||||
description: eservice.description, | ||||||
technology: eservice.technology, | ||||||
mode: eservice.mode, | ||||||
mail: producerMail && { | ||||||
address: producerMail.address, | ||||||
description: producerMail.description, | ||||||
}, | ||||||
draftDescriptor, | ||||||
riskAnalysis: eservice.riskAnalysis.map( | ||||||
toBffCatalogApiEserviceRiskAnalysis | ||||||
), | ||||||
descriptors: notDraftDecriptor, | ||||||
}; | ||||||
} | ||||||
|
||||||
export function toEserviceAttribute( | ||||||
attributes: catalogApi.Attribute[] | ||||||
): EServiceAttribute[] { | ||||||
return attributes.map((attribute) => ({ | ||||||
...attribute, | ||||||
id: unsafeBrandId(attribute.id), | ||||||
})); | ||||||
} | ||||||
|
||||||
export function toDescriptorWithOnlyAttributes( | ||||||
descriptor: catalogApi.EServiceDescriptor | ||||||
): DescriptorWithOnlyAttributes { | ||||||
return { | ||||||
...descriptor, | ||||||
attributes: { | ||||||
certified: descriptor.attributes.certified.map(toEserviceAttribute), | ||||||
declared: descriptor.attributes.declared.map(toEserviceAttribute), | ||||||
verified: descriptor.attributes.verified.map(toEserviceAttribute), | ||||||
}, | ||||||
}; | ||||||
} | ||||||
Comment on lines
+173
to
+193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are using runtime resources to change something at type level, I know the performance impact could be negligible but I saw this in a lot of part of the monorepo and I'm wondering if it is worth discussing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Carminepo2 good point 👍🏻 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference: an almost the same function is present here in another PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Carminepo2 in this commit have introduced a new file
mappers.ts
, my intent is to move here the commons function used to pick, transform or evaluate data.Also in this next PR I'm using this approach, but in this case probably I prefer to place this method in mapper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this commit move this logic in a specific file