Rename one api
This commit is contained in:
parent
bea8bb99e1
commit
cbdca78f18
@ -1,10 +1,10 @@
|
||||
"use server";
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { updateRelationshipRequest } from "~/server/functions";
|
||||
import { updateRelationshipStatus } from "~/server/functions";
|
||||
import { middleware } from "~/middleware";
|
||||
|
||||
interface UpdateRequestRequest {
|
||||
interface UpdateStatusRequest {
|
||||
relationshipId: number;
|
||||
status: 'accepted' | 'rejected';
|
||||
}
|
||||
@ -13,14 +13,14 @@ export async function POST(request: NextRequest) {
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
try {
|
||||
const { relationshipId, status } = await request.json() as UpdateRequestRequest;
|
||||
const { relationshipId, status } = await request.json() as UpdateStatusRequest;
|
||||
console.log("Received request:", { relationshipId, status });
|
||||
|
||||
if (!relationshipId || !status || isNaN(relationshipId))
|
||||
return NextResponse.json({ message: "Missing required fields" }, { status: 400 });
|
||||
|
||||
console.log("Updating relationship request:", relationshipId);
|
||||
const result = await updateRelationshipRequest(relationshipId, status);
|
||||
const result = await updateRelationshipStatus(relationshipId, status);
|
||||
|
||||
if (result.success) {
|
||||
console.log("Relationship request updated successfully");
|
@ -4,7 +4,7 @@ import React, { useState } from 'react';
|
||||
|
||||
type status = 'pending' | 'accepted' | 'rejected';
|
||||
|
||||
export default function UpdateRequestPage() {
|
||||
export default function UpdateStatusPage() {
|
||||
const [relationshipId, setRelationshipId] = useState("");
|
||||
const [status, setStatus] = useState("");
|
||||
const [result, setResult] = useState<string | null>(null);
|
||||
@ -14,7 +14,7 @@ export default function UpdateRequestPage() {
|
||||
setResult(null);
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/relationships/updateRequest', {
|
||||
const response = await fetch('/api/relationships/updateStatus', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@ -37,7 +37,7 @@ export default function UpdateRequestPage() {
|
||||
<main className="flex min-h-screen flex-col items-center justify-center
|
||||
bg-gradient-to-b from-pink-500 to-orange-400 text-white cursor-pointer">
|
||||
<div className="p-4">
|
||||
<h1 className="text-2xl mb-4">Test Send Message</h1>
|
||||
<h1 className="text-2xl mb-4">Update Relationship Status</h1>
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div>
|
||||
<label htmlFor="relationshipId" className="block">Relationship ID:</label>
|
@ -407,7 +407,7 @@ export const createRelationshipRequest = async (requestorId: number, requestedId
|
||||
}
|
||||
};
|
||||
|
||||
export const updateRelationshipRequest = async (relationshipId: number, status: 'accepted' | 'rejected') => {
|
||||
export const updateRelationshipStatus = async (relationshipId: number, status: 'accepted' | 'rejected') => {
|
||||
try {
|
||||
const relationship = await db.select().from(schema.relationships)
|
||||
.where(eq(schema.relationships.id, relationshipId));
|
||||
|
Loading…
Reference in New Issue
Block a user