File size: 1,483 Bytes
f8ff91f
7515f43
fdaf912
 
 
2483bce
fdaf912
 
 
 
 
 
 
 
b7917d5
 
2483bce
b6915e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f8ff91f
 
fdaf912
b7917d5
 
 
fdaf912
 
f8ff91f
fdaf912
b7917d5
fdaf912
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
export const revalidate = 10;

import { createClient } from '@supabase/supabase-js';
import { NextRequest, NextResponse } from "next/server";

// GET request to retrieve the collections requests data from the database
export async function GET(request: NextRequest) {
    // Create a new Supabase client
    const supabase = createClient(
        process.env.SUPABASE_URL ?? '',
        process.env.SUPABASE_SERVICE_ROLE_KEY ?? '',
        { db: { schema: 'public' } },
    );

    // Retrieve the collections requests data from the database
    const { data: collectionsReq, error: collErr } = await supabase
        .from('collections_requests')
        .select(`
            collection_id,
            is_make_public,
            is_pending,
            is_approved,
            created_at,
            updated_at,
            collections (
                id,
                display_name,
                description,
                is_public,
                users (
                    id,
                    name,
                    email
                )
            )
        `)
        .eq('is_pending', true)
        .limit(1000);

    if (collErr) {
        console.error('Error fetching collection request data from database:', collErr.message);
        return NextResponse.json({ error: collErr.message }, { status: 500 });
    }

    // console.log('New Collections Request:', collectionsReq);

    return NextResponse.json({ collectionsReq: collectionsReq });
}