Dashboard API explorer

/api/administrator/reset-codes (PATCH)

Account information like email addresses is generated with faker-js it is not real user information.

await global.api.administrator.ResetCodes.patch(req)

Returns array

[
  {
    "codeid": "code_804b58adcd96bf6e",
    "object": "resetCode",
    "appid": "tests_1656038570",
    "accountid": "acct_49fc855bd7a99197",
    "createdAt": "2022-06-24T02:42:50.568Z",
    "updatedAt": "2022-06-24T02:42:50.568Z"
  },
  {
    "codeid": "code_786b113b4f2ef4ae",
    "object": "resetCode",
    "appid": "tests_1656038570",
    "accountid": "acct_49fc855bd7a99197",
    "createdAt": "2022-06-24T02:42:50.561Z",
    "updatedAt": "2022-06-24T02:42:50.561Z"
  },
  {
    "codeid": "code_d2dbdfdc62524cbe",
    "object": "resetCode",
    "appid": "tests_1656038570",
    "accountid": "acct_49fc855bd7a99197",
    "createdAt": "2022-06-24T02:42:50.554Z",
    "updatedAt": "2022-06-24T02:42:50.554Z"
  }
]

Receives

API routes may receive parameters from the URL and POST supporting simple and multipart:

Field Value Required Type
accountid string optional URL
all boolean optional URL
limit integer optional URL
offset integer optional URL

NodeJS source (view on github)

const dashboard = require('../../../../index.js')

module.exports = {
  get: async (req) => {
    req.query = req.query || {}
    const where = {
      appid: req.appid || global.appid
    }
    if (req.query.accountid) {
      where.accountid = req.query.accountid
    }
    let codeids
    if (req.query.all) {
      codeids = await dashboard.Storage.ResetCode.findAll({
        attributes: ['codeid'],
        where,
        order: [
          ['createdAt', 'DESC']
        ]
      })
    } else {
      const offset = req.query.offset ? parseInt(req.query.offset, 10) : 0
      const limit = req.query.limit ? parseInt(req.query.limit, 10) : global.pageSize
      codeids = await dashboard.Storage.ResetCode.findAll({
        attributes: ['codeid'],
        where,
        offset,
        limit,
        order: [
          ['createdAt', 'DESC']
        ]
      })
    }
    if (!codeids || !codeids.length) {
      return null
    }
    const resetCodes = []
    for (const codeData of codeids) {
      req.query.codeid = codeData.dataValues.codeid
      const resetCode = await global.api.administrator.ResetCode.get(req)
      resetCodes.push(resetCode)
    }
    return resetCodes
  }
}

Test source (view on github)

/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../test-helper.js')

describe('/api/administrator/reset-codes', function () {
  const cachedResponses = {}
  const cachedResetCodes = []
  const accountResetCodes = []
  before(async () => {
    await TestHelper.setupBeforeEach()
    const administrator = await TestHelper.createOwner()
    for (let i = 0, len = global.pageSize + 1; i < len; i++) {
      const user = await TestHelper.createUser()
      await TestHelper.createResetCode(user)
      cachedResetCodes.unshift(user.resetCode.codeid)
    }
    for (let i = 0, len = 3; i < len; i++) {
      await TestHelper.createResetCode(administrator)
      cachedResetCodes.unshift(administrator.resetCode.codeid)
      accountResetCodes.unshift(administrator.resetCode.codeid)
    }
    const req1 = TestHelper.createRequest('/api/administrator/reset-codes?offset=1')
    req1.account = administrator.account
    req1.session = administrator.session
    cachedResponses.offset = await req1.get()
    const req2 = TestHelper.createRequest('/api/administrator/reset-codes?limit=1')
    req2.account = administrator.account
    req2.session = administrator.session
    cachedResponses.limit = await req2.get()
    const req3 = TestHelper.createRequest('/api/administrator/reset-codes?all=true')
    req3.account = administrator.account
    req3.session = administrator.session
    cachedResponses.all = await req3.get()
    const req4 = TestHelper.createRequest(`/api/administrator/reset-codes?accountid=${administrator.account.accountid}&all=true`)
    req4.account = administrator.account
    req4.session = administrator.session
    cachedResponses.accountid = await req4.get()
    const req5 = TestHelper.createRequest('/api/administrator/reset-codes')
    req5.account = administrator.account
    req5.session = administrator.session
    req5.filename = __filename
    req5.saveResponse = true
    cachedResponses.returns = await req5.get()
    global.pageSize = 3
    cachedResponses.pageSize = await req5.get()
  })
  describe('receives', () => {
    it('optional querystring offset (integer)', async () => {
      const offset = 1
      const codesNow = cachedResponses.offset
      for (let i = 0, len = global.pageSize; i < len; i++) {
        assert.strictEqual(codesNow[i].codeid, cachedResetCodes[offset + i])
      }
    })

    it('optional querystring limit (integer)', async () => {
      const limit = 1
      const codesNow = cachedResponses.limit
      assert.strictEqual(codesNow.length, limit)
    })

    it('optional querystring all (boolean)', async () => {
      const codesNow = cachedResponses.all
      assert.strictEqual(codesNow.length, cachedResetCodes.length)
    })

    it('optional querystring accountid (string)', async () => {
      const codesNow = cachedResponses.accountid
      assert.strictEqual(codesNow.length, accountResetCodes.length)
    })
  })

  describe('returns', () => {
    it('array', async () => {
      const resetCodes = cachedResponses.returns
      assert.strictEqual(resetCodes.length, global.pageSize)
    })
  })

  describe('redacts', () => {
    it('secretCodeHash', async () => {
      const resetCodes = cachedResponses.returns
      assert.strictEqual(undefined, resetCodes[0].secretCodeHash)
    })
  })

  describe('configuration', () => {
    it('environment PAGE_SIZE', async () => {
      global.pageSize = 3
      const codesNow = cachedResponses.pageSize
      assert.strictEqual(codesNow.length, global.pageSize)
    })
  })
})