From 2a1a3c2ec4297c084f83f3702a915de85d486e4b Mon Sep 17 00:00:00 2001 From: Vince Angelo Batecan Date: Sat, 22 Jun 2024 12:12:30 +0800 Subject: [PATCH 1/3] attendance-management-angular-13 (JS-0323) Detected usage of the `any` type closes #13 by adding explicit type feat(app): enhance authentication service and improve DTO imports Update AuthService to include LoginToken alongside LoginDTO for improved type safety during login requests Adjust return types within AuthService: Replace generic Observable responses with specific HttpResponse variants involving either LoginToken/StatusMessageResponse or just StatusMessageResponse. Modify AttendanceLineChartService's getAttendanceLineChart()/getSectionAttendanceLineChart() methods by specifying LineChartDTO in their return types while also importing it explicitly along with HttpResponse Remove redundant HttpClient import statement from TopHeaderComponent Enhance StudentService by returning more precise types: Convert countStudentsBySection() method's return value to an observable emitting HttpResponse wrapping around a CountDTO object Transform getAllStudents() method's result into an observable yielding StudentPaging objects rather than an unspecific any type Refactor TeacherService to fetch Teacher entities wrapped inside HttpResponse instances via the getTeacherByUserId() function Standardize SectionService by consistently utilizing observables encapsulating HTTP responses across all methods (createSection(), updateSection(), etc.) and importing required DTO classes like StatusMessageResponse upfront Ensure proper typing throughout remaining components such as AnnouncementsComponent, AdminDashboardComponent, TeacherDashboardComponent, and TeacherStudentsComponent --- src/app/authentication/auth.service.ts | 6 +-- .../authentication/login/auth.component.ts | 5 ++- .../top-header/top-header.component.ts | 2 +- .../admin-dashboard.component.ts | 2 +- .../announcements/announcements.component.ts | 2 +- .../teacher-dashboard.component.ts | 10 +++-- .../teacher-students.component.ts | 2 +- .../services/attendance/attendance.service.ts | 11 ++--- .../attendance-line-chart.service.ts | 12 +++--- src/app/services/section/section.service.ts | 41 +++++++------------ src/app/services/student/student.service.ts | 10 ++--- src/app/services/teacher/teacher.service.ts | 7 ++-- 12 files changed, 48 insertions(+), 62 deletions(-) diff --git a/src/app/authentication/auth.service.ts b/src/app/authentication/auth.service.ts index b59bb38..43ca881 100644 --- a/src/app/authentication/auth.service.ts +++ b/src/app/authentication/auth.service.ts @@ -2,7 +2,7 @@ import {inject, Injectable} from '@angular/core'; import {HttpClient, HttpResponse} from "@angular/common/http"; import {environment} from "../../environments/environment"; import {map, Observable, of} from "rxjs"; -import {LoginDTO} from "../DTO/DTOList"; +import {LoginDTO, LoginToken} from "../DTO/DTOList"; import {StatusMessageResponse} from "../DTO/StatusMessageResponse"; import {ExecutionStatus} from "../enums/ExecutionStatus"; @@ -43,9 +43,9 @@ export class AuthService { return false; } - login(login: LoginDTO): Observable> { + login(login: LoginDTO): Observable> { console.log("Requesting login to " + this.loginUrl); - return this.http.post(this.loginUrl, login, { + return this.http.post(this.loginUrl, login, { responseType: 'json', observe: 'response' }); diff --git a/src/app/authentication/login/auth.component.ts b/src/app/authentication/login/auth.component.ts index 763d957..0991dab 100644 --- a/src/app/authentication/login/auth.component.ts +++ b/src/app/authentication/login/auth.component.ts @@ -16,6 +16,7 @@ import {Router} from "@angular/router"; import {TeacherService} from "../../services/teacher/teacher.service"; import {Roles} from "../../enums/Roles"; import {Teacher} from "../../DTO/TeacherDTO"; +import {StatusMessageResponse} from "../../DTO/StatusMessageResponse"; @Component({ selector: 'app-login', @@ -74,10 +75,10 @@ export class AuthComponent { console.log("Logging in"); // Check if status code 200 this.loginService.login(loginData).pipe( - map((response: HttpResponse) => { + map((response: HttpResponse) => { console.log("Login successful"); // Get token - const loginToken: LoginToken = response.body; + const loginToken: LoginToken = response.body as LoginToken; // Show alert message this.alert.open("Login successful", "Close"); diff --git a/src/app/components/top-header/top-header.component.ts b/src/app/components/top-header/top-header.component.ts index ab6b34b..e6f13eb 100644 --- a/src/app/components/top-header/top-header.component.ts +++ b/src/app/components/top-header/top-header.component.ts @@ -36,7 +36,7 @@ import {NgOptimizedImage} from "@angular/common"; }) export class TopHeaderComponent implements OnInit { @Input() - public sidenav: MatDrawer | any; + public sidenav: MatDrawer | undefined; @Output() public readonly sectionSelected: EventEmitter = new EventEmitter(); diff --git a/src/app/dashboard/admin/admin-dashboard/admin-dashboard.component.ts b/src/app/dashboard/admin/admin-dashboard/admin-dashboard.component.ts index 24fb6c3..a046be8 100644 --- a/src/app/dashboard/admin/admin-dashboard/admin-dashboard.component.ts +++ b/src/app/dashboard/admin/admin-dashboard/admin-dashboard.component.ts @@ -91,7 +91,7 @@ export class AdminDashboardComponent implements OnInit { protected displayedColumns: string[] = ['name', 'grade', 'section', 'time', 'date', 'status']; protected recentActivitiesRow: RecentActivitiesRow[] = [ ]; - protected recentActivitiesTableDataSource: MatTableDataSource = new MatTableDataSource(this.recentActivitiesRow); + protected recentActivitiesTableDataSource: MatTableDataSource = new MatTableDataSource(this.recentActivitiesRow); constructor() { diff --git a/src/app/dashboard/announcements/announcements.component.ts b/src/app/dashboard/announcements/announcements.component.ts index 0427ea6..880c7f5 100644 --- a/src/app/dashboard/announcements/announcements.component.ts +++ b/src/app/dashboard/announcements/announcements.component.ts @@ -93,7 +93,7 @@ export class AnnouncementsComponent implements OnInit { // Mat Table data displayedColumns: string[] = ['title', 'status', 'viewers']; - announcementTableDataSource: MatTableDataSource = new MatTableDataSource(this.announcements); + announcementTableDataSource: MatTableDataSource<{}> = new MatTableDataSource(this.announcements); // Announcement Pagination // Pagination info diff --git a/src/app/dashboard/teacher/teacher-dashboard/teacher-dashboard.component.ts b/src/app/dashboard/teacher/teacher-dashboard/teacher-dashboard.component.ts index 676abbb..df2db67 100644 --- a/src/app/dashboard/teacher/teacher-dashboard/teacher-dashboard.component.ts +++ b/src/app/dashboard/teacher/teacher-dashboard/teacher-dashboard.component.ts @@ -94,7 +94,7 @@ export class TeacherDashboardComponent implements OnInit, OnChanges { // Recent Activities table and Data Source protected displayedColumns: string[] = ['name', 'grade', 'section', 'time', 'date', 'status']; protected recentActivitiesRow: RecentActivitiesRow[] = []; - protected recentActivitiesTableDataSource: MatTableDataSource = new MatTableDataSource(this.recentActivitiesRow); + protected recentActivitiesTableDataSource: MatTableDataSource = new MatTableDataSource(this.recentActivitiesRow); // Section @Input() @@ -384,9 +384,11 @@ export class TeacherDashboardComponent implements OnInit, OnChanges { } updateAttendanceOverviewData(label: string[], data: number[], dataset = 0) { - this.attendanceOverviewChart.data.labels = label; - this.attendanceOverviewChart.data.datasets[dataset].data = data; - this.attendanceOverviewChart.update(); + if (this.attendanceOverviewChart !== undefined) { + this.attendanceOverviewChart.data.labels = label; + this.attendanceOverviewChart.data.datasets[dataset].data = data; + this.attendanceOverviewChart.update(); + } } updateDashboardStatistics() { diff --git a/src/app/dashboard/teacher/teacher-students/teacher-students.component.ts b/src/app/dashboard/teacher/teacher-students/teacher-students.component.ts index da41e77..553f3f8 100644 --- a/src/app/dashboard/teacher/teacher-students/teacher-students.component.ts +++ b/src/app/dashboard/teacher/teacher-students/teacher-students.component.ts @@ -49,7 +49,7 @@ export class TeacherStudentsComponent implements OnInit { // Pie Chart with Chart JS public pieChartLabels = ["Male", "Female"]; public pieChartData = [512, 235]; - public pieChart: any; + public pieChart: Chart<"pie", number[], string> | undefined; ngOnInit() { this.pieChart = new Chart('pieChart', { diff --git a/src/app/services/attendance/attendance.service.ts b/src/app/services/attendance/attendance.service.ts index d227189..230f5f0 100644 --- a/src/app/services/attendance/attendance.service.ts +++ b/src/app/services/attendance/attendance.service.ts @@ -14,24 +14,21 @@ export class AttendanceService { apiUrl: string = environment.apiUrl + "/api/v1/attendances"; http: HttpClient = inject(HttpClient); - constructor() { - } - - countAttendance(dateRange: DateRange, status: Status): Observable { + countAttendance(dateRange: DateRange, status: Status) { return this.http.post(this.apiUrl + `/status/${status}/date-range`, dateRange, { observe: 'response', responseType: 'json' }); } - countAttendanceInSectionByDateRange(sectionId: number, dateRange: DateRange, status: Status): Observable { + countAttendanceInSectionByDateRange(sectionId: number, dateRange: DateRange, status: Status) { return this.http.post(this.apiUrl + `/status/${status}/section/${sectionId}/date-range`, dateRange, { observe: 'response', responseType: 'json' }); } - countAttendanceInSectionByDate(sectionId: number, date: Date, status: Status): Observable { + countAttendanceInSectionByDate(sectionId: number, date: Date, status: Status) { const formattedDate: string = date.toISOString().split('T')[0]; return this.http.get(this.apiUrl + `/status/${status}/section/${sectionId}/date?date=${formattedDate}`, { observe: 'response', @@ -39,7 +36,7 @@ export class AttendanceService { }); } - getAllSectionAndGradeLevelAttendanceByDate(sectionId: number, gradeLevelId: number, date: Date, page: number, size: number, sortBy = "date", orderBy: SortDirection = SortDirection.ASC): Observable { + getAllSectionAndGradeLevelAttendanceByDate(sectionId: number, gradeLevelId: number, date: Date, page: number, size: number, sortBy = "date", orderBy: SortDirection = SortDirection.ASC) { const formattedDate = date.toISOString().split('T')[0]; return this.http.get(this.apiUrl + `/statistics/section/${sectionId}/grade-level/${gradeLevelId}/date`, { diff --git a/src/app/services/charts/attendance/attendance-line-chart.service.ts b/src/app/services/charts/attendance/attendance-line-chart.service.ts index 986f04e..0deaaba 100644 --- a/src/app/services/charts/attendance/attendance-line-chart.service.ts +++ b/src/app/services/charts/attendance/attendance-line-chart.service.ts @@ -1,7 +1,7 @@ import {inject, Injectable} from '@angular/core'; import {environment} from "../../../../environments/environment"; -import {HttpClient} from "@angular/common/http"; -import {DateRange, Status} from "../../../DTO/DTOList"; +import {HttpClient, HttpResponse} from "@angular/common/http"; +import {DateRange, LineChartDTO, Status} from "../../../DTO/DTOList"; import {Observable} from "rxjs"; @Injectable({ @@ -12,11 +12,11 @@ export class AttendanceLineChartService { private baseUrl: string = environment.apiUrl; private http: HttpClient = inject(HttpClient); - getAttendanceLineChart(status: Status, dateRange: DateRange): Observable { - return this.http.post(`${this.baseUrl}/api/v1/attendances/graphic-organizers/line-chart?status=${status}`, dateRange, {observe: 'response', responseType: 'json'}); + getAttendanceLineChart(status: Status, dateRange: DateRange): Observable> { + return this.http.post(`${this.baseUrl}/api/v1/attendances/graphic-organizers/line-chart?status=${status}`, dateRange, {observe: 'response', responseType: 'json'}); } - getSectionAttendanceLineChart(sectionId: number, status: Status, dateRange: DateRange): Observable { - return this.http.post(`${this.baseUrl}/api/v1/attendances/graphic-organizers/sections/${sectionId}/line-chart?status=${status}`, dateRange, {observe: 'response', responseType: 'json'}); + getSectionAttendanceLineChart(sectionId: number, status: Status, dateRange: DateRange): Observable> { + return this.http.post(`${this.baseUrl}/api/v1/attendances/graphic-organizers/sections/${sectionId}/line-chart?status=${status}`, dateRange, {observe: 'response', responseType: 'json'}); } } diff --git a/src/app/services/section/section.service.ts b/src/app/services/section/section.service.ts index eb74828..722652c 100644 --- a/src/app/services/section/section.service.ts +++ b/src/app/services/section/section.service.ts @@ -1,9 +1,10 @@ import {inject, Injectable} from '@angular/core'; import {environment} from "../../../environments/environment"; -import {HttpClient} from "@angular/common/http"; +import {HttpClient, HttpResponse} from "@angular/common/http"; import {Observable} from "rxjs"; import {Section} from "../../DTO/SectionDTO"; import {SortDirection} from "../../enums/SortDirection"; +import {StatusMessageResponse} from "../../DTO/StatusMessageResponse"; @Injectable({ providedIn: 'root' @@ -13,27 +14,15 @@ export class SectionService { private apiUrl: string = environment.apiUrl + "/api/v1/sections"; private http: HttpClient = inject(HttpClient); - public createSection(section: Section) { - return this.http.post(this.apiUrl + "/create", section, {responseType: 'json', observe: 'response'}); + public createSection(section: Section): Observable> { + return this.http.post(this.apiUrl + "/create", section, {responseType: 'json', observe: 'response'}); } - public updateSection(sectionId: number, section: Section) { - return this.http.put(this.apiUrl + `/${sectionId}`, section, {responseType: 'json', observe: 'response'}); + public updateSection(sectionId: number, section: Section): Observable> { + return this.http.put(this.apiUrl + `/${sectionId}`, section, {responseType: 'json', observe: 'response'}); } - - public updateSectionTeacher(sectionId: number, teacherId: number) { - return this.http.patch(this.apiUrl + `/${sectionId}/teacher`, { - params: { - sectionId: sectionId, - teacherId: teacherId - }, - responseType: 'json', - observe: 'response' - }); - } - - public updateSectionGradeLevel(sectionId: number, gradeLevelId: number) { - return this.http.patch(this.apiUrl + `/${sectionId}/grade-level`, { + public updateSectionGradeLevel(sectionId: number, gradeLevelId: number): Observable { + return this.http.patch(this.apiUrl + `/${sectionId}/grade-level`, { params: { gradeLevelId: gradeLevelId }, @@ -42,8 +31,8 @@ export class SectionService { }); } - public updateSectionName(sectionId: number, name: string) { - return this.http.patch(this.apiUrl + `/${sectionId}/name`, null, { + public updateSectionName(sectionId: number, name: string): Observable> { + return this.http.patch(this.apiUrl + `/${sectionId}/name`, null, { params: { name: name }, @@ -52,15 +41,15 @@ export class SectionService { }); } - public deleteSection(sectionId: number) { - return this.http.delete(this.apiUrl + `/${sectionId}`, { + public deleteSection(sectionId: number): Observable> { + return this.http.delete(this.apiUrl + `/${sectionId}`, { responseType: 'json', observe: 'response' } ); } - public getAllSectionsNoPaging() { + public getAllSectionsNoPaging(): Observable> { return this.http.get(this.apiUrl + "/all", { params: { noPaging: true @@ -70,7 +59,7 @@ export class SectionService { }); } - public getAllSections(page: number, size: number, orderBy: SortDirection = SortDirection.ASC, sortBy = "sectionName"): Observable { + public getAllSections(page: number, size: number, orderBy: SortDirection = SortDirection.ASC, sortBy = "sectionName") { return this.http.get(this.apiUrl + "/all", { params: { page: page, @@ -83,7 +72,7 @@ export class SectionService { }); } - public getSectionById(sectionId: number): Observable { + public getSectionById(sectionId: number) { return this.http.get(this.apiUrl + `/${sectionId}`, {responseType: 'json', observe: 'response'}); } diff --git a/src/app/services/student/student.service.ts b/src/app/services/student/student.service.ts index 27863a2..45e6e88 100644 --- a/src/app/services/student/student.service.ts +++ b/src/app/services/student/student.service.ts @@ -33,15 +33,15 @@ export class StudentService { }) } - countStudentsBySection(sectionId: number) { + countStudentsBySection(sectionId: number): Observable> { return this.http.get(this.apiUrl + `/api/v1/students/statistics/section?section=${sectionId}`, { observe: 'response', responseType: 'json' }); } - public getAllStudents(page: number, size: number): Observable { - return this.http.get(this.apiUrl + `/api/v1/students/all?page=${page}&size=${size}`); + public getAllStudents(page: number, size: number): Observable { + return this.http.get(this.apiUrl + `/api/v1/students/all?page=${page}&size=${size}`); } public createStudent(student: Student): Observable> { @@ -137,8 +137,4 @@ export class StudentService { } }); } - - public isStudent(obj: any): obj is Student { - return 'id' in obj && 'name' in obj; // replace 'id' and 'name' with actual properties of Student - } } diff --git a/src/app/services/teacher/teacher.service.ts b/src/app/services/teacher/teacher.service.ts index 481c1ab..5d9e7d1 100644 --- a/src/app/services/teacher/teacher.service.ts +++ b/src/app/services/teacher/teacher.service.ts @@ -1,7 +1,8 @@ import {inject, Injectable} from '@angular/core'; import {environment} from "../../../environments/environment"; -import {HttpClient} from "@angular/common/http"; +import {HttpClient, HttpResponse} from "@angular/common/http"; import {Observable} from "rxjs"; +import {Teacher} from "../../DTO/TeacherDTO"; @Injectable({ providedIn: 'root' @@ -11,8 +12,8 @@ export class TeacherService { private apiUrl: string = environment.apiUrl; private http: HttpClient = inject(HttpClient); - getTeacherByUserId(userId: number): Observable { - return this.http.get(this.apiUrl + `/api/v1/teachers/user?id=${userId}`, { + getTeacherByUserId(userId: number): Observable> { + return this.http.get(this.apiUrl + `/api/v1/teachers/user?id=${userId}`, { observe: 'response', responseType: 'json' }); From 2e6f47dbb062fa95dd0784aab5e2270adfc571f9 Mon Sep 17 00:00:00 2001 From: Vince Angelo Batecan Date: Sat, 22 Jun 2024 12:15:58 +0800 Subject: [PATCH 2/3] Fixes somethings that made from change any to explicit typing. --- src/app/authentication/auth.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/authentication/auth.service.ts b/src/app/authentication/auth.service.ts index 43ca881..24ac133 100644 --- a/src/app/authentication/auth.service.ts +++ b/src/app/authentication/auth.service.ts @@ -28,7 +28,7 @@ export class AuthService { // Check response body if it is valid if (response.body) { const message = response.body; - if (message?.status == ExecutionStatus.VALID) { + if (message?.status === ExecutionStatus.VALID) { return of(true); } } From b40cbde2dd29c2c7665ae93feec48f762e45f94a Mon Sep 17 00:00:00 2001 From: Vince Angelo Batecan Date: Sat, 22 Jun 2024 12:16:07 +0800 Subject: [PATCH 3/3] attendance-management-angular-13 (JS-0323) Detected usage of the `any` type closes #13 by adding explicit type feat(app): enhance authentication service and improve DTO imports Update AuthService to include LoginToken alongside LoginDTO for improved type safety during login requests Adjust return types within AuthService: Replace generic Observable responses with specific HttpResponse variants involving either LoginToken/StatusMessageResponse or just StatusMessageResponse. Modify AttendanceLineChartService's getAttendanceLineChart()/getSectionAttendanceLineChart() methods by specifying LineChartDTO in their return types while also importing it explicitly along with HttpResponse Remove redundant HttpClient import statement from TopHeaderComponent Enhance StudentService by returning more precise types: Convert countStudentsBySection() method's return value to an observable emitting HttpResponse wrapping around a CountDTO object Transform getAllStudents() method's result into an observable yielding StudentPaging objects rather than an unspecific any type Refactor TeacherService to fetch Teacher entities wrapped inside HttpResponse instances via the getTeacherByUserId() function Standardize SectionService by consistently utilizing observables encapsulating HTTP responses across all methods (createSection(), updateSection(), etc.) and importing required DTO classes like StatusMessageResponse upfront Ensure proper typing throughout remaining components such as AnnouncementsComponent, AdminDashboardComponent, TeacherDashboardComponent, and TeacherStudentsComponent --- src/app/services/attendance/attendance.service.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/app/services/attendance/attendance.service.ts b/src/app/services/attendance/attendance.service.ts index 230f5f0..f59b7eb 100644 --- a/src/app/services/attendance/attendance.service.ts +++ b/src/app/services/attendance/attendance.service.ts @@ -1,10 +1,11 @@ import {inject, Injectable} from '@angular/core'; import {environment} from "../../../environments/environment"; -import {HttpClient} from "@angular/common/http"; +import {HttpClient, HttpResponse} from "@angular/common/http"; import {DateRange, Status} from "../../DTO/DTOList"; import {Observable} from "rxjs"; import {CountDTO} from "../../DTO/CountDTO"; import {SortDirection} from "../../enums/SortDirection"; +import {AttendancePaging} from "../../DTO/AttendanceDTO"; @Injectable({ providedIn: 'root' @@ -14,8 +15,8 @@ export class AttendanceService { apiUrl: string = environment.apiUrl + "/api/v1/attendances"; http: HttpClient = inject(HttpClient); - countAttendance(dateRange: DateRange, status: Status) { - return this.http.post(this.apiUrl + `/status/${status}/date-range`, dateRange, { + countAttendance(dateRange: DateRange, status: Status): Observable> { + return this.http.post(this.apiUrl + `/status/${status}/date-range`, dateRange, { observe: 'response', responseType: 'json' }); @@ -28,7 +29,7 @@ export class AttendanceService { }); } - countAttendanceInSectionByDate(sectionId: number, date: Date, status: Status) { + countAttendanceInSectionByDate(sectionId: number, date: Date, status: Status): Observable> { const formattedDate: string = date.toISOString().split('T')[0]; return this.http.get(this.apiUrl + `/status/${status}/section/${sectionId}/date?date=${formattedDate}`, { observe: 'response', @@ -36,10 +37,10 @@ export class AttendanceService { }); } - getAllSectionAndGradeLevelAttendanceByDate(sectionId: number, gradeLevelId: number, date: Date, page: number, size: number, sortBy = "date", orderBy: SortDirection = SortDirection.ASC) { + getAllSectionAndGradeLevelAttendanceByDate(sectionId: number, gradeLevelId: number, date: Date, page: number, size: number, sortBy = "date", orderBy: SortDirection = SortDirection.ASC): Observable> { const formattedDate = date.toISOString().split('T')[0]; - return this.http.get(this.apiUrl + `/statistics/section/${sectionId}/grade-level/${gradeLevelId}/date`, { + return this.http.get(this.apiUrl + `/statistics/section/${sectionId}/grade-level/${gradeLevelId}/date`, { params: { date: formattedDate, page: page,