mirror of
https://github.com/shuaiplus/nodewarden.git
synced 2026-06-20 13:00:39 +00:00
feat: remove handleUpdateProfile function to streamline account management
This commit is contained in:
@@ -240,42 +240,6 @@ export async function handleGetProfile(request: Request, env: Env, userId: strin
|
||||
return jsonResponse(toProfile(user, env));
|
||||
}
|
||||
|
||||
// PUT /api/accounts/profile
|
||||
export async function handleUpdateProfile(request: Request, env: Env, userId: string): Promise<Response> {
|
||||
const storage = new StorageService(env.DB);
|
||||
const user = await storage.getUserById(userId);
|
||||
if (!user) return errorResponse('User not found', 404);
|
||||
|
||||
let body: { name?: string; email?: string };
|
||||
try {
|
||||
body = await request.json();
|
||||
} catch {
|
||||
return errorResponse('Invalid JSON', 400);
|
||||
}
|
||||
|
||||
if (typeof body.name === 'string') {
|
||||
user.name = body.name.trim() || user.name;
|
||||
}
|
||||
if (typeof body.email === 'string') {
|
||||
const normalized = body.email.trim().toLowerCase();
|
||||
if (!normalized) return errorResponse('Email is required', 400);
|
||||
user.email = normalized;
|
||||
}
|
||||
user.updatedAt = new Date().toISOString();
|
||||
|
||||
try {
|
||||
await storage.saveUser(user);
|
||||
} catch (error) {
|
||||
const msg = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
|
||||
if (msg.includes('unique') || msg.includes('constraint')) {
|
||||
return errorResponse('Email already registered', 409);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
return handleGetProfile(request, env, userId);
|
||||
}
|
||||
|
||||
// POST /api/accounts/keys
|
||||
export async function handleSetKeys(request: Request, env: Env, userId: string): Promise<Response> {
|
||||
const storage = new StorageService(env.DB);
|
||||
|
||||
Reference in New Issue
Block a user