Skip to content

Commit

Permalink
ft(invitationPagination): Improve invitation table pagination
Browse files Browse the repository at this point in the history
B# Last command done (1 command done):
  • Loading branch information
Oliviier-dev committed Oct 15, 2024
1 parent c99966a commit b82f35e
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/resolvers/TableViewInvitationResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const TableViewInvitationResolver = {
) {
try {
const { query,orgToken } = args;
const limit = args.limit ?? 5;
const limit = args.limit ?? 3;
const offset = args.offset ?? 0;

if (!query) throw new GraphQLError('No query provided')
Expand All @@ -34,12 +34,12 @@ const TableViewInvitationResolver = {
],
};

const totalInvitations = await Invitation.countDocuments(searchCriteria);

const invitations = await Invitation.find(searchCriteria)
.skip(offset)
.limit(limit)

const totalInvitations = invitations.length

return {
invitations,
totalInvitations,
Expand All @@ -58,11 +58,13 @@ const TableViewInvitationResolver = {

async getAllInvitations(_: any, args: { limit: number; offset: number;orgToken: string }) {
try {
const { orgToken } = args;
const { limit = 3, offset = 0, orgToken } = args;
if (!orgToken) throw new GraphQLError('No organization token provided');
const org = (await checkLoggedInOrganization(orgToken)).name.toLocaleLowerCase();
const invitations = await Invitation.find({orgName:org});
const totalInvitations = invitations.length;
const invitations = await Invitation.find({ orgName: org })
.skip(offset)
.limit(limit);
const totalInvitations = await Invitation.countDocuments({ orgName: org });

return {
invitations,
Expand All @@ -87,7 +89,7 @@ const TableViewInvitationResolver = {
) {
try {
const { userId } = (await checkUserLoggedIn(context))(['admin']);
const { orgToken, role, status, limit = 5, offset = 0 } = args;
const { orgToken, role, status, limit = 3, offset = 0 } = args;

if (!userId) {
throw new GraphQLError('User id not provided');
Expand Down Expand Up @@ -122,6 +124,8 @@ const TableViewInvitationResolver = {
};

let invitations: any = [];

const totalInvitations = await Invitation.countDocuments(criteria);

// OUR TRUE LOGIC
if (role && status) {
Expand Down Expand Up @@ -149,7 +153,6 @@ const TableViewInvitationResolver = {
.limit(limit);
}

const totalInvitations = invitations.length;
return {
invitations,
totalInvitations,
Expand Down

0 comments on commit b82f35e

Please sign in to comment.