Skip to content

Commit

Permalink
Fix as suggest
Browse files Browse the repository at this point in the history
  • Loading branch information
rGregnanin committed Jun 14, 2024
1 parent 2ac008e commit 255a3bf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
27 changes: 10 additions & 17 deletions packages/authorization-process/src/model/domain/apiConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
ApiKey,
ApiKeyUse,
} from "./models.js";
import { missingUserId } from "./errors.js";

export const ClientKindToApiClientKind = (kind: ClientKind): ApiClientKind =>
match<ClientKind, ApiClientKind>(kind)
Expand Down Expand Up @@ -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,
});
11 changes: 1 addition & 10 deletions packages/authorization-process/src/model/domain/errors.ts
Original file line number Diff line number Diff line change
@@ -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<ErrorCodes> {
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);
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ export const fromClientV2 = (input: ClientV2): Client => ({
purposes: input.purposes.map((purposeId) => unsafeBrandId(purposeId)),
users: input.users.map(unsafeBrandId<UserId>),
kind: fromClientKindV2(input.kind),
createdAt: bigIntToDate(input.createdAt!),
createdAt: bigIntToDate(input.createdAt),
keys: input.keys.map(fromKeyV2),
});

0 comments on commit 255a3bf

Please sign in to comment.