diff --git a/app/controllers/simplified-account/settings/api-keys/api-keys.controller.js b/app/controllers/simplified-account/settings/api-keys/api-keys.controller.js index 8261b4b5e..67f7b73f3 100644 --- a/app/controllers/simplified-account/settings/api-keys/api-keys.controller.js +++ b/app/controllers/simplified-account/settings/api-keys/api-keys.controller.js @@ -5,7 +5,7 @@ async function get (req, res) { const activeKeys = await apiKeysService.getActiveKeys(req.account.id) return response(req, res, 'simplified-account/settings/api-keys/index', { accountType: req.account.type, - activeKeys: activeKeys, + activeKeys, createApiKeyLink: '#', showRevokedKeysLink: '#' }) diff --git a/app/controllers/simplified-account/settings/api-keys/api-keys.controller.test.js b/app/controllers/simplified-account/settings/api-keys/api-keys.controller.test.js index 2b359caaa..a666e7bbe 100644 --- a/app/controllers/simplified-account/settings/api-keys/api-keys.controller.test.js +++ b/app/controllers/simplified-account/settings/api-keys/api-keys.controller.test.js @@ -5,7 +5,7 @@ const ACCOUNT_TYPE = 'live' const SERVICE_ID = 'service-id-123abc' const mockResponse = sinon.spy() -const tokens = [{ description: 'my token', created_by: 'system generated', issued_date: '12 Dec 2024' }] +const tokens = [{ description: 'my token', createdBy: 'system generated', issuedDate: '12 Dec 2024' }] const apiKeysService = { getActiveKeys: sinon.stub().resolves(tokens) } diff --git a/app/models/Token.class.js b/app/models/Token.class.js new file mode 100644 index 000000000..638ad186d --- /dev/null +++ b/app/models/Token.class.js @@ -0,0 +1,42 @@ +class Token { + withDescription (description) { + if (description) { + this.description = description + } + return this + } + + withCreatedBy (createdBy) { + if (createdBy) { + this.createdBy = createdBy + } + return this + } + + withIssuedDate (issuedDate) { + if (issuedDate) { + this.issuedDate = issuedDate + } + return this + } + + withLastUsed (lastUsed) { + if (lastUsed) { + this.lastUsed = lastUsed + } + return this + } + + static fromJson (data) { + if (!data) { + return undefined + } + return new Token() + .withDescription(data?.description) + .withCreatedBy(data?.created_by) + .withIssuedDate(data?.issued_date) + .withLastUsed(data?.last_used) + } +} + +module.exports.Token = Token diff --git a/app/services/api-keys.service.js b/app/services/api-keys.service.js index ab8e7f12a..a7fc52917 100644 --- a/app/services/api-keys.service.js +++ b/app/services/api-keys.service.js @@ -1,15 +1,16 @@ const publicAuthClient = require('@services/clients/public-auth.client') +const { Token } = require('@models/Token.class') /** * Gets the list of active api keys for a gateway account * @param {string} gatewayAccountId - * @returns {Promise} + * @returns {[Token]} */ const getActiveKeys = async (gatewayAccountId) => { const publicAuthData = await publicAuthClient.getActiveTokensForAccount({ accountId: gatewayAccountId }) - return publicAuthData.tokens + return publicAuthData.tokens.map(tokenData => Token.fromJson(tokenData)) } module.exports = { diff --git a/app/views/simplified-account/settings/api-keys/index.njk b/app/views/simplified-account/settings/api-keys/index.njk index fdde7f9f8..89b1e2c83 100644 --- a/app/views/simplified-account/settings/api-keys/index.njk +++ b/app/views/simplified-account/settings/api-keys/index.njk @@ -65,7 +65,7 @@ text: 'Created by' }, value: { - text: key.created_by + text: key.createdBy } }, { @@ -73,7 +73,7 @@ text: 'Date created' }, value: { - text: key.issued_date + text: key.issuedDate } }, { @@ -81,7 +81,7 @@ text: 'Last used' }, value: { - text: key.last_used + text: key.lastUsed } } ]