Skip to content

Commit

Permalink
fix some api routes
Browse files Browse the repository at this point in the history
  • Loading branch information
docimin committed Oct 26, 2023
1 parent 15af13b commit 2842f96
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 18 deletions.
1 change: 0 additions & 1 deletion app/api/account/createBadge/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export async function POST(request) {
const data = await response.json();
return NextResponse.json(data, { status: 200 });
} catch (error) {
console.error("Error in createBadge API route:", error);
return NextResponse.json(error.message, { status: 500 });
}
}
4 changes: 2 additions & 2 deletions app/api/user/createUser/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export async function POST(request) {
}

const data = await response.json();
return NextResponse.json(data);
return NextResponse.json(data, { status: 200 });
} catch (error) {
return NextResponse.error(500, error.message);
return NextResponse.json(error.message, { status: 500 });
}
}
4 changes: 2 additions & 2 deletions app/api/user/createUserData/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export async function POST(request) {
}

const data = await response.json();
return NextResponse.json(data);
return NextResponse.json(data, { status: 200 });
} catch (error) {
return NextResponse.error(500, error.message);
return NextResponse.json(error.message, { status: 500 });
}
}
6 changes: 3 additions & 3 deletions app/api/user/editUserData/[uniqueId]/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export async function PUT(request) {
// Assume the last segment of the URL is the user ID
const userId = request.url.split("/").pop();

const requestBody = await request.json();
const requestData = await request.arrayBuffer();

if (!userId) {
throw new Error("User ID is required");
Expand All @@ -20,9 +20,9 @@ export async function PUT(request) {
method: "PUT",
headers: {
Authorization: `Bearer ${process.env.DOMAIN_API_KEY}`,
"Content-Type": "application/json",
"Content-Type": request.headers.get("Content-Type") || "multipart/form-data",
},
body: requestBody,
body: requestData,
});

if (!response.ok) {
Expand Down
12 changes: 3 additions & 9 deletions app/api/user/getUserSelf/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,14 @@ export async function GET() {
});

if (response.status === 403) {
return NextResponse.json(
{ error: "Unauthorized" },
{ status: 403 }
); } else if (!response.ok) {
return NextResponse.json({ error: "Unauthorized" }, { status: 403 });
} else if (!response.ok) {
throw new Error("Failed to fetch data");
}

const data = await response.json();
return NextResponse.json(data, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json(
{ error: "Internal Server Error" },
{ status: 500 }
);
return NextResponse.json(error.message, { status: 500 });
}
}
1 change: 1 addition & 0 deletions components/account/accountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default function AccountPage() {

if (userResponseUpdate.status === 200) {
alert("User data updated successfully");
window.location.reload();
} else if (userResponseUpdate.status === 400) {
alert("Username needs to be at least 3 characters long");
}
Expand Down
2 changes: 1 addition & 1 deletion components/account/frontPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default function AccountPage() {
setUserData(responseData); // Set the userData state with the response data
// Reload the window
alert("Saved!");
window.location.reload();
//window.location.reload();
} else {
// Check for the specific error structure
if (
Expand Down

0 comments on commit 2842f96

Please sign in to comment.