diff --git a/src/app/api/relationships/checkRelationshipStatus/route.ts b/src/app/api/relationships/checkStatus/route.ts similarity index 100% rename from src/app/api/relationships/checkRelationshipStatus/route.ts rename to src/app/api/relationships/checkStatus/route.ts diff --git a/src/app/api/relationships/createRequest/route.ts b/src/app/api/relationships/createRequest/route.ts index fa454bf..5fbf977 100755 --- a/src/app/api/relationships/createRequest/route.ts +++ b/src/app/api/relationships/createRequest/route.ts @@ -9,14 +9,17 @@ export const POST = async (request: NextRequest) => { const middlewareResponse = await middleware(request); if (middlewareResponse) return middlewareResponse; try { - const url = new URL(request.url); - const userId = Number.parseInt(url.searchParams.get('userId') ?? ''); - const partnerId = Number.parseInt(url.searchParams.get('partnerId') ?? ''); - if (!userId || !partnerId || isNaN(userId) || isNaN(partnerId)) + const body = await request.json() as { + userId: number; + targetUserId: number; + }; + const { userId, targetUserId } = body; + console.log('User ID:', userId, 'Partner ID:', targetUserId); + if (!userId || !targetUserId || isNaN(userId) || isNaN(targetUserId)) return NextResponse.json( - { message: 'Missing userId or partnerId' }, { status: 400 } + { message: 'Missing userId or targetUserId' }, { status: 400 } ); - const relationshipData: RelationshipData | null = await createRelationshipRequest(userId, partnerId); + const relationshipData: RelationshipData | null = await createRelationshipRequest(userId, targetUserId); if (!relationshipData) { return NextResponse.json( { message: 'Error creating relationship request' }, { status: 500 } diff --git a/src/app/api/relationships/updateStatus/route.ts b/src/app/api/relationships/updateStatus/route.ts index 8abce18..480f3b1 100755 --- a/src/app/api/relationships/updateStatus/route.ts +++ b/src/app/api/relationships/updateStatus/route.ts @@ -9,9 +9,12 @@ export const POST = async (request: NextRequest) => { const middlewareResponse = await middleware(request); if (middlewareResponse) return middlewareResponse; try { - const url = new URL(request.url); - const userId = Number.parseInt(url.searchParams.get('userId') ?? ''); - const status = url.searchParams.get('status'); + const body = await request.json() as { + userId: number; + status: string; + }; + const { userId, status } = body; + console.log('User ID:', userId, 'Status:', status); if (!userId || !status || isNaN(userId)) return NextResponse.json( { message: 'Missing userId or status' }, { status: 400 } @@ -21,7 +24,7 @@ export const POST = async (request: NextRequest) => { await updateRelationshipStatus(userId, theStatus); if (!relationshipData || relationshipData === undefined) { return NextResponse.json( - { message: 'Error updating relationship status' }, { status: 500 } + { message: 'Error updating relationship status.' }, { status: 500 } ); } return NextResponse.json(relationshipData); diff --git a/src/server/functions.ts b/src/server/functions.ts index 008b858..fce176b 100755 --- a/src/server/functions.ts +++ b/src/server/functions.ts @@ -226,6 +226,10 @@ export const updateRelationshipStatus = async ( throw new Error('Relationship not found'); } const relationship = relationships[0] as Relationship; + // Everything above is just getting info + if (userId === relationship.requestorId) { + throw new Error('The requestor cannot accept the relationship they requested.'); + } if (status === 'accepted') { await db.update(schema.relationships) .set({ isAccepted: true })