Skip to content

Commit

Permalink
feat: query the baseUrl when calling createOrUpdate.
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitdevos committed Jun 21, 2024
1 parent f494b9c commit 0b3bb9c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
5 changes: 2 additions & 3 deletions packages/client-node/integration/LegalOfficer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { State } from "./Utils.js";
import { LegalOfficer } from "@logion/client/dist/Types.js";
import { LegalOfficer, CreateOrUpdateLegalOfficer } from "@logion/client";
export async function backendConfig(state: State) {
const { client, requesterAccount, alice } = state;

Expand All @@ -23,8 +23,7 @@ export async function workload(state: State) {

export async function updateLegalOfficer(state: State) {
const { client, alice } = state;
const updatedAlice: LegalOfficer = {
node: alice.node,
const updatedAlice: CreateOrUpdateLegalOfficer = {
userIdentity: {
firstName: "Alice",
lastName: "updated-last-name",
Expand Down
2 changes: 1 addition & 1 deletion packages/client-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "module",
"scripts": {
"build": "yarn lint && tsc -p tsconfig.json",
"integration-test": "docker compose up -d && ./scripts/integration_test_db_setup.sh && NODE_OPTIONS=--loader=ts-node/esm jasmine --config=jasmine-integration.json ; docker compose down",
"integration-test": "docker compose up -d && ./scripts/integration_test_db_setup.sh && NODE_OPTIONS=--loader=ts-node/esm jasmine --config=jasmine-integration.json",
"lint": "yarn eslint src/**",
"test": "NODE_OPTIONS=--loader=ts-node/esm jasmine --config=jasmine.json",
"clean": "rm -rf dist"
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@logion/client",
"version": "0.46.0-2",
"version": "0.46.0-5",
"description": "logion SDK for client applications",
"main": "dist/index.js",
"packageManager": "[email protected]",
Expand Down
15 changes: 11 additions & 4 deletions packages/client/src/LegalOfficerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AxiosFactory } from "./AxiosFactory.js";
import { LegalOfficer, LegalOfficerClass, LegalOfficerPostalAddress, UserIdentity } from "./Types.js";
import { MultiSourceHttpClient, aggregateArrays, Endpoint, MultiSourceHttpClientState } from "./Http.js";
import { newBackendError } from "./Error.js";
import { requireDefined } from "./assertions.js";

interface BackendLegalOfficer {
userIdentity: UserIdentity;
Expand All @@ -17,7 +18,7 @@ interface BackendLegalOfficer {
}

export interface CreateOrUpdateLegalOfficer {
node: string;
account: ValidAccountId;
userIdentity: UserIdentity;
postalAddress: LegalOfficerPostalAddress;
additionalDetails: string;
Expand All @@ -38,7 +39,7 @@ export class LegalOfficerClient {

private readonly token: string | undefined;

private api: LogionNodeApiClass;
private readonly api: LogionNodeApiClass;

async getLegalOfficers(): Promise<LegalOfficerClass[]> {
const onchain = await this.api.polkadot.query.loAuthorityList.legalOfficerSet.entries();
Expand Down Expand Up @@ -144,9 +145,15 @@ export class LegalOfficerClient {
if(!this.authenticated) {
throw new Error("Authentication is required");
}
const legalOfficerData = await this.api.queries.getLegalOfficerData(legalOfficer.account);
try {
const backend = this.axiosFactory.buildAxiosInstance(legalOfficer.node, this.token);
await backend.put('/api/legal-officer', legalOfficer);
const endpoint = requireDefined(
legalOfficerData?.hostData?.baseUrl,
() => new Error(`Unable to find node of LLO ${ legalOfficer.account.address }`)
)
const backend = this.axiosFactory.buildAxiosInstance(endpoint, this.token);
const { userIdentity, postalAddress, additionalDetails } = legalOfficer;
await backend.put('/api/legal-officer', { userIdentity, postalAddress, additionalDetails });
} catch(e) {
throw newBackendError(e);
}
Expand Down

0 comments on commit 0b3bb9c

Please sign in to comment.