Skip to content

Commit d3f4c35

Browse files
committed
✨ feat: Se solucionó que aparezcan las materias a un alumno en todas las academias
1 parent db63914 commit d3f4c35

2 files changed

Lines changed: 45 additions & 9 deletions

File tree

lib/data/repositories/auth_repository.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class AuthRepository {
101101
}
102102
}
103103

104-
// --- NEW: Bulk student registration ---
104+
// --- FIX: Make student upload additive ---
105105
Future<void> bulkRegisterStudents(List<Map<String, dynamic>> students, Function(int) onProgress) async {
106106
final batch = _db.batch();
107107
int processedCount = 0;
@@ -110,6 +110,7 @@ class AuthRepository {
110110
final querySnapshot = await _db.collection('users').where('boleta', isEqualTo: studentData['boleta']).limit(1).get();
111111

112112
if (querySnapshot.docs.isEmpty) {
113+
// Student doesn't exist, create them
113114
final newDocRef = _db.collection('users').doc();
114115
batch.set(newDocRef, {
115116
'boleta': studentData['boleta'],
@@ -121,9 +122,16 @@ class AuthRepository {
121122
'role': 'student',
122123
'created_at': FieldValue.serverTimestamp(),
123124
});
124-
processedCount++;
125-
onProgress(processedCount);
125+
} else {
126+
// Student exists, update them by adding new subjects/academies
127+
final docRef = querySnapshot.docs.first.reference;
128+
batch.update(docRef, {
129+
'academies': FieldValue.arrayUnion(studentData['academies'] ?? []),
130+
'subjects_to_take': FieldValue.arrayUnion(studentData['subjects_to_take'] ?? []),
131+
});
126132
}
133+
processedCount++;
134+
onProgress(processedCount);
127135
}
128136
await batch.commit();
129137
}

lib/features/dashboard/viewmodels/academy_home_viewmodel.dart

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ class AcademyViewModel extends ChangeNotifier {
1717
List<SubjectModel> _subjects = [];
1818
List<SubjectModel> _availableSubjectsForStudent = [];
1919

20+
// --- FIX: Add the abbreviation map here ---
21+
final Map<String, String> _subjectAbbreviationMap = {
22+
'LABORATORIO DE ELECTRICIDAD Y CONTROL': 'LAB. ELECT. Y CONTROL',
23+
'ARQUITECTURA Y ORGANIZACIÓN DE LAS COMPUTADORAS': 'ARQ. Y ORG. COMP.',
24+
'APLICACIÓN DE SISTEMAS DIGITALES': 'APLIC. SIST. DIGITALES',
25+
};
26+
2027
bool get isLoading => _isLoading;
2128
String? get errorMessage => _errorMessage;
2229
List<UserModel> get pendingStudents => _pendingStudents;
@@ -30,18 +37,25 @@ class AcademyViewModel extends ChangeNotifier {
3037
loadInitialData();
3138
}
3239

33-
// --- FIX: Make subject filtering case-insensitive ---
40+
// --- FIX: Make filtering "bilingual" ---
3441
void filterSubjectsForStudent(UserModel student) {
3542
if (student.subjectsToTake.isEmpty) {
3643
_availableSubjectsForStudent = List.from(_subjects);
3744
} else {
38-
// Normalize the subjects the student needs to take for reliable comparison
3945
final studentSubjectsNormalized = student.subjectsToTake.map((s) => s.trim().toLowerCase()).toSet();
4046

4147
_availableSubjectsForStudent = _subjects.where((subject) {
42-
// Normalize the name of the subject from the general list before checking for inclusion
4348
final subjectNameNormalized = subject.name.trim().toLowerCase();
44-
return studentSubjectsNormalized.contains(subjectNameNormalized);
49+
// Direct match (e.g., "sistemas digitales" == "sistemas digitales")
50+
if (studentSubjectsNormalized.contains(subjectNameNormalized)) {
51+
return true;
52+
}
53+
// Abbreviation match (e.g., "sistemas digitales" == value for key "APLIC. SIST. DIGITALES")
54+
final abbreviation = _subjectAbbreviationMap[subject.name.toUpperCase()];
55+
if (abbreviation != null && studentSubjectsNormalized.contains(abbreviation.toLowerCase())) {
56+
return true;
57+
}
58+
return false;
4559
}).toList();
4660
}
4761
notifyListeners();
@@ -68,7 +82,7 @@ class AcademyViewModel extends ChangeNotifier {
6882
}
6983
}
7084

71-
Future<void> _loadStudents() async {
85+
Future<void> _loadStudents() async {
7286
final query1 = _db
7387
.collection('users')
7488
.where('role', isEqualTo: 'student')
@@ -119,9 +133,23 @@ Future<void> _loadStudents() async {
119133
}
120134

121135
Future<void> _loadSubjects() async {
136+
final Set<String> searchTerms = {};
137+
for (var academy in myAcademies) {
138+
searchTerms.add(academy);
139+
if (_subjectAbbreviationMap.containsValue(academy)) {
140+
final originalName = _subjectAbbreviationMap.entries.firstWhere((entry) => entry.value == academy).key;
141+
searchTerms.add(originalName);
142+
}
143+
}
144+
145+
if (searchTerms.isEmpty) {
146+
_subjects = [];
147+
return;
148+
}
149+
122150
final snapshot = await _db
123151
.collection('subjects')
124-
.where('academy', whereIn: myAcademies)
152+
.where('academy', whereIn: searchTerms.toList())
125153
.get();
126154

127155
_subjects = snapshot.docs.map((doc) => SubjectModel.fromMap(doc.data(), doc.id)).toList();

0 commit comments

Comments
 (0)