diff --git a/src/controllers/audit.controller.js b/src/controllers/audit.controller.js index a69316a2..afc58b4d 100644 --- a/src/controllers/audit.controller.js +++ b/src/controllers/audit.controller.js @@ -1,10 +1,24 @@ import { Audit } from '../models'; +import { + paginationParams, + optionallyPaginatedResponse, +} from '../utils/helpers'; + export const findAll = async (req, res) => { try { - const { orgUid } = req.query; - const auditResults = await Audit.findAll({ where: { orgUid } }); - return res.json(auditResults); + let { page, limit, orgUid } = req.query; + + let pagination = paginationParams(page, limit); + + const auditResults = await Audit.findAndCountAll({ + where: { orgUid }, + ...pagination, + }); + + console.log(auditResults); + + return res.json(optionallyPaginatedResponse(auditResults, page, limit)); } catch (error) { res.status(400).json({ message: 'Can not retreive issuances', diff --git a/src/validations/audit.validations.js b/src/validations/audit.validations.js index 7170293e..25c68d32 100644 --- a/src/validations/audit.validations.js +++ b/src/validations/audit.validations.js @@ -1,5 +1,10 @@ import Joi from 'joi'; -export const auditGetSchema = Joi.object().keys({ - orgUid: Joi.string().required(), -}); +export const auditGetSchema = Joi.object() + .keys({ + page: Joi.number(), + limit: Joi.number(), + orgUid: Joi.string(), + }) + .with('page', 'limit') + .with('limit', 'page');