Skip to content

Commit

Permalink
fix: paginated response for projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael.Taylor committed Dec 29, 2021
1 parent 4f74935 commit c79bb2b
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions src/controllers/project.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
RelatedProject,
} from '../models';

import { optionallyPaginatedResponse, paginationParams } from "./helpers";
import { optionallyPaginatedResponse, paginationParams } from './helpers';

export const create = async (req, res) => {
// When creating new projects assign a uuid to is so
Expand All @@ -32,7 +32,8 @@ export const create = async (req, res) => {
};

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

if (useMock) {
res.json(ProjectMock.findAll({ ...paginationParams(page, limit) }));
Expand All @@ -45,9 +46,17 @@ export const findAll = async (req, res) => {

if (search) {
if (dialect === 'sqlite') {
results = await Project.findAllSqliteFts(search, orgUid, paginationParams(page, limit));
results = await Project.findAllSqliteFts(
search,
orgUid,
paginationParams(page, limit),
);
} else if (dialect === 'mysql') {
results = await Project.findAllMySQLFts(search, orgUid, paginationParams(page, limit));
results = await Project.findAllMySQLFts(
search,
orgUid,
paginationParams(page, limit),
);
}
return res.json(optionallyPaginatedResponse(results, page, limit));
}
Expand All @@ -71,11 +80,16 @@ export const findAll = async (req, res) => {
};
}

return res.json(optionallyPaginatedResponse(
await Project.findAndCountAll({ ...query, ...paginationParams(page, limit) }),
page,
limit,
));
return res.json(
optionallyPaginatedResponse(
await Project.findAndCountAll({
...query,
...paginationParams(page, limit),
}),
page,
limit,
),
);
}

const query = {
Expand All @@ -88,7 +102,16 @@ export const findAll = async (req, res) => {
],
};

return res.json(await Project.findAll(query));
return res.json(
optionallyPaginatedResponse(
await Project.findAndCountAll({
...query,
...paginationParams(page, limit),
}),
page,
limit,
),
);
};

export const findOne = async (req, res) => {
Expand Down

0 comments on commit c79bb2b

Please sign in to comment.