mirror of
https://codeberg.org/MarkusThielker/next-ory.git
synced 2025-04-12 12:38:43 +00:00
NORY-45: prepare custom query for pagination
This commit is contained in:
parent
5e01a7f50f
commit
2d2c021446
2 changed files with 27 additions and 7 deletions
dashboard/src
|
@ -16,9 +16,9 @@ export default async function UserPage(
|
||||||
const page = params.page ? Number(params.page) : 1;
|
const page = params.page ? Number(params.page) : 1;
|
||||||
const query = params.query ? params.query as string : '';
|
const query = params.query ? params.query as string : '';
|
||||||
|
|
||||||
let pageSize = 250;
|
let pageSize = 50;
|
||||||
|
|
||||||
const initialData = await queryIdentities({ page, pageSize, query });
|
const { data, pageCount } = await queryIdentities({ page, pageSize, query });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
|
@ -34,7 +34,7 @@ export default async function UserPage(
|
||||||
queryParamKey="query"
|
queryParamKey="query"
|
||||||
placeholder="Search for identifiers (Email, Username...)"/>
|
placeholder="Search for identifiers (Email, Username...)"/>
|
||||||
<IdentityDataTable
|
<IdentityDataTable
|
||||||
data={initialData}
|
data={data}
|
||||||
page={page}
|
page={page}
|
||||||
query={query}/>
|
query={query}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -15,14 +15,14 @@ import { eq, ilike, or, sql } from 'drizzle-orm';
|
||||||
|
|
||||||
interface QueryIdentitiesProps {
|
interface QueryIdentitiesProps {
|
||||||
page: number,
|
page: number,
|
||||||
pageSize?: number,
|
pageSize: number,
|
||||||
query?: string,
|
query?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function queryIdentities({ page, pageSize, query }: QueryIdentitiesProps) {
|
export async function queryIdentities({ page, pageSize, query }: QueryIdentitiesProps) {
|
||||||
|
|
||||||
const db = await getDB();
|
const db = await getDB();
|
||||||
const results = await db.select()
|
const result = await db.select()
|
||||||
.from(identities)
|
.from(identities)
|
||||||
.leftJoin(identityVerifiableAddresses, eq(identities.id, identityVerifiableAddresses.identityId))
|
.leftJoin(identityVerifiableAddresses, eq(identities.id, identityVerifiableAddresses.identityId))
|
||||||
.leftJoin(identityRecoveryAddresses, eq(identities.id, identityRecoveryAddresses.identityId))
|
.leftJoin(identityRecoveryAddresses, eq(identities.id, identityRecoveryAddresses.identityId))
|
||||||
|
@ -30,14 +30,34 @@ export async function queryIdentities({ page, pageSize, query }: QueryIdentities
|
||||||
sql`${identities.traits}::text ILIKE
|
sql`${identities.traits}::text ILIKE
|
||||||
${`%${query}%`}`,
|
${`%${query}%`}`,
|
||||||
ilike(identityVerifiableAddresses.value, `%${query}%`),
|
ilike(identityVerifiableAddresses.value, `%${query}%`),
|
||||||
));
|
))
|
||||||
|
.limit(pageSize)
|
||||||
|
.offset((page - 1) * pageSize);
|
||||||
|
|
||||||
return results.map((it) => {
|
const resultCount = await db.$count(
|
||||||
|
db.select()
|
||||||
|
.from(identities)
|
||||||
|
.leftJoin(identityVerifiableAddresses, eq(identities.id, identityVerifiableAddresses.identityId))
|
||||||
|
.leftJoin(identityRecoveryAddresses, eq(identities.id, identityRecoveryAddresses.identityId))
|
||||||
|
.where(or(
|
||||||
|
sql`${identities.traits}::text ILIKE
|
||||||
|
${`%${query}%`}`,
|
||||||
|
ilike(identityVerifiableAddresses.value, `%${query}%`),
|
||||||
|
))
|
||||||
|
.as('subquery'),
|
||||||
|
);
|
||||||
|
|
||||||
|
const resultTyped = result.map((it) => {
|
||||||
const typed = it.identities as unknown as Identity;
|
const typed = it.identities as unknown as Identity;
|
||||||
typed.verifiable_addresses = [it.identity_verifiable_addresses] as unknown as VerifiableIdentityAddress[];
|
typed.verifiable_addresses = [it.identity_verifiable_addresses] as unknown as VerifiableIdentityAddress[];
|
||||||
typed.recovery_addresses = [it.identity_verifiable_addresses] as unknown as RecoveryIdentityAddress[];
|
typed.recovery_addresses = [it.identity_verifiable_addresses] as unknown as RecoveryIdentityAddress[];
|
||||||
return typed;
|
return typed;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: resultTyped,
|
||||||
|
pageCount: Math.ceil(resultCount / pageSize),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue