Skip to content

Commit 238f9dc

Browse files
committed
Refactor users CRUD handlers to improve pagination logic and update OpenAPI documentation. Adjusted pagination handling in crud.tsx to correctly determine the presence of a next cursor and removed unnecessary comments. Updated admin.json to reflect the removal of pagination parameters for team permission definitions, streamlining the API documentation.
1 parent fbfd13e commit 238f9dc

2 files changed

Lines changed: 6 additions & 41 deletions

File tree

apps/backend/src/app/api/latest/users/crud.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -629,13 +629,9 @@ export const usersCrudHandlers = createLazyProxy(() => createCrudHandlers(usersC
629629
},
630630
{ projectUserId: sortDirection },
631631
],
632-
// +1 to detect whether a next page exists without a separate count.
632+
// +1 because we need to know if there is a next page
633633
take: query.limit ? query.limit + 1 : undefined,
634-
// Cursor convention (matches teams/crud.tsx): the client sends the
635-
// id of the LAST row of the previous page; Prisma starts AT that id,
636-
// and `skip: 1` drops it so we don't re-emit it.
637634
...query.cursor ? {
638-
skip: 1,
639635
cursor: {
640636
tenancyId_projectUserId: {
641637
tenancyId: auth.tenancy.id,
@@ -645,13 +641,13 @@ export const usersCrudHandlers = createLazyProxy(() => createCrudHandlers(usersC
645641
} : {},
646642
});
647643

648-
const items = db.slice(0, query.limit).map((user) => userPrismaToCrud(user, auth.tenancy.config));
649-
const hasMore = query.limit != null && db.length > query.limit;
650644
return {
651-
items,
645+
// remove the last item because it's the next cursor
646+
items: db.map((user) => userPrismaToCrud(user, auth.tenancy.config)).slice(0, query.limit),
652647
is_paginated: true,
653648
pagination: {
654-
next_cursor: hasMore && items.length > 0 ? items[items.length - 1].id : null,
649+
// if result is not full length, there is no next cursor
650+
next_cursor: query.limit && db.length >= query.limit + 1 ? db[db.length - 1].projectUserId : null,
655651
},
656652
};
657653
},

docs-mintlify/openapi/admin.json

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7380,38 +7380,7 @@
73807380
"get": {
73817381
"summary": "List team permission definitions",
73827382
"description": "Query and filter the permission with team_id, user_id, and permission_id (the equivalent of listing permissions on the Stack dashboard)",
7383-
"parameters": [
7384-
{
7385-
"name": "limit",
7386-
"in": "query",
7387-
"schema": {
7388-
"type": "integer",
7389-
"description": "Maximum number of items to return (capped at 200). When set, the response is paginated via cursor."
7390-
},
7391-
"description": "Maximum number of items to return (capped at 200). When set, the response is paginated via cursor.",
7392-
"required": false
7393-
},
7394-
{
7395-
"name": "cursor",
7396-
"in": "query",
7397-
"schema": {
7398-
"type": "string",
7399-
"description": "Cursor (permission id) to start the next page from. Requires `limit` to also be set."
7400-
},
7401-
"description": "Cursor (permission id) to start the next page from. Requires `limit` to also be set.",
7402-
"required": false
7403-
},
7404-
{
7405-
"name": "query",
7406-
"in": "query",
7407-
"schema": {
7408-
"type": "string",
7409-
"description": "Free-text filter applied to permission id and description (case-insensitive)."
7410-
},
7411-
"description": "Free-text filter applied to permission id and description (case-insensitive).",
7412-
"required": false
7413-
}
7414-
],
7383+
"parameters": [],
74157384
"tags": [
74167385
"Permissions"
74177386
],

0 commit comments

Comments
 (0)