Skip to content

Commit

Permalink
IMN-664 IMN-665 IMN-666 IMN-667 descriptor activate suspend update pu…
Browse files Browse the repository at this point in the history
…blish (#922)
  • Loading branch information
sandrotaje authored Sep 11, 2024
1 parent 1479d36 commit 0e45e69
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 10 deletions.
63 changes: 58 additions & 5 deletions packages/bff/src/routers/catalogRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import {
} from "pagopa-interop-models";
import { toEserviceCatalogProcessQueryParams } from "../model/api/converters/catalogClientApiConverter.js";
import { makeApiProblem } from "../model/domain/errors.js";
import { PagoPAInteropBeClients } from "../providers/clientProvider.js";
import { catalogServiceBuilder } from "../services/catalogService.js";
import { fromBffAppContext } from "../utilities/context.js";
import {
bffGetCatalogErrorMapper,
emptyErrorMapper,
} from "../utilities/errorMappers.js";
import { PagoPAInteropBeClients } from "../providers/clientProvider.js";

const catalogRouter = (
ctx: ZodiosContext,
Expand Down Expand Up @@ -189,19 +189,72 @@ const catalogRouter = (
)
.post(
"/eservices/:eServiceId/descriptors/:descriptorId/activate",
async (_req, res) => res.status(501).send()
async (req, res) => {
const ctx = fromBffAppContext(req.ctx, req.headers);
try {
await catalogService.activateDescriptor(
unsafeBrandId(req.params.eServiceId),
req.params.descriptorId,
ctx
);
return res.status(204).json().send();
} catch (error) {
const errorRes = makeApiProblem(error, emptyErrorMapper, ctx.logger);
return res.status(errorRes.status).json(errorRes).end();
}
}
)
.post(
"/eservices/:eServiceId/descriptors/:descriptorId/update",
async (_req, res) => res.status(501).send()
async (req, res) => {
const ctx = fromBffAppContext(req.ctx, req.headers);
try {
const { id } = await catalogService.updateDescriptor(
unsafeBrandId(req.params.eServiceId),
req.params.descriptorId,
req.body,
ctx
);
return res.status(200).json().send({ id });
} catch (error) {
const errorRes = makeApiProblem(error, emptyErrorMapper, ctx.logger);
return res.status(errorRes.status).json(errorRes).end();
}
}
)
.post(
"/eservices/:eServiceId/descriptors/:descriptorId/publish",
async (_req, res) => res.status(501).send()
async (req, res) => {
const ctx = fromBffAppContext(req.ctx, req.headers);
try {
await catalogService.publishDescriptor(
unsafeBrandId(req.params.eServiceId),
req.params.descriptorId,
ctx
);
return res.status(204).json().send();
} catch (error) {
const errorRes = makeApiProblem(error, emptyErrorMapper, ctx.logger);
return res.status(errorRes.status).json(errorRes).end();
}
}
)
.post(
"/eservices/:eServiceId/descriptors/:descriptorId/suspend",
async (_req, res) => res.status(501).send()
async (req, res) => {
const ctx = fromBffAppContext(req.ctx, req.headers);
try {
await catalogService.suspendDescriptor(
unsafeBrandId(req.params.eServiceId),
req.params.descriptorId,
ctx
);
return res.status(204).json().send();
} catch (error) {
const errorRes = makeApiProblem(error, emptyErrorMapper, ctx.logger);
return res.status(errorRes.status).json(errorRes).end();
}
}
)
.post(
"/eservices/:eServiceId/descriptors/:descriptorId/documents",
Expand Down
59 changes: 54 additions & 5 deletions packages/bff/src/services/catalogService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable functional/immutable-data */
import { randomUUID } from "crypto";
import { FileManager } from "pagopa-interop-commons";
import { bffApi, catalogApi, tenantApi } from "pagopa-interop-api-clients";
import {
FileManager,
WithLogger,
formatDateyyyyMMddThhmmss,
getAllFromPaginated,
Expand All @@ -15,6 +15,8 @@ import {
RiskAnalysisId,
unsafeBrandId,
} from "pagopa-interop-models";
import { CreatedResource } from "../../../api-clients/dist/bffApi.js";
import { catalogApiDescriptorState } from "../model/api/apiTypes.js";
import {
toBffCatalogApiDescriptorAttributes,
toBffCatalogApiDescriptorDoc,
Expand All @@ -23,22 +25,20 @@ import {
toBffCatalogApiProducerDescriptorEService,
toBffCatalogDescriptorEService,
} from "../model/api/converters/catalogClientApiConverter.js";

import { catalogApiDescriptorState } from "../model/api/apiTypes.js";
import {
eserviceDescriptorNotFound,
eserviceRiskNotFound,
} from "../model/domain/errors.js";
import { getLatestActiveDescriptor } from "../model/modelMappingUtils.js";
import { assertRequesterIsProducer } from "../model/validators.js";
import { BffAppContext, Headers } from "../utilities/context.js";
import { verifyAndCreateEServiceDocument } from "../utilities/eserviceDocumentUtils.js";
import {
AgreementProcessClient,
AttributeProcessClient,
CatalogProcessClient,
TenantProcessClient,
} from "../providers/clientProvider.js";
import { BffAppContext, Headers } from "../utilities/context.js";
import { verifyAndCreateEServiceDocument } from "../utilities/eserviceDocumentUtils.js";
import { getLatestAgreement } from "./agreementService.js";

export type CatalogService = ReturnType<typeof catalogServiceBuilder>;
Expand Down Expand Up @@ -603,6 +603,55 @@ export function catalogServiceBuilder(

return toBffCatalogApiEserviceRiskAnalysis(riskAnalysis);
},
activateDescriptor: async (
eServiceId: EServiceId,
descriptorId: string,
{ headers }: WithLogger<BffAppContext>
): Promise<void> =>
await catalogProcessClient.activateDescriptor(undefined, {
headers,
params: {
eServiceId,
descriptorId,
},
}),
updateDescriptor: async (
eServiceId: EServiceId,
descriptorId: string,
seed: catalogApi.UpdateEServiceDescriptorQuotasSeed,
{ headers }: WithLogger<BffAppContext>
): Promise<CreatedResource> =>
await catalogProcessClient.updateDescriptor(seed, {
headers,
params: {
eServiceId,
descriptorId,
},
}),
publishDescriptor: async (
eServiceId: EServiceId,
descriptorId: string,
{ headers }: WithLogger<BffAppContext>
): Promise<void> =>
await catalogProcessClient.publishDescriptor(undefined, {
headers,
params: {
eServiceId,
descriptorId,
},
}),
suspendDescriptor: async (
eServiceId: EServiceId,
descriptorId: string,
{ headers }: WithLogger<BffAppContext>
): Promise<void> =>
await catalogProcessClient.suspendDescriptor(undefined, {
headers,
params: {
eServiceId,
descriptorId,
},
}),
updateEServiceDocumentById: async (
eServiceId: EServiceId,
descriptorId: DescriptorId,
Expand Down

0 comments on commit 0e45e69

Please sign in to comment.