diff --git a/playwright-report/index.html b/playwright-report/index.html index 8968129..63c28bf 100644 --- a/playwright-report/index.html +++ b/playwright-report/index.html @@ -82,4 +82,4 @@ Error generating stack: `+n.message+`
- \ No newline at end of file + \ No newline at end of file diff --git a/server/prisma/test.db b/server/prisma/test.db index df7a0ba..2529006 100644 Binary files a/server/prisma/test.db and b/server/prisma/test.db differ diff --git a/server/src/controllers/auth.controller.ts b/server/src/controllers/auth.controller.ts index 0e7ab1b..280bc1f 100644 --- a/server/src/controllers/auth.controller.ts +++ b/server/src/controllers/auth.controller.ts @@ -86,11 +86,11 @@ export class AuthController { static async initializeAccount(req: any, res: Response) { try { const userId = req.user.userId; - const { language } = req.body; + const { language, birthDate, height, weight, gender } = req.body; if (!language) { return sendError(res, 'Language is required', 400); } - const user = await AuthService.initializeUser(userId, language); + const user = await AuthService.initializeUser(userId, language, { birthDate, height, weight, gender }); return sendSuccess(res, { user }); } catch (error: any) { logger.error('Error in initializeAccount', { error }); diff --git a/server/src/services/auth.service.ts b/server/src/services/auth.service.ts index bcd5fdb..d7122bd 100644 --- a/server/src/services/auth.service.ts +++ b/server/src/services/auth.service.ts @@ -153,12 +153,25 @@ export class AuthService { } } - static async initializeUser(userId: string, language: string) { - // Update profile language + static async initializeUser(userId: string, language: string, profileData: any = {}) { + // Prepare profile update data + const updateData: any = { language }; + + if (profileData.weight && !isNaN(parseFloat(profileData.weight))) updateData.weight = parseFloat(profileData.weight); + if (profileData.height && !isNaN(parseFloat(profileData.height))) updateData.height = parseFloat(profileData.height); + if (profileData.gender) updateData.gender = profileData.gender; + if (profileData.birthDate && profileData.birthDate !== '') { + const date = new Date(profileData.birthDate); + if (!isNaN(date.getTime())) { + updateData.birthDate = date; + } + } + + // Update profile language and other attributes await prisma.userProfile.upsert({ where: { userId }, - update: { language }, - create: { userId, language, weight: 70 } + update: updateData, + create: { userId, ...updateData } }); // Seed exercises in that language diff --git a/src/components/InitializeAccount.tsx b/src/components/InitializeAccount.tsx index a5f107b..956fd96 100644 --- a/src/components/InitializeAccount.tsx +++ b/src/components/InitializeAccount.tsx @@ -13,11 +13,22 @@ interface InitializeAccountProps { const InitializeAccount: React.FC = ({ onInitialized, language, onLanguageChange }) => { const [isSubmitting, setIsSubmitting] = useState(false); const [error, setError] = useState(''); + const [birthDate, setBirthDate] = useState(''); + const [height, setHeight] = useState(''); + const [weight, setWeight] = useState(''); + const [gender, setGender] = useState<'MALE' | 'FEMALE' | 'OTHER' | ''>(''); const handleInitialize = async () => { setIsSubmitting(true); setError(''); - const res = await initializeAccount(language); + + const profileData: any = {}; + if (birthDate) profileData.birthDate = birthDate; + if (height) profileData.height = parseFloat(height); + if (weight) profileData.weight = parseFloat(weight); + if (gender) profileData.gender = gender; + + const res = await initializeAccount(language, profileData); if (res.success && res.user) { onInitialized(res.user); } else { @@ -32,8 +43,8 @@ const InitializeAccount: React.FC = ({ onInitialized, la ]; return ( -
-
+
+
@@ -78,6 +89,59 @@ const InitializeAccount: React.FC = ({ onInitialized, la ))}
+
+
+
+ + setBirthDate(e.target.value)} + className="w-full p-4 rounded-2xl bg-surface-container-high border border-outline-variant/30 text-on-surface focus:border-primary focus:outline-none transition-all" + /> +
+
+
+ + setHeight(e.target.value)} + className="w-full p-4 rounded-2xl bg-surface-container-high border border-outline-variant/30 text-on-surface focus:border-primary focus:outline-none transition-all" + /> +
+
+ + setWeight(e.target.value)} + className="w-full p-4 rounded-2xl bg-surface-container-high border border-outline-variant/30 text-on-surface focus:border-primary focus:outline-none transition-all" + /> +
+
+
+ + +
+
+
+