Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#331 Improve invitation table pagination to be dynamic #337

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading