From b4a314cee491f71723f446c315cfadf8e280200a Mon Sep 17 00:00:00 2001 From: jay-dee7 Date: Tue, 6 Aug 2024 15:49:36 +0530 Subject: [PATCH] fix: Use null for missing accounts instead of undefined Signed-off-by: jay-dee7 --- src/controllers/admin/organisation.ts | 18 ++++++++++-------- src/controllers/api/account.ts | 4 ++-- src/static/swagger-admin.json | 4 +++- src/types/admin.ts | 4 ++-- src/types/customer.ts | 4 ++-- src/types/swagger-admin-types.ts | 2 ++ 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/controllers/admin/organisation.ts b/src/controllers/admin/organisation.ts index 923cc37b..2fa4e07e 100644 --- a/src/controllers/admin/organisation.ts +++ b/src/controllers/admin/organisation.ts @@ -81,15 +81,16 @@ export class OrganisationController { } satisfies AdminOrganisationUpdateUnsuccessfulResponseBody); } + const testnetAddress = paymentAccount.find((acc) => acc.namespace === CheqdNetwork.Testnet)?.address; + const mainnetAddress = paymentAccount.find((acc) => acc.namespace === CheqdNetwork.Mainnet)?.address; + return response.status(StatusCodes.OK).json({ name: customer.name, email: customer.email, description: customer.description, cosmosAddress: { - [CheqdNetwork.Testnet]: paymentAccount.find((acc) => acc.namespace === CheqdNetwork.Testnet) - ?.address, - [CheqdNetwork.Mainnet]: paymentAccount.find((acc) => acc.namespace === CheqdNetwork.Mainnet) - ?.address, + [CheqdNetwork.Testnet]: testnetAddress ?? null, + [CheqdNetwork.Mainnet]: mainnetAddress ?? null, }, } satisfies AdminOrganisationUpdateResponseBody); } catch (error) { @@ -134,15 +135,16 @@ export class OrganisationController { } satisfies AdminOrganisationGetUnsuccessfulResponseBody); } + const testnetAddress = paymentAccount.find((acc) => acc.namespace === CheqdNetwork.Testnet)?.address; + const mainnetAddress = paymentAccount.find((acc) => acc.namespace === CheqdNetwork.Mainnet)?.address; + return response.status(StatusCodes.OK).json({ name: customer.name, email: customer.email, description: customer.description, cosmosAddress: { - [CheqdNetwork.Testnet]: paymentAccount.find((acc) => acc.namespace === CheqdNetwork.Testnet) - ?.address, - [CheqdNetwork.Mainnet]: paymentAccount.find((acc) => acc.namespace === CheqdNetwork.Mainnet) - ?.address, + [CheqdNetwork.Testnet]: testnetAddress ?? null, + [CheqdNetwork.Mainnet]: mainnetAddress ?? null, }, } satisfies AdminOrganisationGetResponseBody); } catch (error) { diff --git a/src/controllers/api/account.ts b/src/controllers/api/account.ts index d2a2a074..7455ac43 100644 --- a/src/controllers/api/account.ts +++ b/src/controllers/api/account.ts @@ -80,8 +80,8 @@ export class AccountController { name: response.locals.customer.name, }, paymentAccount: { - mainnet: paymentAccounts.find((acc) => acc.namespace === CheqdNetwork.Mainnet)?.address ?? '', - testnet: paymentAccounts.find((acc) => acc.namespace === CheqdNetwork.Testnet)?.address ?? '', + mainnet: paymentAccounts.find((acc) => acc.namespace === CheqdNetwork.Mainnet)?.address ?? null, + testnet: paymentAccounts.find((acc) => acc.namespace === CheqdNetwork.Testnet)?.address ?? null, }, }; diff --git a/src/static/swagger-admin.json b/src/static/swagger-admin.json index 534b4899..4d6394c6 100644 --- a/src/static/swagger-admin.json +++ b/src/static/swagger-admin.json @@ -514,10 +514,12 @@ "properties": { "testnet": { "type": "string", - "example": "cheqd1hwzvac94udsk8x4mf6htt544lev4jltkwgxp7u" + "example": "cheqd1hwzvac94udsk8x4mf6htt544lev4jltkwgxp7u", + "nullable": true }, "mainnet": { "type": "string", + "nullable": true, "example": "cheqd1hwzvac94udsk8x4mf6htt544lev4jltkwgxp7u" } } diff --git a/src/types/admin.ts b/src/types/admin.ts index 3b5cf3a0..a3266fd0 100644 --- a/src/types/admin.ts +++ b/src/types/admin.ts @@ -161,8 +161,8 @@ export type AdminOrganisationResponseBody = { email?: string; description?: string; cosmosAddress?: { - [CheqdNetwork.Testnet]?: string; - [CheqdNetwork.Mainnet]?: string; + [CheqdNetwork.Testnet]: string | null; + [CheqdNetwork.Mainnet]: string | null; }; }; diff --git a/src/types/customer.ts b/src/types/customer.ts index bc6211c6..fe21fcac 100644 --- a/src/types/customer.ts +++ b/src/types/customer.ts @@ -10,8 +10,8 @@ export type QueryCustomerResponseBody = { name: string; }; paymentAccount: { - [CheqdNetwork.Testnet]: string; - [CheqdNetwork.Mainnet]: string; + [CheqdNetwork.Testnet]: string | null; + [CheqdNetwork.Mainnet]: string | null; }; }; diff --git a/src/types/swagger-admin-types.ts b/src/types/swagger-admin-types.ts index 040e746f..e78272fb 100644 --- a/src/types/swagger-admin-types.ts +++ b/src/types/swagger-admin-types.ts @@ -346,8 +346,10 @@ * testnet: * type: string * example: cheqd1hwzvac94udsk8x4mf6htt544lev4jltkwgxp7u + * nullable: true * mainnet: * type: string + * nullable: true * example: cheqd1hwzvac94udsk8x4mf6htt544lev4jltkwgxp7u * NotFoundError: * description: The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.