Skip to content

Commit

Permalink
fix: Use null for missing accounts instead of undefined
Browse files Browse the repository at this point in the history
Signed-off-by: jay-dee7 <[email protected]>
  • Loading branch information
jay-dee7 committed Aug 6, 2024
1 parent 87f82d1 commit b4a314c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
18 changes: 10 additions & 8 deletions src/controllers/admin/organisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/api/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};

Expand Down
4 changes: 3 additions & 1 deletion src/static/swagger-admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,12 @@
"properties": {
"testnet": {
"type": "string",
"example": "cheqd1hwzvac94udsk8x4mf6htt544lev4jltkwgxp7u"
"example": "cheqd1hwzvac94udsk8x4mf6htt544lev4jltkwgxp7u",
"nullable": true
},
"mainnet": {
"type": "string",
"nullable": true,
"example": "cheqd1hwzvac94udsk8x4mf6htt544lev4jltkwgxp7u"
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/types/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};

Expand Down
4 changes: 2 additions & 2 deletions src/types/customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export type QueryCustomerResponseBody = {
name: string;
};
paymentAccount: {
[CheqdNetwork.Testnet]: string;
[CheqdNetwork.Mainnet]: string;
[CheqdNetwork.Testnet]: string | null;
[CheqdNetwork.Mainnet]: string | null;
};
};

Expand Down
2 changes: 2 additions & 0 deletions src/types/swagger-admin-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b4a314c

Please sign in to comment.