Dashboard API explorer

/api/administrator/deleted-accounts (GET)

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

await global.api.administrator.DeletedAccounts.get(req)

Returns array

[
  {
    "accountid": "acct_1d3a70ce7dc43703",
    "object": "account",
    "appid": "tests_1656038568",
    "profileid": "prof_4819a89136d5c51c",
    "sessionKeyNumber": 1,
    "deletedAt": "2022-07-01T02:42:48.000Z",
    "lastSignedInAt": "2022-06-24T02:42:48.000Z",
    "createdAt": "2022-06-24T02:42:48.564Z",
    "updatedAt": "2022-06-24T02:42:48.595Z"
  },
  {
    "accountid": "acct_8ca24552760d5367",
    "object": "account",
    "appid": "tests_1656038568",
    "profileid": "prof_202237f155264d70",
    "sessionKeyNumber": 1,
    "deletedAt": "2022-07-01T02:42:48.000Z",
    "lastSignedInAt": "2022-06-24T02:42:48.000Z",
    "createdAt": "2022-06-24T02:42:48.525Z",
    "updatedAt": "2022-06-24T02:42:48.555Z"
  }
]

Receives

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

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

NodeJS source (view on github)

const dashboard = require('../../../../index.js')
const { Op } = require('sequelize')

module.exports = {
  get: async (req) => {
    req.query = req.query || {}
    let accountids
    if (req.query.all) {
      accountids = await dashboard.Storage.Account.findAll({
        attributes: ['accountid'],
        where: {
          deletedAt: {
            [Op.gt]: 0
          },
          appid: req.appid || global.appid
        },
        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
      accountids = await dashboard.Storage.Account.findAll({
        attributes: ['accountid'],
        where: {
          deletedAt: {
            [Op.gt]: 0
          },
          appid: req.appid || global.appid
        },
        order: [
          ['createdAt', 'DESC']
        ],
        offset,
        limit
      })
    }
    if (!accountids || !accountids.length) {
      return null
    }
    const accounts = []
    for (const accountData of accountids) {
      req.query.accountid = accountData.dataValues.accountid
      const account = await global.api.administrator.Account.get(req)
      accounts.push(account)
    }
    return accounts
  }
}

Test source (view on github)

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

describe('/api/administrator/deleted-accounts', () => {
  describe('receives', () => {
    it('optional querystring offset (integer)', async () => {
      const offset = 1
      const administrator = await TestHelper.createOwner()
      const accounts = []
      for (let i = 0, len = global.pageSize + 1; i < len; i++) {
        const user = await TestHelper.createUser()
        await TestHelper.setDeleted(user)
        accounts.unshift(user.account.accountid)
      }
      const req = TestHelper.createRequest(`/api/administrator/deleted-accounts?offset=${offset}`)
      req.account = administrator.account
      req.session = administrator.session
      const accountsNow = await req.get()
      for (let i = 0, len = global.pageSize; i < len; i++) {
        assert.strictEqual(accountsNow[i].accountid, accounts[offset + i])
      }
    })

    it('optional querystring limit (integer)', async () => {
      const limit = 1
      const administrator = await TestHelper.createOwner()
      const accounts = []
      for (let i = 0, len = limit + 1; i < len; i++) {
        const user = await TestHelper.createUser()
        await TestHelper.setDeleted(user)
        accounts.unshift(user.account.accountid)
      }
      const req = TestHelper.createRequest(`/api/administrator/deleted-accounts?limit=${limit}`)
      req.account = administrator.account
      req.session = administrator.session
      const accountsNow = await req.get()
      assert.strictEqual(accountsNow.length, limit)
    })

    it('optional querystring all (boolean)', async () => {
      const administrator = await TestHelper.createOwner()
      const accounts = []
      for (let i = 0, len = global.pageSize + 1; i < len; i++) {
        const user = await TestHelper.createUser()
        await TestHelper.setDeleted(user)
        accounts.unshift(user.account.accountid)
      }
      const req = TestHelper.createRequest('/api/administrator/deleted-accounts?all=true')
      req.account = administrator.account
      req.session = administrator.session
      const accountsNow = await req.get()
      assert.strictEqual(accountsNow.length, accounts.length)
    })
  })

  describe('returns', () => {
    it('array', async () => {
      const administrator = await TestHelper.createOwner()
      const user = await TestHelper.createUser()
      await TestHelper.setDeleted(user)
      const user2 = await TestHelper.createUser()
      await TestHelper.setDeleted(user2)
      const req = TestHelper.createRequest('/api/administrator/deleted-accounts')
      req.account = administrator.account
      req.session = administrator.session
      req.filename = __filename
      req.saveResponse = true
      const accounts = await req.get()
      assert.strictEqual(accounts.length, global.pageSize)
      assert.strictEqual(accounts[0].accountid, user2.account.accountid)
      assert.strictEqual(accounts[1].accountid, user.account.accountid)
    })
  })

  describe('redacts', () => {
    it('usernameHash', async () => {
      const administrator = await TestHelper.createOwner()
      const user = await TestHelper.createUser()
      await TestHelper.setDeleted(user)
      const req = TestHelper.createRequest('/api/administrator/deleted-accounts')
      req.account = administrator.account
      req.session = administrator.session
      const accounts = await req.get()
      assert.strictEqual(undefined, accounts[0].usernameHash)
    })

    it('passwordHash', async () => {
      const administrator = await TestHelper.createOwner()
      const user = await TestHelper.createUser()
      await TestHelper.setDeleted(user)
      const req = TestHelper.createRequest('/api/administrator/deleted-accounts')
      req.account = administrator.account
      req.session = administrator.session
      const accounts = await req.get()
      assert.strictEqual(undefined, accounts[0].passwordHash)
    })

    it('sessionKey', async () => {
      const administrator = await TestHelper.createOwner()
      const user = await TestHelper.createUser()
      await TestHelper.setDeleted(user)
      const req = TestHelper.createRequest('/api/administrator/deleted-accounts')
      req.account = administrator.account
      req.session = administrator.session
      const accounts = await req.get()
      assert.strictEqual(undefined, accounts[0].sessionKey)
    })
  })

  describe('configuration', () => {
    it('environment PAGE_SIZE', async () => {
      global.pageSize = 3
      const administrator = await TestHelper.createOwner()
      for (let i = 0, len = global.pageSize + 1; i < len; i++) {
        const user = await TestHelper.createUser()
        await TestHelper.setDeleted(user)
      }
      const req = TestHelper.createRequest('/api/administrator/deleted-accounts')
      req.account = administrator.account
      req.session = administrator.session
      const accountsNow = await req.get()
      assert.strictEqual(accountsNow.length, global.pageSize)
    })
  })
})