Skip to content

Commit

Permalink
feat: paginate audit table
Browse files Browse the repository at this point in the history
  • Loading branch information
frantzarty committed Mar 29, 2022
1 parent 8a807dc commit 0a6fb7b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
20 changes: 17 additions & 3 deletions src/controllers/audit.controller.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
11 changes: 8 additions & 3 deletions src/validations/audit.validations.js
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit 0a6fb7b

Please sign in to comment.