This commit is contained in:
Michael Freno
2025-12-16 22:42:05 -05:00
commit 8fb748f401
81 changed files with 4378 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
import { NextRequest, NextResponse } from "next/server";
import { cookies } from "next/headers";
import { newEmailInput } from "@/types/input-types";
import { ConnectionFactory } from "@/app/utils";
export async function POST(input: NextRequest) {
const inputData = (await input.json()) as newEmailInput;
const { id, newEmail } = inputData;
const oldEmail = (await cookies()).get("emailToken");
const conn = ConnectionFactory();
const query = `UPDATE User SET email = ? WHERE id = ? AND email = ?`;
const params = [newEmail, id, oldEmail];
try {
const res = await conn.execute({ sql: query, args: params as string[] });
return NextResponse.json({ res: res }, { status: 202 });
} catch (e) {
console.log(e);
return NextResponse.json({ status: 400 });
}
}

View File

@@ -0,0 +1,35 @@
import { User } from "@/types/model-types";
import { ConnectionFactory } from "@/app/utils";
import { NextResponse } from "next/server";
export async function GET(
_: Request,
context: { params: Promise<{ id: string }> },
) {
try {
const conn = ConnectionFactory();
const userQuery = "SELECT * FROM User WHERE id =?";
const params = await context.params;
const userParams = [params.id];
const res = await conn.execute({ sql: userQuery, args: userParams });
if (res.rows[0]) {
const user = res.rows[0] as unknown as User;
if (user && user.display_name !== "user deleted")
return NextResponse.json(
{
id: user.id,
email: user.email,
emailVerified: user.email_verified,
image: user.image,
displayName: user.display_name,
provider: user.provider,
hasPassword: !!user.password_hash,
},
{ status: 202 },
);
}
return NextResponse.json({}, { status: 200 });
} catch (err) {
console.error(err);
return NextResponse.json({}, { status: 200 });
}
}

View File

@@ -0,0 +1,33 @@
import { ConnectionFactory } from "@/app/utils";
import { env } from "@/env.mjs";
import { changeImageInput } from "@/types/input-types";
import { NextRequest, NextResponse } from "next/server";
export async function GET(
_: Request,
context: { params: Promise<{ id: string }> },
) {
const conn = ConnectionFactory();
const query = "SELECT * FROM User WHERE id = ?";
const params = await context.params;
const idArr = [params.id];
const results = await conn.execute({ sql: query, args: idArr });
return NextResponse.json({ user: results.rows[0] }, { status: 200 });
}
export async function POST(
request: NextRequest,
context: { params: Promise<{ id: string }> },
) {
const inputData = (await request.json()) as changeImageInput;
const { imageURL } = inputData;
try {
const conn = ConnectionFactory();
const query = `UPDATE User SET image = ? WHERE id = ?`;
const fullURL = env.NEXT_PUBLIC_AWS_BUCKET_STRING + imageURL;
const params = [imageURL ? fullURL : null, (await context.params).id];
await conn.execute({ sql: query, args: params });
return NextResponse.json({ res: "success" }, { status: 200 });
} catch (err) {
return NextResponse.json({ res: err }, { status: 500 });
}
}

View File

@@ -0,0 +1,31 @@
import { User } from "@/types/model-types";
import { ConnectionFactory } from "@/app/utils";
import { NextResponse } from "next/server";
export async function GET(
_: Request,
context: { params: Promise<{ id: string }> },
) {
try {
const conn = ConnectionFactory();
const userQuery = "SELECT email, display_name, image FROM User WHERE id =?";
const params = await context.params;
const userParams = [params.id];
const res = await conn.execute({ sql: userQuery, args: userParams });
if (res.rows[0]) {
const user = res.rows[0] as unknown as User;
if (user && user.display_name !== "user deleted")
return NextResponse.json(
{
email: user.email,
image: user.image,
display_name: user.display_name,
},
{ status: 202 },
);
}
return NextResponse.json({}, { status: 200 });
} catch (err) {
console.error(err);
return NextResponse.json({}, { status: 200 });
}
}