mirror of
https://github.com/hex248/sprint.git
synced 2026-02-07 18:23:03 +00:00
avatarURL for register and update routes
This commit is contained in:
@@ -21,7 +21,7 @@ export default async function register(req: BunRequest) {
|
||||
return new Response("invalid request body", { status: 400 });
|
||||
}
|
||||
|
||||
const { name, username, password } = body as Record<string, unknown>;
|
||||
const { name, username, password, avatarURL } = body as Record<string, unknown>;
|
||||
|
||||
if (!isNonEmptyString(name) || !isNonEmptyString(username) || !isNonEmptyString(password)) {
|
||||
return new Response("name, username, and password are required", { status: 400 });
|
||||
@@ -41,7 +41,7 @@ export default async function register(req: BunRequest) {
|
||||
}
|
||||
|
||||
const passwordHash = await hashPassword(password);
|
||||
const user = await createUser(name, username, passwordHash);
|
||||
const user = await createUser(name, username, passwordHash, avatarURL as string | undefined);
|
||||
if (!user) {
|
||||
return new Response("failed to create user", { status: 500 });
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { AuthedRequest } from "../../auth/middleware";
|
||||
import { hashPassword } from "../../auth/utils";
|
||||
import { getUserById } from "../../db/queries";
|
||||
|
||||
// /user/update?id=1&name=NewName&password=NewPassword
|
||||
// /user/update?id=1&name=NewName&password=NewPassword&avatarURL=...
|
||||
export default async function update(req: AuthedRequest) {
|
||||
const url = new URL(req.url);
|
||||
const id = url.searchParams.get("id");
|
||||
@@ -18,13 +18,14 @@ export default async function update(req: AuthedRequest) {
|
||||
|
||||
const name = url.searchParams.get("name") || undefined;
|
||||
const password = url.searchParams.get("password") || undefined;
|
||||
const avatarURL = url.searchParams.get("avatarURL") || undefined;
|
||||
let passwordHash: string | undefined;
|
||||
if (password !== undefined) {
|
||||
passwordHash = await hashPassword(password);
|
||||
}
|
||||
|
||||
const { updateById } = await import("../../db/queries/users");
|
||||
const updatedUser = await updateById(user.id, { name, passwordHash });
|
||||
const updatedUser = await updateById(user.id, { name, passwordHash, avatarURL });
|
||||
|
||||
if (!updatedUser) {
|
||||
return new Response("failed to update user", { status: 500 });
|
||||
|
||||
Reference in New Issue
Block a user