Initialize GUI has profile attributes

This commit is contained in:
AG
2025-12-18 22:45:50 +02:00
parent abffb52af1
commit 051e1e8a32
11 changed files with 136 additions and 19 deletions

Binary file not shown.

View File

@@ -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 });

View File

@@ -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