Skip to content

Commit

Permalink
IMN-604 BFF Catalog router (#665)
Browse files Browse the repository at this point in the history
Co-authored-by: Simone Camito <[email protected]>
  • Loading branch information
Viktor-K and MalpenZibo authored Jul 9, 2024
1 parent 75dcf78 commit 3aeb4df
Show file tree
Hide file tree
Showing 38 changed files with 2,954 additions and 2,076 deletions.
9 changes: 4 additions & 5 deletions packages/agreement-lifecycle/src/filters/attributesFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

import {
CertifiedTenantAttribute,
CompactTenant,
DeclaredTenantAttribute,
Tenant,
TenantId,
VerifiedTenantAttribute,
tenantAttributeType,
} from "pagopa-interop-models";
import { TenantWithOnlyAttributes } from "../models/models.js";

export const filterVerifiedAttributes = (
producerId: TenantId,
tenant: Tenant | CompactTenant
tenant: TenantWithOnlyAttributes
): VerifiedTenantAttribute[] =>
tenant.attributes.filter(
(att) =>
Expand All @@ -25,15 +24,15 @@ export const filterVerifiedAttributes = (
) as VerifiedTenantAttribute[];

export const filterCertifiedAttributes = (
tenant: Tenant | CompactTenant
tenant: TenantWithOnlyAttributes
): CertifiedTenantAttribute[] =>
tenant.attributes.filter(
(att) =>
att.type === tenantAttributeType.CERTIFIED && !att.revocationTimestamp
) as CertifiedTenantAttribute[];

export const filterDeclaredAttributes = (
tenant: Tenant | CompactTenant
tenant: TenantWithOnlyAttributes
): DeclaredTenantAttribute[] =>
tenant.attributes.filter(
(att) =>
Expand Down
1 change: 1 addition & 0 deletions packages/agreement-lifecycle/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./validator/attributesValidator.js";
export * from "./filters/attributesFilter.js";
export * from "./models/models.js";
4 changes: 4 additions & 0 deletions packages/agreement-lifecycle/src/models/models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Descriptor, Tenant } from "pagopa-interop-models";

export type DescriptorWithOnlyAttributes = Pick<Descriptor, "attributes">;
export type TenantWithOnlyAttributes = Pick<Tenant, "attributes">;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {
filterDeclaredAttributes,
filterVerifiedAttributes,
} from "../filters/attributesFilter.js";
import {
DescriptorWithOnlyAttributes,
TenantWithOnlyAttributes,
} from "../models/models.js";

const attributesSatisfied = (
descriptorAttributes: EServiceAttribute[][],
Expand All @@ -24,8 +28,8 @@ const attributesSatisfied = (
});

export const certifiedAttributesSatisfied = (
descriptor: Descriptor,
tenant: Tenant | CompactTenant
descriptor: DescriptorWithOnlyAttributes,
tenant: TenantWithOnlyAttributes
): boolean => {
const certifiedAttributes = filterCertifiedAttributes(tenant).map(
(a) => a.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@
import { AuthData, CreateEvent } from "pagopa-interop-commons";
import {
Agreement,
EService,
Tenant,
agreementState,
AgreementEvent,
AgreementEventV2,
AgreementState,
Descriptor,
genericError,
AgreementEventV2,
EService,
Tenant,
UserId,
agreementState,
genericError,
} from "pagopa-interop-models";
import { match } from "ts-pattern";
import {
agreementArchivableStates,
matchingCertifiedAttributes,
matchingDeclaredAttributes,
matchingVerifiedAttributes,
agreementArchivableStates,
} from "../model/domain/validators.js";
} from "../model/domain/agreement-validators.js";
import { UpdateAgreementSeed } from "../model/domain/models.js";
import {
toCreateEventAgreementActivated,
toCreateEventAgreementSuspendedByPlatform,
toCreateEventAgreementUnsuspendedByConsumer,
toCreateEventAgreementUnsuspendedByPlatform,
toCreateEventAgreementUnsuspendedByProducer,
} from "../model/domain/toEvent.js";
import { UpdateAgreementSeed } from "../model/domain/models.js";
import { createAgreementArchivedByUpgradeEvent } from "./agreementService.js";
import {
createStamp,
suspendedByConsumerStamp,
suspendedByProducerStamp,
} from "./agreementStampUtils.js";
import { createAgreementArchivedByUpgradeEvent } from "./agreementService.js";
import { ReadModelService } from "./readModelService.js";

export function createActivationUpdateAgreementSeed({
Expand Down
4 changes: 2 additions & 2 deletions packages/agreement-process/src/services/agreementService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { z } from "zod";
import {
AppContext,
AuthData,
Expand Down Expand Up @@ -33,7 +34,6 @@ import {
unsafeBrandId,
CompactTenant,
} from "pagopa-interop-models";
import { z } from "zod";
import { SelfcareV2Client } from "pagopa-interop-selfcare-v2-client";
import {
declaredAttributesSatisfied,
Expand Down Expand Up @@ -100,7 +100,7 @@ import {
verifyConsumerDoesNotActivatePending,
verifyCreationConflictingAgreements,
verifySubmissionConflictingAgreements,
} from "../model/domain/validators.js";
} from "../model/domain/agreement-validators.js";
import {
ApiAgreementDocumentSeed,
ApiAgreementPayload,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CreateEvent, Logger } from "pagopa-interop-commons";
import {
Agreement,
AgreementEvent,
Expand All @@ -12,7 +13,6 @@ import {
CompactTenant,
} from "pagopa-interop-models";
import { P, match } from "ts-pattern";
import { CreateEvent, Logger } from "pagopa-interop-commons";
import {
certifiedAttributesSatisfied,
declaredAttributesSatisfied,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import {
tenantMailKind,
} from "pagopa-interop-models";
import { match } from "ts-pattern";
import {
matchingCertifiedAttributes,
matchingDeclaredAttributes,
matchingVerifiedAttributes,
} from "../model/domain/agreement-validators.js";
import {
agreementNotInExpectedState,
consumerWithNotValidEmail,
} from "../model/domain/errors.js";
import { UpdateAgreementSeed } from "../model/domain/models.js";
import {
matchingCertifiedAttributes,
matchingDeclaredAttributes,
matchingVerifiedAttributes,
} from "../model/domain/validators.js";
import { ApiAgreementSubmissionPayload } from "../model/types.js";
import { createStamp } from "./agreementStampUtils.js";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ import {
AuthData,
} from "pagopa-interop-commons";
import {
WithMetadata,
Agreement,
AgreementEvent,
agreementState,
generateId,
AgreementId,
Descriptor,
EService,
Tenant,
WithMetadata,
agreementState,
generateId,
} from "pagopa-interop-models";
import {
toCreateEventAgreementArchivedByUpgrade,
toCreateEventAgreementUpgraded,
toCreateEventAgreementAdded,
} from "../model/domain/toEvent.js";
import {
matchingCertifiedAttributes,
matchingDeclaredAttributes,
matchingVerifiedAttributes,
verifyConflictingAgreements,
} from "../model/domain/validators.js";
import { createStamp } from "./agreementStampUtils.js";
} from "../model/domain/agreement-validators.js";
import {
toCreateEventAgreementAdded,
toCreateEventAgreementArchivedByUpgrade,
toCreateEventAgreementUpgraded,
} from "../model/domain/toEvent.js";
import { createAndCopyDocumentsForClonedAgreement } from "./agreementService.js";
import { createStamp } from "./agreementStampUtils.js";
import { ReadModelService } from "./readModelService.js";
import { ContractBuilder } from "./agreementContractBuilder.js";

Expand Down
52 changes: 26 additions & 26 deletions packages/agreement-process/test/activateAgreement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
/* eslint-disable sonarjs/cognitive-complexity */
/* eslint-disable functional/immutable-data */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import {
formatDateyyyyMMddHHmmss,
genericLogger,
} from "pagopa-interop-commons";
import {
decodeProtobufPayload,
getMockAgreement,
Expand All @@ -20,35 +23,37 @@ import {
randomBoolean,
} from "pagopa-interop-commons-test";
import {
formatDateyyyyMMddHHmmss,
genericLogger,
} from "pagopa-interop-commons";
import {
generateId,
AgreementId,
agreementState,
EService,
Agreement,
Descriptor,
descriptorState,
TenantId,
AgreementActivatedV2,
AgreementId,
AgreementSetMissingCertifiedAttributesByPlatformV2,
AgreementSuspendedByPlatformV2,
AgreementUnsuspendedByConsumerV2,
AgreementUnsuspendedByPlatformV2,
AgreementUnsuspendedByProducerV2,
Attribute,
CertifiedTenantAttribute,
DeclaredTenantAttribute,
VerifiedTenantAttribute,
Descriptor,
EService,
Tenant,
TenantAttribute,
fromAgreementV2,
AgreementUnsuspendedByProducerV2,
AgreementUnsuspendedByConsumerV2,
Attribute,
AgreementActivatedV2,
TenantId,
UserId,
AgreementSetMissingCertifiedAttributesByPlatformV2,
AgreementUnsuspendedByPlatformV2,
AgreementSuspendedByPlatformV2,
VerifiedTenantAttribute,
agreementState,
descriptorState,
fromAgreementV2,
generateId,
unsafeBrandId,
} from "pagopa-interop-models";
import { UserResponse } from "pagopa-interop-selfcare-v2-client";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import {
agreementActivableStates,
agreementActivationAllowedDescriptorStates,
agreementArchivableStates,
} from "../src/model/domain/agreement-validators.js";
import {
agreementActivationFailed,
agreementMissingUserInfo,
Expand All @@ -64,11 +69,6 @@ import {
tenantNotFound,
userNotFound,
} from "../src/model/domain/errors.js";
import {
agreementActivableStates,
agreementActivationAllowedDescriptorStates,
agreementArchivableStates,
} from "../src/model/domain/validators.js";
import { config } from "../src/utilities/config.js";
import {
addOneAgreement,
Expand Down
24 changes: 12 additions & 12 deletions packages/agreement-process/test/agreementConsumerDocuments.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable functional/no-let */
import { generateMock } from "@anatine/zod-mock";
import { fileManagerDeleteError, genericLogger } from "pagopa-interop-commons";
import {
decodeProtobufPayload,
getMockAgreement,
Expand All @@ -8,34 +9,33 @@ import {
} from "pagopa-interop-commons-test/index.js";
import {
Agreement,
AgreementConsumerDocumentAddedV2,
AgreementConsumerDocumentRemovedV2,
AgreementDocument,
generateId,
AgreementId,
TenantId,
AgreementDocumentId,
AgreementId,
EServiceId,
AgreementConsumerDocumentAddedV2,
TenantId,
agreementState,
AgreementConsumerDocumentRemovedV2,
generateId,
toAgreementV2,
} from "pagopa-interop-models";
import { describe, beforeEach, it, expect } from "vitest";
import { fileManagerDeleteError, genericLogger } from "pagopa-interop-commons";
import { beforeEach, describe, expect, it } from "vitest";
import { agreementConsumerDocumentChangeValidStates } from "../src/model/domain/agreement-validators.js";
import {
agreementNotFound,
operationNotAllowed,
agreementDocumentAlreadyExists,
agreementDocumentNotFound,
agreementNotFound,
documentChangeNotAllowed,
agreementDocumentAlreadyExists,
operationNotAllowed,
} from "../src/model/domain/errors.js";
import { config } from "../src/utilities/config.js";
import { agreementConsumerDocumentChangeValidStates } from "../src/model/domain/validators.js";
import {
addOneAgreement,
agreementService,
fileManager,
readLastAgreementEvent,
getMockConsumerDocument,
readLastAgreementEvent,
} from "./utils.js";

describe("agreement consumer document", () => {
Expand Down
16 changes: 8 additions & 8 deletions packages/agreement-process/test/archiveAgreement.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { fail } from "assert";
import { genericLogger } from "pagopa-interop-commons";
import {
decodeProtobufPayload,
getMockAgreement,
getRandomAuthData,
randomArrayItem,
} from "pagopa-interop-commons-test/index.js";
import {
Agreement,
AgreementArchivedByConsumerV2,
Expand All @@ -10,20 +17,13 @@ import {
generateId,
toAgreementV2,
} from "pagopa-interop-models";
import { genericLogger } from "pagopa-interop-commons";
import { describe, expect, it, vi } from "vitest";
import {
decodeProtobufPayload,
getMockAgreement,
getRandomAuthData,
randomArrayItem,
} from "pagopa-interop-commons-test/index.js";
import { agreementArchivableStates } from "../src/model/domain/agreement-validators.js";
import {
agreementNotFound,
agreementNotInExpectedState,
operationNotAllowed,
} from "../src/model/domain/errors.js";
import { agreementArchivableStates } from "../src/model/domain/validators.js";
import {
addOneAgreement,
agreementService,
Expand Down
Loading

0 comments on commit 3aeb4df

Please sign in to comment.