Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions app/api/contacts/[id]/prism-count/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { NextRequest, NextResponse } from 'next/server';
import prisma from '@/lib/prisma';
import { requireSuperAdmin } from '@/lib/auth';

export async function GET(
request: NextRequest,
context: { params: Promise<{ id: string }> }
) {
const { id } = await context.params;
try {
await requireSuperAdmin();

// Count unique prisms for this contact through payment destinations -> splits -> prisms
const prismCount = await prisma.prism.count({
where: {
splits: {
some: {
paymentDestination: {
contactId: id,
},
},
},
},
});

return NextResponse.json({ count: prismCount });
} catch (error) {
if (error instanceof Error && error.message.includes('Unauthorized')) {
return new NextResponse('Unauthorized', { status: 401 });
}
console.error('Error fetching prism count:', error);
return new NextResponse('Internal Server Error', { status: 500 });
}
}

50 changes: 50 additions & 0 deletions app/api/contacts/[id]/shared-prisms/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { NextRequest, NextResponse } from 'next/server';
import prisma from '@/lib/prisma';
import { requireSuperAdmin } from '@/lib/auth';

export async function GET(
request: NextRequest,
context: { params: Promise<{ id: string }> }
) {
const { id } = await context.params;
try {
await requireSuperAdmin();

// Get unique prisms for this contact through payment destinations -> splits -> prisms
const prisms = await prisma.prism.findMany({
where: {
splits: {
some: {
paymentDestination: {
contactId: id,
},
},
},
},
select: {
id: true,
name: true,
slug: true,
},
distinct: ['id'],
});

// For now, prisms don't have thumbnails in the schema
// When thumbnail support is added, it can be included here
const prismsWithThumbnails = prisms.map(prism => ({
id: prism.id,
name: prism.name,
slug: prism.slug,
thumbnail: null, // Will show blank thumbnail if no profile is set
}));

return NextResponse.json({ prisms: prismsWithThumbnails, count: prisms.length });
} catch (error) {
if (error instanceof Error && error.message.includes('Unauthorized')) {
return new NextResponse('Unauthorized', { status: 401 });
}
console.error('Error fetching shared prisms:', error);
return new NextResponse('Internal Server Error', { status: 500 });
}
}

Loading