feat: adds pagination in organizations table

This commit is contained in:
Piyush Gupta
2025-10-07 22:59:48 +05:30
parent 464a18ccb2
commit b7b5939c16
7 changed files with 198 additions and 126 deletions
+22
View File
@@ -138,6 +138,27 @@ export const orgDALFactory = (db: TDbClient) => {
}
};
const countOrganizationsByFilter = async ({ searchTerm }: { searchTerm: string }) => {
interface CountResult {
count: string;
}
try {
const count = await db
.replicaNode()(TableName.Organization)
.where((qb) => {
if (searchTerm) {
void qb.whereILike(`${TableName.Organization}.name`, `%${searchTerm}%`);
}
})
.count("*")
.first();
return parseInt((count as unknown as CountResult).count || "0", 10);
} catch (error) {
throw new DatabaseError({ error, name: "Count organizations by filter" });
}
};
const findOrgById = async (orgId: string) => {
try {
const org = (await db
@@ -670,6 +691,7 @@ export const orgDALFactory = (db: TDbClient) => {
findOrgBySlug,
findAllOrgsByUserId,
findOrganizationsByFilter,
countOrganizationsByFilter,
ghostUserExists,
findOrgMembersByUsername,
findOrgMembersByRole,