diff --git a/.github/workflows/main_avinyawebapp-production.yml b/.github/workflows/main_avinyawebapp-production.yml index a74c3f41..b9a3aedd 100644 --- a/.github/workflows/main_avinyawebapp-production.yml +++ b/.github/workflows/main_avinyawebapp-production.yml @@ -62,7 +62,7 @@ jobs: npm run test --if-present - name: Upload artifact for node app - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: node-app path: campus/deployment/node-app @@ -76,7 +76,7 @@ jobs: steps: - name: Download artifact from build job - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: node-app diff --git a/campus/frontend/lib/avinya/enrollment/lib/data/person.dart b/campus/frontend/lib/avinya/enrollment/lib/data/person.dart index 738c6a06..b953990d 100644 --- a/campus/frontend/lib/avinya/enrollment/lib/data/person.dart +++ b/campus/frontend/lib/avinya/enrollment/lib/data/person.dart @@ -14,6 +14,7 @@ class MainOrganization { AvinyaType? avinya_type; Name? name; String? phone; + List? parent_organizations; MainOrganization( {this.id, @@ -22,7 +23,8 @@ class MainOrganization { this.address, this.avinya_type, this.name, - this.phone}); + this.phone, + this.parent_organizations}); factory MainOrganization.fromJson(Map json) { return MainOrganization( @@ -36,6 +38,12 @@ class MainOrganization { : null, name: json['name'] != null ? Name.fromJson(json['name']) : null, phone: json['phone'], + // Safely handle 'parent_organizations' being null + parent_organizations: json['parent_organizations'] != null + ? (json['parent_organizations'] as List) + .map((item) => ParentOrganization.fromJson(item)) + .toList() + : [], ); } @@ -47,6 +55,11 @@ class MainOrganization { if (avinya_type != null) 'avinya_type': avinya_type!.toJson(), if (name != null) 'name': name!.toJson(), if (phone != null) 'phone': phone, + // Correctly handling 'parent_organizations' as a list + if (parent_organizations != null) + 'parent_organizations': parent_organizations! + .map((parentOrg) => parentOrg.toJson()) + .toList(), }; } @@ -108,6 +121,27 @@ class Name { }; } +class ParentOrganization { + int? id; + Name? name; + + ParentOrganization({this.id, this.name}); + + factory ParentOrganization.fromJson(Map json) { + return ParentOrganization( + id: json['id'], + name: json['name'] is Map + ? Name.fromJson(json['name']) + : null, // Handle cases where 'name' is not a Map + ); + } + + Map toJson() => { + if (id != null) 'id': id, + if (name != null) 'name': name?.toJson(), + }; +} + class City { int? id; Name? name; diff --git a/campus/frontend/lib/avinya/enrollment/lib/widgets/student_update.dart b/campus/frontend/lib/avinya/enrollment/lib/widgets/student_update.dart index f722b4c7..f778b135 100644 --- a/campus/frontend/lib/avinya/enrollment/lib/widgets/student_update.dart +++ b/campus/frontend/lib/avinya/enrollment/lib/widgets/student_update.dart @@ -40,7 +40,11 @@ class _StudentUpdateState extends State { Future getUserPerson() async { Person user = await fetchPerson(widget.id); - classes = await fetchClasses(user.organization?.id); + classes = await fetchClasses( + (user.organization?.parent_organizations?.isNotEmpty ?? false) + ? user.organization?.parent_organizations?.first.id + : null); + setState(() { classes = classes; userPerson = user; @@ -454,18 +458,11 @@ class _StudentUpdateState extends State { } List> _getClassOptions() { - List> classes = [ - {'id': 18, 'description': 'Leopards'}, - {'id': 2, 'description': 'Dolphine'}, - {'id': 3, 'description': 'Bees'}, - {'id': 4, 'description': 'Elephents'}, - ]; - return classes .map((classe) => DropdownMenuItem( - value: classe['id'] as int, // Explicitly cast to int - child: Text( - classe['description'] as String), // Explicitly cast to String + value: classe.id, // Access id directly from MainOrganization + child: Text(classe.description ?? + 'No description'), // Handle null description )) .toList(); }