Skip to content

Commit

Permalink
feat: units pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeen committed Dec 23, 2021
1 parent 679c197 commit 9132891
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/controllers/units.controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict';

import { uuid as uuidv4 } from 'uuidv4';
import { Staging, UnitMock, Unit, Qualification, Vintage } from '../models';
import { paginationParams } from './helpers';

export const create = async (req, res) => {
try {
Expand All @@ -26,8 +29,10 @@ export const create = async (req, res) => {
};

export const findAll = async (req, res) => {
const { page, limit } = req.query;

if (req.query.useMock) {
res.json(UnitMock.findAll());
res.json(UnitMock.findAll({ ...paginationParams(page, limit) }));
return;
}

Expand All @@ -40,6 +45,7 @@ export const findAll = async (req, res) => {
},
Vintage,
],
...paginationParams(page, limit),
}),
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/models/units/units.mock.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import stub from './units.stub.json';

export const UnitMock = {
findAll: () => stub,
findAll: ({ limit, offset }) => stub.slice(offset * limit, (offset + 1) * limit),
findOne: (id) => {
return stub.find((record) => record.id == id);
},
Expand Down

0 comments on commit 9132891

Please sign in to comment.