Skip to content

Commit

Permalink
V.0.3.1.5 🐛 Bugfix (#34)
Browse files Browse the repository at this point in the history
Fixed formatting error for join queries and multi join queries causing some queries to not function properly.
  • Loading branch information
xKhronoz authored May 20, 2024
1 parent 7515f43 commit b6915e6
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function POST(request: NextRequest) {
return NextResponse.json({ error: updatedUserCollReqErr.message }, { status: 500 });
}

// Update the user's collections data in the database, set is_public = true
// Update the user's collections data in the database, set is_public to is_make_public
console.log('is_public:', is_make_public);
const { data: updatedUserCollections, error: updatedUserCollErr } = await supabase
.from('collections')
Expand Down
20 changes: 19 additions & 1 deletion frontend/app/api/admin/collections-requests/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,25 @@ export async function GET(request: NextRequest) {
// 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 (collection_id, id, display_name, description, is_public, users (id, name, email))')
.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);

if (collErr) {
Expand Down
16 changes: 14 additions & 2 deletions frontend/app/api/admin/collections/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ export async function GET(request: NextRequest) {
// Retrieve the collections requests data from the database
const { data: collections, error: collErr } = await supabase
.from('collections')
.select('collection_id, id, display_name, description, is_public, created_at, users (id, name, email)');
.select(`
collection_id,
id,
display_name,
description,
is_public,
created_at,
users (
id,
name,
email
)
`);

if (collErr) {
console.error('Error fetching collections data from database:', collErr.message);
Expand Down Expand Up @@ -57,7 +69,7 @@ export async function PUT(request: NextRequest) {
.from('collections_requests')
.delete()
.eq('collection_id', collection_id);

if (delError) {
console.error('Error deleting collection requests data in database:', delError.message);
return NextResponse.json({ error: delError.message }, { status: 500 });
Expand Down
7 changes: 6 additions & 1 deletion frontend/app/api/admin/is-admin/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ export async function GET(request: NextRequest) {
// Ensure user is an admin
const { data: userData, error: userError } = await supabase
.from('users')
.select('id, admins (id)')
.select(`
id,
admins (
id
)
`)
.eq('id', userId)
.single();

Expand Down
9 changes: 8 additions & 1 deletion frontend/app/api/admin/users/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ export async function GET(request: NextRequest) {

const { data: usersData, error: usersError } = await supabase
.from('users')
.select('id, name, email, admins (id)');
.select(`
id,
name,
email,
admins (
id
)
`);

if (usersError) {
console.error('Error fetching users data from database:', usersError.message);
Expand Down
16 changes: 15 additions & 1 deletion frontend/app/api/user/collections-requests/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,21 @@ export async function GET(request: NextRequest) {
// Retrieve the user's collections and collections requests data via inner join from the database
const { data: userCollectionsReq, error: userCollErr } = await supabase
.from('collections')
.select('collection_id, display_name, description, is_public, created_at, collections_requests (collection_id, is_make_public, is_pending, is_approved, created_at, updated_at)')
.select(`
collection_id,
display_name,
description,
is_public,
created_at,
collections_requests (
collection_id,
is_make_public,
is_pending,
is_approved,
created_at,
updated_at
)
`)
.eq('id', userId);

if (userCollErr) {
Expand Down

0 comments on commit b6915e6

Please sign in to comment.