Skip to content

Commit

Permalink
Add total-count in response header.
Browse files Browse the repository at this point in the history
  • Loading branch information
elszczepano committed Mar 25, 2019
1 parent 45de675 commit 834afd0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/controllers/errorTicketController.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import ErrorTicket from '../models/ErrorTicket';

export default {
getAll(req, res) {
async getAll(req, res) {
const offset = parseInt(req.query.offset) || 0;
const perPage = parseInt(req.query.perPage) || 10;
const count = await ErrorTicket.estimatedDocumentCount();
return ErrorTicket.find({})
.populate({
path: 'user',
Expand All @@ -15,6 +16,7 @@ export default {
success: false,
message: 'Error tickets not found.'
});
res.append('total-count', count);
res.status(200).json({
success: true,
data: item
Expand Down
4 changes: 3 additions & 1 deletion src/controllers/matchController.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Match from '../models/Match';

export default {
getAll(req, res) {
async getAll(req, res) {
const offset = parseInt(req.query.offset) || 0;
const perPage = parseInt(req.query.perPage) || 100;
const count = await Match.estimatedDocumentCount();
return Match.find({})
.populate({
path: 'user1',
Expand All @@ -19,6 +20,7 @@ export default {
success: false,
message: 'Matches not found.'
});
res.append('total-count', count);
res.status(200).json({
success: true,
data: item
Expand Down
6 changes: 4 additions & 2 deletions src/controllers/messageController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import Message from '../models/Message';
import Match from '../models/Match';

export default {
getAll(req, res) {
async getAll(req, res) {
const offset = parseInt(req.query.offset) || 0;
const perPage = parseInt(req.query.perPage) || 100;
const count = await Message.estimatedDocumentCount();
return Message.find({})
.populate({
path: 'recipient',
Expand All @@ -23,7 +24,8 @@ export default {
success: false,
message: 'Messages not found.'
});
return res.status(200).json({
res.append('total-count', count);
res.status(200).json({
success: true,
data: item
});
Expand Down
4 changes: 3 additions & 1 deletion src/controllers/pendingMatchController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import PendingMatch from '../models/PendingMatch';
import Match from '../models/Match';

export default {
getAll(req, res) {
async getAll(req, res) {
const offset = parseInt(req.query.offset) || 0;
const perPage = parseInt(req.query.perPage) || 10;
const count = await PendingMatch.estimatedDocumentCount();
return PendingMatch.find({}).skip(offset).limit(perPage)
.populate({
path: 'user1',
Expand All @@ -19,6 +20,7 @@ export default {
success: false,
message: 'Pending matches not found.'
});
res.append('total-count', count);
res.status(200).json({
success: true,
data: item
Expand Down
4 changes: 3 additions & 1 deletion src/controllers/privilegedUserController.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import PrivilegedUser from '../models/PrivilegedUser';

export default {
getAll(req, res) {
async getAll(req, res) {
const offset = parseInt(req.query.offset) || 0;
const perPage = parseInt(req.query.perPage) || 10;
const count = await PrivilegedUser.estimatedDocumentCount();
return PrivilegedUser.find({}).skip(offset).limit(perPage)
.populate({
path: 'user',
Expand All @@ -14,6 +15,7 @@ export default {
success: false,
message: 'Privileged users not found.'
});
res.append('total-count', count);
res.status(200).json({
success: true,
data: item
Expand Down
4 changes: 3 additions & 1 deletion src/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import User from '../models/User';
import moment from 'moment';

export default {
getAll(req, res) {
async getAll(req, res) {
const offset = parseInt(req.query.offset) || 0;
const perPage = parseInt(req.query.perPage) || 3;
const count = await User.estimatedDocumentCount();
return User.find({}).skip(offset).limit(perPage)
.then(item => {
if(!item.length || !item) return res.status(404).json({
success: false,
message: 'Users not found.'
});
res.append('total-count', count);
res.status(200).json({
success: true,
data: item
Expand Down

0 comments on commit 834afd0

Please sign in to comment.