From 255a3bf640963da557218a0e714bfdc78fbbfa7b Mon Sep 17 00:00:00 2001 From: Roberto Gregnanin Date: Fri, 14 Jun 2024 12:20:03 +0200 Subject: [PATCH] Fix as suggest --- .../src/model/domain/apiConverter.ts | 27 +++++++------------ .../src/model/domain/errors.ts | 11 +------- .../authorization/protobufConverterFromV2.ts | 2 +- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/packages/authorization-process/src/model/domain/apiConverter.ts b/packages/authorization-process/src/model/domain/apiConverter.ts index 7f9be19be9..418f25dea5 100644 --- a/packages/authorization-process/src/model/domain/apiConverter.ts +++ b/packages/authorization-process/src/model/domain/apiConverter.ts @@ -14,7 +14,6 @@ import { ApiKey, ApiKeyUse, } from "./models.js"; -import { missingUserId } from "./errors.js"; export const ClientKindToApiClientKind = (kind: ClientKind): ApiClientKind => match(kind) @@ -48,23 +47,17 @@ export function clientToApiClient( createdAt: client.createdAt.toJSON(), purposes: client.purposes, kind: ClientKindToApiClientKind(client.kind), - description: client.description ? client.description : undefined, + description: client.description, ...(includeKeys ? { keys: client.keys } : {}), }; } -export const keyToApiKey = (key: Key): ApiKey => { - if (!key.userId) { - throw missingUserId(key.kid); - } else { - return { - name: key.name, - createdAt: key.createdAt.toJSON(), - kid: key.kid, - encodedPem: key.encodedPem, - algorithm: key.algorithm, - use: KeyUseToApiKeyUse(key.use), - userId: key.userId, - }; - } -}; +export const keyToApiKey = (key: Key): ApiKey => ({ + name: key.name, + createdAt: key.createdAt.toJSON(), + kid: key.kid, + encodedPem: key.encodedPem, + algorithm: key.algorithm, + use: KeyUseToApiKeyUse(key.use), + userId: key.userId, +}); diff --git a/packages/authorization-process/src/model/domain/errors.ts b/packages/authorization-process/src/model/domain/errors.ts index 2530f10b03..c98ab058c2 100644 --- a/packages/authorization-process/src/model/domain/errors.ts +++ b/packages/authorization-process/src/model/domain/errors.ts @@ -1,18 +1,9 @@ -import { ApiError, makeApiProblemBuilder } from "pagopa-interop-models"; +import { makeApiProblemBuilder } from "pagopa-interop-models"; export const errorCodes = { clientNotFound: "0001", - missingUserId: "0002", }; -export function missingUserId(kid: string): ApiError { - return new ApiError({ - detail: `Key ${kid} has not UserId`, - code: "missingUserId", - title: "Missing userId", - }); -} - export type ErrorCodes = keyof typeof errorCodes; export const makeApiProblem = makeApiProblemBuilder(errorCodes); diff --git a/packages/models/src/authorization/protobufConverterFromV2.ts b/packages/models/src/authorization/protobufConverterFromV2.ts index 674ad146bf..36671661db 100644 --- a/packages/models/src/authorization/protobufConverterFromV2.ts +++ b/packages/models/src/authorization/protobufConverterFromV2.ts @@ -38,6 +38,6 @@ export const fromClientV2 = (input: ClientV2): Client => ({ purposes: input.purposes.map((purposeId) => unsafeBrandId(purposeId)), users: input.users.map(unsafeBrandId), kind: fromClientKindV2(input.kind), - createdAt: bigIntToDate(input.createdAt!), + createdAt: bigIntToDate(input.createdAt), keys: input.keys.map(fromKeyV2), });