p 1 and 2 compeleted
This commit is contained in:
1 parent
6adb541967
commit
3573709d99
28 files changed
+2533
-240
No files matched your search
@@ -21,7 +21,7 @@ export async function GET(request: NextRequest) {
|
||||
}
|
||||
|
||||
const profile = db
|
||||
.prepare(`SELECT * FROM fitness_profiles WHERE userId = ?`)
|
||||
.prepare(`SELECT * FROM fitness_profiles WHERE user_id = ?`)
|
||||
.get(userId);
|
||||
|
||||
if (profile) {
|
||||
@@ -78,8 +78,8 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
// Check if profile exists
|
||||
const existingProfile = db
|
||||
.prepare(`SELECT userId FROM fitness_profiles WHERE userId = ?`)
|
||||
.get(userId) as { userId: string } | undefined;
|
||||
.prepare(`SELECT user_id FROM fitness_profiles WHERE user_id = ?`)
|
||||
.get(userId) as { user_id: string } | undefined;
|
||||
|
||||
const now = new Date().toISOString();
|
||||
const fitnessGoalsJson = JSON.stringify(fitnessGoals || []);
|
||||
@@ -92,14 +92,13 @@ export async function POST(request: NextRequest) {
|
||||
weight = ?,
|
||||
age = ?,
|
||||
gender = ?,
|
||||
fitnessGoals = ?,
|
||||
activityLevel = ?,
|
||||
medicalConditions = ?,
|
||||
fitness_goals = ?,
|
||||
activity_level = ?,
|
||||
medical_conditions = ?,
|
||||
allergies = ?,
|
||||
injuries = ?,
|
||||
preferences = ?,
|
||||
updatedAt = ?
|
||||
WHERE userId = ?`,
|
||||
updated_at = ?
|
||||
WHERE user_id = ?`,
|
||||
).run(
|
||||
height,
|
||||
weight,
|
||||
@@ -110,7 +109,6 @@ export async function POST(request: NextRequest) {
|
||||
medicalConditions || null,
|
||||
allergies || null,
|
||||
injuries || null,
|
||||
preferences || null,
|
||||
now,
|
||||
userId,
|
||||
);
|
||||
@@ -121,12 +119,15 @@ export async function POST(request: NextRequest) {
|
||||
});
|
||||
} else {
|
||||
// Create new profile
|
||||
const profileId = `fp_${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
|
||||
|
||||
db.prepare(
|
||||
`INSERT INTO fitness_profiles
|
||||
(userId, height, weight, age, gender, fitnessGoals, activityLevel,
|
||||
medicalConditions, allergies, injuries, preferences, createdAt, updatedAt)
|
||||
(id, user_id, height, weight, age, gender, fitness_goals, activity_level,
|
||||
medical_conditions, allergies, injuries, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
).run(
|
||||
profileId,
|
||||
userId,
|
||||
height,
|
||||
weight,
|
||||
@@ -137,7 +138,6 @@ export async function POST(request: NextRequest) {
|
||||
medicalConditions || null,
|
||||
allergies || null,
|
||||
injuries || null,
|
||||
preferences || null,
|
||||
now,
|
||||
now,
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user