enhancment complete with phase 10

This commit is contained in:
dimitar committed 2026-03-10 05:37:22 +01:00
1 parent 2c4927478a
commit 6adb541967
44 files changed
+7820 -845

No files matched your search

+21 -13
View File
@@ -1,24 +1,28 @@
import { NextRequest, NextResponse } from "next/server";
import { getDatabase } from "../../../../lib/database/index";
import log from "@/lib/logger";
import { fitnessProfileSchema } from "@/lib/validation/schemas";
import {
validateRequestBody,
validationErrorResponse,
} from "@/lib/validation/helpers";
export async function POST(request: NextRequest) {
try {
const db = await getDatabase();
const profileData = await request.json();
if (
!profileData.userId ||
!profileData.height ||
!profileData.weight ||
!profileData.age
) {
return NextResponse.json(
{ error: "Missing required fields" },
{ status: 400 },
);
// Validate request body
const validation = await validateRequestBody(request, fitnessProfileSchema);
if (!validation.success) {
log.warn("Fitness profile validation failed", {
errors: validation.errors,
});
return validationErrorResponse(validation.errors);
}
const profileData = validation.data;
// Check if user exists
const user = await db.getUserById(profileData.userId);
if (!user) {
@@ -32,9 +36,13 @@ export async function POST(request: NextRequest) {
let profile;
if (existingProfile) {
profile = await db.updateFitnessProfile(profileData.userId, profileData);
// Update - omit userId from update data
const { userId, ...updateData } = profileData;
profile = await db.updateFitnessProfile(userId, updateData as any);
} else {
profile = await db.createFitnessProfile(profileData);
// Create - omit userId since the function signature expects it separately
const { userId, ...createData } = profileData;
profile = await db.createFitnessProfile({ userId, ...createData } as any);
}
return NextResponse.json(