Skip to content

Commit

Permalink
[squash]: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
oswaldquek committed Dec 18, 2024
1 parent 6f1ff23 commit 4c8ee34
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: '#'
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
42 changes: 42 additions & 0 deletions app/models/Token.class.js
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions app/services/api-keys.service.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions app/views/simplified-account/settings/api-keys/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,23 @@
text: 'Created by'
},
value: {
text: key.created_by
text: key.createdBy
}
},
{
key: {
text: 'Date created'
},
value: {
text: key.issued_date
text: key.issuedDate
}
},
{
key: {
text: 'Last used'
},
value: {
text: key.last_used
text: key.lastUsed
}
}
]
Expand Down

0 comments on commit 4c8ee34

Please sign in to comment.