Dashboard API explorer

/api/user/delete-reset-code (DELETE)

await global.api.user.DeleteResetCode.delete(req)
Located in Dashboard API

Returns boolean

Exceptions

These exceptions are thrown (NodeJS) or returned as JSON (HTTP) if you provide incorrect data or do not meet the requirements:

Exception Circumstances
invalid querystring codeid
invalid-reset-codeid missing querystring codeid
invalid-account ineligible querystring codeid

NodeJS source (edit on github)

If you see a problem with the source submit a pull request on Github.

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

module.exports = {
  delete: async (req) => {
    if (!req.query || !req.query.codeid) {
      throw new Error('invalid-reset-codeid')
    }
    const code = await global.api.user.ResetCode.get(req)
    if (code.accountid !== req.account.accountid) {
      throw new Error('invalid-account')
    }
    const secretCodeHash = await dashboard.StorageObject.getProperty(`${req.appid}/resetCode/${req.query.codeid}`, 'secretCodeHash')
    await dashboard.Storage.delete(`${req.appid}/resetCode/${req.query.codeid}`)
    await dashboard.StorageObject.setProperty(`${req.appid}/account/${req.account.accountid}`, 'resetCodeLastDeleted', dashboard.Timestamp.now)
    await dashboard.StorageList.remove(`${req.appid}/resetCodes`, req.query.codeid)
    await dashboard.StorageList.remove(`${req.appid}/account/resetCodes/${req.account.accountid}`, req.query.codeid)
    await dashboard.Storage.delete(`${req.appid}/map/account/resetCodes/${req.account.accountid}/${secretCodeHash}`)
    req.query.accountid = req.account.accountid
    return true
  }
}

Test source (edit on github)

Tests perform real HTTP requests against a running Dashboard server.

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

describe('/api/user/delete-reset-code', () => {
  describe('exceptions', () => {
    describe('invalid-reset-codeid', () => {
      it('missing querystring codeid', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest('/api/user/delete-reset-code')
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.delete()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-reset-codeid')
      })

      it('invalid querystring codeid', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest('/api/user/delete-reset-code?codeid=invalid')
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.delete()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-reset-codeid')
      })
    })

    describe('invalid-account', () => {
      it('ineligible querystring codeid', async () => {
        const user = await TestHelper.createUser()
        const user2 = await TestHelper.createUser()
        await TestHelper.createResetCode(user2)
        const req = TestHelper.createRequest(`/api/user/delete-reset-code?codeid=${user2.resetCode.codeid}`)
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.delete()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-account')
      })
    })
  })

  describe('returns', () => {
    it('boolean', async () => {
      const user = await TestHelper.createUser()
      await TestHelper.createResetCode(user)
      const req = TestHelper.createRequest(`/api/user/delete-reset-code?codeid=${user.resetCode.codeid}`)
      req.account = user.account
      req.session = user.session
      req.filename = __filename
      req.saveResponse = true
      const deleted = await req.delete()
      assert.strictEqual(deleted, true)
    })
  })
})