Skip to content
Open
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
28 changes: 21 additions & 7 deletions apps/dashboard/app/api/claims/[action]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as schema from "@/lib/server/schema";
import {
fetchLiveClaimCodeFromGet,
} from "@/lib/server/claims/get-claim-code";
import { getAdminIdentityFromRequest } from "@/lib/server/admin-auth";
import {
getDonorUsageForDonor,
rankDonorCandidatesForClaim,
Expand Down Expand Up @@ -655,15 +656,11 @@ async function handleDelete(req: NextRequest) {
}

try {
const auth = await authenticateAppUser(req);
if ("response" in auth) {
return auth.response;
}

const { claimCodeId } = (await req.json()) as {
const adminIdentity = getAdminIdentityFromRequest(req);
const { userId: requestedUserId, claimCodeId } = (await req.json()) as {
userId?: string;
claimCodeId?: string;
};
const userId = auth.user.id;

if (!claimCodeId) {
return NextResponse.json(
Expand All @@ -672,6 +669,23 @@ async function handleDelete(req: NextRequest) {
);
}

let userId: string;
if (adminIdentity) {
if (!requestedUserId) {
return NextResponse.json(
{ error: "Missing userId" },
{ status: 400 }
);
}
userId = requestedUserId;
} else {
const auth = await authenticateAppUser(req);
if ("response" in auth) {
return auth.response;
}
userId = auth.user.id;
}

// Fetch the claim to verify ownership and get amount
const claim = await db
.select()
Expand Down
Loading