Default exercises are created in selected language. Initial GUI added

This commit is contained in:
AG
2025-12-18 22:16:39 +02:00
parent 78d4a10f33
commit abffb52af1
12 changed files with 332 additions and 117 deletions

View File

@@ -67,17 +67,13 @@ export class AuthService {
include: { profile: true }
});
// Seed default exercises
// Seed default exercises
await this.seedDefaultExercises(user.id);
const token = jwt.sign({ userId: user.id, role: user.role }, JWT_SECRET);
const { password: _, ...userSafe } = user;
return { user: userSafe, token };
}
static async seedDefaultExercises(userId: string) {
static async seedDefaultExercises(userId: string, language: string = 'en') {
try {
// Ensure env is loaded from root (in case server didn't restart)
if (!process.env.DEFAULT_EXERCISES_CSV_PATH) {
@@ -110,6 +106,8 @@ export class AuthService {
const headers = lines[0].split(',').map(h => h.trim());
const exercisesToCreate = [];
const nameColumn = language === 'ru' ? 'name_ru' : 'name';
for (let i = 1; i < lines.length; i++) {
const cols = lines[i].split(',').map(c => c.trim());
if (cols.length < headers.length) continue;
@@ -117,10 +115,12 @@ export class AuthService {
const row: any = {};
headers.forEach((h, idx) => row[h] = cols[idx]);
if (row.name && row.type) {
const exerciseName = row[nameColumn] || row['name'];
if (exerciseName && row.type) {
exercisesToCreate.push({
userId,
name: row.name,
name: exerciseName,
type: row.type,
bodyWeightPercentage: row.bodyWeightPercentage ? parseFloat(row.bodyWeightPercentage) : 0,
isUnilateral: row.isUnilateral === 'true',
@@ -153,14 +153,34 @@ export class AuthService {
}
}
static async initializeUser(userId: string, language: string) {
// Update profile language
await prisma.userProfile.upsert({
where: { userId },
update: { language },
create: { userId, language, weight: 70 }
});
// Seed exercises in that language
await this.seedDefaultExercises(userId, language);
// Mark as first login done
await prisma.user.update({
where: { id: userId },
data: { isFirstLogin: false }
});
// Return updated user
return this.getUser(userId);
}
static async changePassword(userId: string, newPassword: string) {
const hashed = await bcrypt.hash(newPassword, 10);
await prisma.user.update({
where: { id: userId },
data: {
password: hashed,
isFirstLogin: false
password: hashed
}
});
}