31 lines
src/api/profile/patchProfile.ts
Applies a partial update to a user profile record.
// PATCH /api/profile/:userId — applies a partial update to a user profile.import type { Request, Response } from "express";import { db } from "./db";export interface ProfilePatch { displayName?: string; bio?: string;}
/** * Applies a partial update to the specified user profile. * Only fields explicitly included in the request body should be updated. * Fields absent from the request must retain their current stored values.*/
export async function patchProfile( req: Request, res: Response,): Promise<void> { const { userId } = req.params; const { displayName, bio } = req.body as ProfilePatch; const profile = await db.profiles.findById(userId); if (!profile) { res.status(404).json({ error: "Profile not found" }); return;}
await db.profiles.update(userId, { displayName, bio }); res.status(200).json({ updated: true });}