diff --git a/CHANGELOG.md b/CHANGELOG.md index d22deb0c..9a4450c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added + +Adds a new `getAccount` query to retrieve account information. It includes fields such as `id`, `name`, `accountName`, `tradingName`, and `isActive`. This query is implemented in both the GraphQL schema and the LMClient class. + ## [0.55.0] - 2024-08-22 ### Added diff --git a/graphql/schema.graphql b/graphql/schema.graphql index 84a1e3c4..0451e69a 100644 --- a/graphql/schema.graphql +++ b/graphql/schema.graphql @@ -113,6 +113,15 @@ type Query { getSellersPaginated(page: Int, pageSize: Int): GetSellersPaginatedResponse @validateAdminUserAccess @cacheControl(scope: PRIVATE) + getAccount: Account @validateAdminUserAccess @cacheControl(scope: PRIVATE) +} + +type Account { + id: ID + name: String + accountName: String + tradingName: String + isActive: Boolean } type PaginationResponse { diff --git a/node/clients/LMClient.ts b/node/clients/LMClient.ts index b8bebc4a..65dcb3c2 100644 --- a/node/clients/LMClient.ts +++ b/node/clients/LMClient.ts @@ -24,7 +24,59 @@ export default class LMClient extends ExternalClient { }) } + public getAccount = async () => { + return this.get(`/api/license-manager/account`).then( + (res) => { + return res + } + ) + } + protected get = (url: string) => { return this.http.get(url) } } + +interface GetAccountResponse { + isActive: boolean + id: string + name: string + accountName: string + lv: unknown + isOperating: boolean + defaultUrl: unknown + district: unknown + country: unknown + complement: unknown + compunknownName: string + cnpj: string + haveParentAccount: boolean + parentAccountId: unknown + parentAccountName: unknown + city: unknown + address: unknown + logo: unknown + hasLogo: boolean + number: unknown + postalCode: unknown + state: unknown + telephone: string + tradingName: string + licenses: unknown[] + sponsor: { + name: string + email: string + phone: string + } + contact: { + name: string + email: string + phone: string + } + operationDate: unknown + inactivationDate: unknown + creationDate: string + hosts: unknown[] + sites: unknown[] + appKeys: unknown[] +} diff --git a/node/resolvers/Queries/Settings.ts b/node/resolvers/Queries/Settings.ts index c1c86254..e72dd34e 100644 --- a/node/resolvers/Queries/Settings.ts +++ b/node/resolvers/Queries/Settings.ts @@ -76,6 +76,21 @@ const B2BSettings = { } } }, + getAccount: async (_: void, __: void, ctx: Context) => { + const { + clients: { lm }, + } = ctx + + return lm.getAccount().catch((e) => { + if (e.message) { + throw new GraphQLError(e.message) + } else if (e.response?.data?.message) { + throw new GraphQLError(e.response.data.message) + } else { + throw new GraphQLError(e) + } + }) + }, } export default B2BSettings