Initialize GUI has profile attributes
This commit is contained in:
Binary file not shown.
@@ -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 });
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user