-
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 11 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -109,7 +109,7 @@ export function toBffCatalogApiDescriptorAttribute( | |||||
}); | ||||||
} | ||||||
|
||||||
export function toBffCatalogApiDescriptorInterface( | ||||||
export function toBffCatalogApiDescriptorDoc( | ||||||
document: catalogApi.EServiceDoc | ||||||
): bffApi.EServiceDoc { | ||||||
return { | ||||||
|
@@ -123,24 +123,27 @@ export function toBffCatalogApiDescriptorInterface( | |||||
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}`] = []; | ||||||
} | ||||||
}); | ||||||
const answers: { [key: string]: string[] } = | ||||||
riskAnalysis.riskAnalysisForm.singleAnswers | ||||||
.concat( | ||||||
riskAnalysis.riskAnalysisForm.multiAnswers.flatMap((multiAnswer) => | ||||||
multiAnswer.values.map((answerValue) => ({ | ||||||
id: multiAnswer.id, | ||||||
value: answerValue, | ||||||
key: multiAnswer.key, | ||||||
})) | ||||||
) | ||||||
) | ||||||
.reduce((answers: { [key: string]: string[] }, answer) => { | ||||||
const key = `${answer.key}`; | ||||||
Viktor-K marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
if (answers[key] && answer.value) { | ||||||
answers[key] = [...answers[key], answer.value]; | ||||||
} else { | ||||||
answers[key] = []; | ||||||
AsterITA marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
return answers; | ||||||
}, {}); | ||||||
|
||||||
const riskAnalysisForm: bffApi.RiskAnalysisForm = { | ||||||
riskAnalysisId: riskAnalysis.id, | ||||||
|
@@ -164,7 +167,7 @@ export function toBffCatalogApiProducerDescriptorEService( | |||||
(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[] = | ||||||
const notDraftDecriptors: bffApi.CompactDescriptor[] = | ||||||
eservice.descriptors.filter((d) => d.state !== descriptorApiState.DRAFT); | ||||||
|
||||||
const draftDescriptor: bffApi.CompactDescriptor | undefined = | ||||||
|
@@ -184,7 +187,7 @@ export function toBffCatalogApiProducerDescriptorEService( | |||||
riskAnalysis: eservice.riskAnalysis.map( | ||||||
toBffCatalogApiEserviceRiskAnalysis | ||||||
), | ||||||
descriptors: notDraftDecriptor, | ||||||
descriptors: notDraftDecriptors, | ||||||
}; | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,16 +6,11 @@ import { | |||||
bffApi, | ||||||
attributeRegistryApi, | ||||||
} from "pagopa-interop-api-clients"; | ||||||
import { | ||||||
DescriptorId, | ||||||
EServiceId, | ||||||
TenantId, | ||||||
unsafeBrandId, | ||||||
} from "pagopa-interop-models"; | ||||||
import { DescriptorId, EServiceId, unsafeBrandId } from "pagopa-interop-models"; | ||||||
import { descriptorApiState } from "../model/api/catalogTypes.js"; | ||||||
import { | ||||||
toBffCatalogApiDescriptorAttribute, | ||||||
toBffCatalogApiDescriptorInterface, | ||||||
toBffCatalogApiDescriptorDoc, | ||||||
toBffCatalogApiEService, | ||||||
toBffCatalogApiProducerDescriptorEService, | ||||||
} from "../model/api/converters/catalogClientApiConverter.js"; | ||||||
|
@@ -50,7 +45,7 @@ const enhanceCatalogEService = | |||||
requesterId: string | ||||||
): ((eservice: catalogApi.EService) => Promise<bffApi.CatalogEService>) => | ||||||
async (eservice: catalogApi.EService): Promise<bffApi.CatalogEService> => { | ||||||
const producerTenant = await tenantProcessClient.getTenant({ | ||||||
const producerTenant = await tenantProcessClient.tenant.getTenant({ | ||||||
headers, | ||||||
params: { | ||||||
id: eservice.producerId, | ||||||
|
@@ -59,7 +54,7 @@ const enhanceCatalogEService = | |||||
|
||||||
const requesterTenant: tenantApi.Tenant = | ||||||
requesterId !== eservice.producerId | ||||||
? await tenantProcessClient.getTenant({ | ||||||
? await tenantProcessClient.tenant.getTenant({ | ||||||
headers, | ||||||
params: { | ||||||
id: requesterId, | ||||||
|
@@ -129,6 +124,36 @@ const getBulkAttributes = async ( | |||||
return await attributesBulk(0, []); | ||||||
}; | ||||||
|
||||||
const getEserviceDesciptor = ( | ||||||
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.
Suggested change
We can align this name with the other retrieves like this and we can fix the typo 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. Done with this commit |
||||||
eservice: catalogApi.EService, | ||||||
descriptorId: DescriptorId | ||||||
): catalogApi.EServiceDescriptor => { | ||||||
const descriptor = eservice.descriptors.find((e) => e.id === descriptorId); | ||||||
|
||||||
if (!descriptor) { | ||||||
throw eserviceDescriptorNotFound( | ||||||
unsafeBrandId<EServiceId>(eservice.id), // catalogApi.EService type is missing branded types | ||||||
descriptorId | ||||||
); | ||||||
} | ||||||
|
||||||
return descriptor; | ||||||
}; | ||||||
|
||||||
const getAttributeIds = ( | ||||||
descriptor: catalogApi.EServiceDescriptor | ||||||
): string[] => [ | ||||||
...descriptor.attributes.certified.flatMap((atts) => | ||||||
atts.map((att) => att.id) | ||||||
), | ||||||
...descriptor.attributes.declared.flatMap((atts) => | ||||||
atts.map((att) => att.id) | ||||||
), | ||||||
...descriptor.attributes.verified.flatMap((atts) => | ||||||
atts.map((att) => att.id) | ||||||
), | ||||||
]; | ||||||
|
||||||
export function catalogServiceBuilder( | ||||||
catalogProcessClient: CatalogProcessClient, | ||||||
tenantProcessClient: TenantProcessClient, | ||||||
|
@@ -176,8 +201,8 @@ export function catalogServiceBuilder( | |||||
return response; | ||||||
}, | ||||||
getProducerEServiceDescriptor: async ( | ||||||
eServiceId: string, | ||||||
descriptorId: string, | ||||||
eserviceId: EServiceId, | ||||||
AsterITA marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
descriptorId: DescriptorId, | ||||||
context: WithLogger<BffAppContext> | ||||||
): Promise<bffApi.ProducerEServiceDescriptor> => { | ||||||
const requesterId = context.authData.organizationId; | ||||||
|
@@ -186,40 +211,18 @@ export function catalogServiceBuilder( | |||||
const eservice: catalogApi.EService = | ||||||
await catalogProcessClient.getEServiceById({ | ||||||
params: { | ||||||
eServiceId, | ||||||
eServiceId: eserviceId, | ||||||
}, | ||||||
headers, | ||||||
}); | ||||||
|
||||||
if (eservice.producerId !== requesterId) { | ||||||
throw invalidEServiceRequester( | ||||||
unsafeBrandId<EServiceId>(eServiceId), | ||||||
unsafeBrandId<TenantId>(requesterId) | ||||||
); | ||||||
throw invalidEServiceRequester(eserviceId, requesterId); | ||||||
} | ||||||
|
||||||
const descriptor = eservice.descriptors.find( | ||||||
(e) => e.id === descriptorId | ||||||
); | ||||||
|
||||||
if (!descriptor) { | ||||||
throw eserviceDescriptorNotFound( | ||||||
unsafeBrandId<EServiceId>(eServiceId), | ||||||
unsafeBrandId<DescriptorId>(descriptorId) | ||||||
); | ||||||
} | ||||||
const descriptor = getEserviceDesciptor(eservice, descriptorId); | ||||||
|
||||||
const descriptorAttributeIds: string[] = [ | ||||||
...descriptor.attributes.certified.flatMap((atts) => | ||||||
atts.map((att) => att.id) | ||||||
), | ||||||
...descriptor.attributes.declared.flatMap((atts) => | ||||||
atts.map((att) => att.id) | ||||||
), | ||||||
...descriptor.attributes.verified.flatMap((atts) => | ||||||
atts.map((att) => att.id) | ||||||
), | ||||||
]; | ||||||
const descriptorAttributeIds = getAttributeIds(descriptor); | ||||||
|
||||||
const attributes = await getBulkAttributes( | ||||||
attributeProcessClient, | ||||||
|
@@ -248,7 +251,7 @@ export function catalogServiceBuilder( | |||||
], | ||||||
}; | ||||||
|
||||||
const requesterTenant = await tenantProcessClient.getTenant({ | ||||||
const requesterTenant = await tenantProcessClient.tenant.getTenant({ | ||||||
headers, | ||||||
params: { | ||||||
id: requesterId, | ||||||
|
@@ -261,8 +264,8 @@ export function catalogServiceBuilder( | |||||
description: descriptor.description, | ||||||
interface: | ||||||
descriptor.interface && | ||||||
toBffCatalogApiDescriptorInterface(descriptor.interface), | ||||||
docs: descriptor.docs.map(toBffCatalogApiDescriptorInterface), | ||||||
toBffCatalogApiDescriptorDoc(descriptor.interface), | ||||||
docs: descriptor.docs.map(toBffCatalogApiDescriptorDoc), | ||||||
state: descriptor.state, | ||||||
audience: descriptor.audience, | ||||||
voucherLifespan: descriptor.voucherLifespan, | ||||||
|
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.
Could you reuse type from bffApi.RiskAnalysisForm?