Fix errors
This commit is contained in:
parent
4c3688b065
commit
fc8f26dd0b
@ -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 }
|
||||
|
@ -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);
|
||||
|
@ -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 })
|
||||
|
Loading…
Reference in New Issue
Block a user