fix errors
This commit is contained in:
parent
69a6bb656e
commit
439b285126
@ -11,7 +11,9 @@
|
|||||||
"db:studio": "drizzle-kit studio",
|
"db:studio": "drizzle-kit studio",
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
"lint": "next lint",
|
"lint": "next lint",
|
||||||
"start": "next start"
|
"start": "next start",
|
||||||
|
"go": "pnpm dev",
|
||||||
|
"go:prod": "pnpm build && pnpm start"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@t3-oss/env-nextjs": "^0.10.1",
|
"@t3-oss/env-nextjs": "^0.10.1",
|
||||||
|
BIN
public/uploads/profile-pictures/2_1729280510919.jpg
Normal file
BIN
public/uploads/profile-pictures/2_1729280510919.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
@ -8,23 +8,38 @@ import type { User } from '~/server/types';
|
|||||||
export const POST = async (request: NextRequest) => {
|
export const POST = async (request: NextRequest) => {
|
||||||
const middlewareResponse = await middleware(request);
|
const middlewareResponse = await middleware(request);
|
||||||
if (middlewareResponse) return middlewareResponse;
|
if (middlewareResponse) return middlewareResponse;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const url = new URL(request.url);
|
// Parse the request body
|
||||||
const appleId = url.searchParams.get('appleId');
|
const body = await request.json() as {
|
||||||
const email = url.searchParams.get('email');
|
appleId: string;
|
||||||
const fullName = url.searchParams.get('fullName');
|
email: string;
|
||||||
const pushToken = url.searchParams.get('pushToken');
|
fullName: string;
|
||||||
if (!appleId || !email || !fullName || !pushToken)
|
pushToken: string;
|
||||||
|
};
|
||||||
|
const { appleId, email, fullName, pushToken } = body;
|
||||||
|
|
||||||
|
// Validate the required fields
|
||||||
|
if (!appleId || !email || !fullName || !pushToken) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ message: 'Missing required parameters' }, { status: 400 }
|
{ 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 }
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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);
|
return NextResponse.json(newUser);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating user:', error);
|
console.error('Error creating user:', error);
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
|
@ -12,6 +12,7 @@ export const GET = async (request: NextRequest) => {
|
|||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
const userId = Number.parseInt(url.searchParams.get('userId') ?? '');
|
const userId = Number.parseInt(url.searchParams.get('userId') ?? '');
|
||||||
const searchTerm = url.searchParams.get('searchTerm');
|
const searchTerm = url.searchParams.get('searchTerm');
|
||||||
|
console.log(userId, searchTerm);
|
||||||
if (!userId || !searchTerm || isNaN(userId))
|
if (!userId || !searchTerm || isNaN(userId))
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ message: 'Missing userId or searchTerm' }, { status: 400 }
|
{ 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
|
// Delete the old pfp file if it exists
|
||||||
const oldPfpUrl = await getPfpUrl(userId);
|
const oldPfpUrl = await getPfpUrl(userId);
|
||||||
|
console.log("Old pfp url: ", oldPfpUrl);
|
||||||
if (oldPfpUrl) {
|
if (oldPfpUrl) {
|
||||||
const oldFilePath = path.join(process.cwd(), 'public', oldPfpUrl);
|
const oldFilePath = path.join(process.cwd(), 'public', oldPfpUrl);
|
||||||
await fs.unlink(oldFilePath).catch((error) => {
|
await fs.unlink(oldFilePath).catch((error) => {
|
||||||
|
@ -91,10 +91,11 @@ export const createUser = async (
|
|||||||
fullName: string, pushToken: string
|
fullName: string, pushToken: string
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
|
console.log(appleId, email, fullName, pushToken);
|
||||||
|
|
||||||
if (!appleId || !email || !fullName || !pushToken) {
|
if (!appleId || !email || !fullName || !pushToken) {
|
||||||
throw new Error("Error: All required fields must be filled");
|
throw new Error("Error: All required fields must be filled");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if username or email is already taken
|
// Check if username or email is already taken
|
||||||
const existingUser = await db.select().from(schema.users)
|
const existingUser = await db.select().from(schema.users)
|
||||||
.where(or(eq(schema.users.appleId, appleId), eq(schema.users.email, email)));
|
.where(or(eq(schema.users.appleId, appleId), eq(schema.users.email, email)));
|
||||||
@ -102,15 +103,18 @@ export const createUser = async (
|
|||||||
if (existingUser.length > 0) {
|
if (existingUser.length > 0) {
|
||||||
throw new Error("Username or email is already in use");
|
throw new Error("Username or email is already in use");
|
||||||
}
|
}
|
||||||
|
console.log('right before we add the user');
|
||||||
|
|
||||||
const newUsers: User[] = await db.insert(schema.users).values({
|
const newUsers: User[] = await db.insert(schema.users).values({
|
||||||
appleId, email, fullName, pushToken
|
appleId, email, fullName, pushToken
|
||||||
}).returning() as User[]; // return the newly created user
|
}).returning() as User[]; // return the newly created user
|
||||||
|
|
||||||
|
const newUser: User | undefined = newUsers[0];
|
||||||
|
|
||||||
if (!newUsers.length || !newUsers[0]?.id)
|
if (!newUsers.length || !newUsers[0]?.id)
|
||||||
throw new Error("Failed to create new user");
|
throw new Error("Failed to create new user");
|
||||||
|
|
||||||
return newUsers[0];
|
return newUser;
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
@ -144,8 +148,10 @@ export const getPfpUrl = async (userId: number) => {
|
|||||||
try {
|
try {
|
||||||
const users = await db.select().from(schema.users)
|
const users = await db.select().from(schema.users)
|
||||||
.where(eq(schema.users.id, userId))
|
.where(eq(schema.users.id, userId))
|
||||||
|
console.log(users);
|
||||||
const user = users[0] as User;
|
const user = users[0] as User;
|
||||||
return (users === undefined) ? user.pfpUrl : null;
|
if (!user) return null;
|
||||||
|
return user.pfpUrl;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error getting pfp url:', error);
|
console.error('Error getting pfp url:', error);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user