-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IMN-745 - API Gateway - GET Agreement Purposes (#905)
- Loading branch information
1 parent
9fe58bd
commit 9910d84
Showing
12 changed files
with
174 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as purposeApi from "./generated/purposeApi.js"; | ||
import { QueryParametersByAlias } from "./utils.js"; | ||
|
||
type Api = typeof purposeApi.purposeApi.api; | ||
|
||
export type GetPurposesQueryParams = QueryParametersByAlias<Api, "getPurposes">; | ||
|
||
export * from "./generated/purposeApi.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { apiGatewayApi, purposeApi } from "pagopa-interop-api-clients"; | ||
import { assertActivePurposeVersionExists } from "../services/validators.js"; | ||
|
||
const allowedPurposeStates: apiGatewayApi.PurposeState[] = [ | ||
apiGatewayApi.PurposeState.Values.ACTIVE, | ||
apiGatewayApi.PurposeState.Values.SUSPENDED, | ||
]; | ||
|
||
export function toPurposeProcessGetPurposesQueryParams( | ||
queryParams: apiGatewayApi.GetPurposesQueryParams | ||
): Omit<purposeApi.GetPurposesQueryParams, "offset" | "limit"> { | ||
const { eserviceId, consumerId } = queryParams; | ||
|
||
return { | ||
producersIds: [], | ||
consumersIds: consumerId ? [consumerId] : [], | ||
eservicesIds: eserviceId ? [eserviceId] : [], | ||
states: allowedPurposeStates, | ||
excludeDraft: false, | ||
}; | ||
} | ||
|
||
export function toApiGatewayPurpose( | ||
purpose: purposeApi.Purpose | ||
): apiGatewayApi.Purpose { | ||
const activePurposeVersion = [...purpose.versions] | ||
.sort( | ||
(a, b) => | ||
new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime() | ||
) | ||
.find((v) => allowedPurposeStates.includes(v.state)); | ||
|
||
assertActivePurposeVersionExists(activePurposeVersion, purpose.id); | ||
|
||
return { | ||
id: purpose.id, | ||
throughput: activePurposeVersion.dailyCalls, | ||
state: activePurposeVersion.state, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters