fix errors
This commit is contained in:
@@ -8,23 +8,38 @@ import type { User } from '~/server/types';
|
||||
export const POST = async (request: NextRequest) => {
|
||||
const middlewareResponse = await middleware(request);
|
||||
if (middlewareResponse) return middlewareResponse;
|
||||
|
||||
try {
|
||||
const url = new URL(request.url);
|
||||
const appleId = url.searchParams.get('appleId');
|
||||
const email = url.searchParams.get('email');
|
||||
const fullName = url.searchParams.get('fullName');
|
||||
const pushToken = url.searchParams.get('pushToken');
|
||||
if (!appleId || !email || !fullName || !pushToken)
|
||||
// Parse the request body
|
||||
const body = await request.json() as {
|
||||
appleId: string;
|
||||
email: string;
|
||||
fullName: string;
|
||||
pushToken: string;
|
||||
};
|
||||
const { appleId, email, fullName, pushToken } = body;
|
||||
|
||||
// Validate the required fields
|
||||
if (!appleId || !email || !fullName || !pushToken) {
|
||||
return NextResponse.json(
|
||||
{ message: 'Missing required parameters' }, { status: 400 }
|
||||
);
|
||||
const newUser: User | null = await createUser(appleId, email, fullName, pushToken);
|
||||
if (!newUser) {
|
||||
return NextResponse.json(
|
||||
{ message: 'Error creating user' }, { status: 500 }
|
||||
{ message: 'Missing required parameters' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Create the new user
|
||||
const newUser: User | undefined = await createUser(appleId, email, fullName, pushToken);
|
||||
|
||||
if (!newUser) {
|
||||
return NextResponse.json(
|
||||
{ message: 'Error creating user' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
// Return the new user data
|
||||
return NextResponse.json(newUser);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error creating user:', error);
|
||||
if (error instanceof Error) {
|
||||
|
@@ -12,6 +12,7 @@ export const GET = async (request: NextRequest) => {
|
||||
const url = new URL(request.url);
|
||||
const userId = Number.parseInt(url.searchParams.get('userId') ?? '');
|
||||
const searchTerm = url.searchParams.get('searchTerm');
|
||||
console.log(userId, searchTerm);
|
||||
if (!userId || !searchTerm || isNaN(userId))
|
||||
return NextResponse.json(
|
||||
{ message: 'Missing userId or searchTerm' }, { status: 400 }
|
||||
|
@@ -37,6 +37,7 @@ export const POST = async (request: NextRequest) => {
|
||||
|
||||
// Delete the old pfp file if it exists
|
||||
const oldPfpUrl = await getPfpUrl(userId);
|
||||
console.log("Old pfp url: ", oldPfpUrl);
|
||||
if (oldPfpUrl) {
|
||||
const oldFilePath = path.join(process.cwd(), 'public', oldPfpUrl);
|
||||
await fs.unlink(oldFilePath).catch((error) => {
|
||||
|
Reference in New Issue
Block a user