From 594a011fb3ba8c69177ce1134079ca05f5d9aefc Mon Sep 17 00:00:00 2001 From: mrisqid Date: Sat, 10 Aug 2024 19:20:37 +0700 Subject: [PATCH] update: update attestation get by default by schema uid and recipient address --- apps/haus/src/app/api/attestation/route.ts | 24 +++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/apps/haus/src/app/api/attestation/route.ts b/apps/haus/src/app/api/attestation/route.ts index 9be2386..ad1950b 100644 --- a/apps/haus/src/app/api/attestation/route.ts +++ b/apps/haus/src/app/api/attestation/route.ts @@ -69,6 +69,15 @@ export async function POST(request: Request) { } } +interface WhereType { + schemaId: { + equals: string | undefined + } + recipient?: { + equals: string | undefined + } +} + export async function GET(request: NextRequest) { const searchParams = request.nextUrl.searchParams const query = ` @@ -85,19 +94,24 @@ export async function GET(request: NextRequest) { ` try { - // schema uid: ?uid=xxxxxxxxxxxxxxxxxxxxxx - const uid = searchParams.get('uid') + if (!SCHEMA_UID) return - if (!uid) { - return NextResponse.json({ message: 'Schema UID is required' }, { status: 400 }) + const where: WhereType = { + schemaId: { + equals: SCHEMA_UID, + }, } + // schema recipient: ?recipient=xxxxxxxxxxxxxxxxxxxxxx + const recipient = searchParams.get('recipient') + if (recipient) where.recipient = { equals: searchParams.get('recipient') || undefined } + const response = await axios.post( QUERY_ENDPOINT, { query, variables: { - where: { schemaId: { equals: uid } }, + where, orderBy: [{ timeCreated: 'desc' }], }, },