Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.

attendance-management-angular-13 (JS-0323) Detected usage of the `any… #14

Merged
merged 3 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/app/authentication/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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);
}
}
Expand All @@ -43,9 +43,9 @@ export class AuthService {
return false;
}

login(login: LoginDTO): Observable<HttpResponse<LoginDTO | StatusMessageResponse>> {
login(login: LoginDTO): Observable<HttpResponse<LoginToken | StatusMessageResponse>> {
console.log("Requesting login to " + this.loginUrl);
return this.http.post<LoginDTO | StatusMessageResponse>(this.loginUrl, login, {
return this.http.post<LoginToken | StatusMessageResponse>(this.loginUrl, login, {
responseType: 'json',
observe: 'response'
});
Expand Down
5 changes: 3 additions & 2 deletions src/app/authentication/login/auth.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -74,10 +75,10 @@ export class AuthComponent {
console.log("Logging in");
// Check if status code 200
this.loginService.login(loginData).pipe(
map((response: HttpResponse<any>) => {
map((response: HttpResponse<LoginToken | StatusMessageResponse>) => {
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");
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/top-header/top-header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number> = new EventEmitter<number>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class AdminDashboardComponent implements OnInit {
protected displayedColumns: string[] = ['name', 'grade', 'section', 'time', 'date', 'status'];
protected recentActivitiesRow: RecentActivitiesRow[] = [
];
protected recentActivitiesTableDataSource: MatTableDataSource<any> = new MatTableDataSource(this.recentActivitiesRow);
protected recentActivitiesTableDataSource: MatTableDataSource<RecentActivitiesRow> = new MatTableDataSource(this.recentActivitiesRow);


constructor() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/dashboard/announcements/announcements.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

// Mat Table data
displayedColumns: string[] = ['title', 'status', 'viewers'];
announcementTableDataSource: MatTableDataSource<any> = new MatTableDataSource(this.announcements);
announcementTableDataSource: MatTableDataSource<{}> = new MatTableDataSource(this.announcements);

Check warning on line 96 in src/app/dashboard/announcements/announcements.component.ts

View check run for this annotation

codefactor.io / CodeFactor

src/app/dashboard/announcements/announcements.component.ts#L96

Don't use `{}` as a type. `{}` actually means "any non-nullish value". - If you want a type meaning "any object", you probably want `object` instead. - If you want a type meaning "any value", you probably want `unknown` instead. - If you want a type meaning "empty object", you probably want `Record<string, never>` instead. - If you really want a type meaning "any non-nullish value", you probably want `NonNullable<unknown>` instead. (@typescript-eslint/ban-types)

// Announcement Pagination
// Pagination info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> = new MatTableDataSource(this.recentActivitiesRow);
protected recentActivitiesTableDataSource: MatTableDataSource<RecentActivitiesRow> = new MatTableDataSource(this.recentActivitiesRow);

// Section
@Input()
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
18 changes: 8 additions & 10 deletions src/app/services/attendance/attendance.service.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -14,35 +15,32 @@ export class AttendanceService {
apiUrl: string = environment.apiUrl + "/api/v1/attendances";
http: HttpClient = inject(HttpClient);

constructor() {
}

countAttendance(dateRange: DateRange, status: Status): Observable<any> {
return this.http.post(this.apiUrl + `/status/${status}/date-range`, dateRange, {
countAttendance(dateRange: DateRange, status: Status): Observable<HttpResponse<number>> {
return this.http.post<number>(this.apiUrl + `/status/${status}/date-range`, dateRange, {
observe: 'response',
responseType: 'json'
});
}

countAttendanceInSectionByDateRange(sectionId: number, dateRange: DateRange, status: Status): Observable<any> {
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<any> {
countAttendanceInSectionByDate(sectionId: number, date: Date, status: Status): Observable<HttpResponse<CountDTO>> {
const formattedDate: string = date.toISOString().split('T')[0];
return this.http.get<CountDTO>(this.apiUrl + `/status/${status}/section/${sectionId}/date?date=${formattedDate}`, {
observe: 'response',
responseType: 'json'
});
}

getAllSectionAndGradeLevelAttendanceByDate(sectionId: number, gradeLevelId: number, date: Date, page: number, size: number, sortBy = "date", orderBy: SortDirection = SortDirection.ASC): Observable<any> {
getAllSectionAndGradeLevelAttendanceByDate(sectionId: number, gradeLevelId: number, date: Date, page: number, size: number, sortBy = "date", orderBy: SortDirection = SortDirection.ASC): Observable<HttpResponse<AttendancePaging>> {
const formattedDate = date.toISOString().split('T')[0];

return this.http.get(this.apiUrl + `/statistics/section/${sectionId}/grade-level/${gradeLevelId}/date`, {
return this.http.get<AttendancePaging>(this.apiUrl + `/statistics/section/${sectionId}/grade-level/${gradeLevelId}/date`, {
params: {
date: formattedDate,
page: page,
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -12,11 +12,11 @@ export class AttendanceLineChartService {
private baseUrl: string = environment.apiUrl;
private http: HttpClient = inject(HttpClient);

getAttendanceLineChart(status: Status, dateRange: DateRange): Observable<any> {
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<HttpResponse<LineChartDTO>> {
return this.http.post<LineChartDTO>(`${this.baseUrl}/api/v1/attendances/graphic-organizers/line-chart?status=${status}`, dateRange, {observe: 'response', responseType: 'json'});
}

getSectionAttendanceLineChart(sectionId: number, status: Status, dateRange: DateRange): Observable<any> {
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<HttpResponse<LineChartDTO>> {
return this.http.post<LineChartDTO>(`${this.baseUrl}/api/v1/attendances/graphic-organizers/sections/${sectionId}/line-chart?status=${status}`, dateRange, {observe: 'response', responseType: 'json'});
}
}
41 changes: 15 additions & 26 deletions src/app/services/section/section.service.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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<HttpResponse<StatusMessageResponse>> {
return this.http.post<StatusMessageResponse>(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<HttpResponse<StatusMessageResponse>> {
return this.http.put<StatusMessageResponse>(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<StatusMessageResponse> {
return this.http.patch<StatusMessageResponse>(this.apiUrl + `/${sectionId}/grade-level`, {
params: {
gradeLevelId: gradeLevelId
},
Expand All @@ -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<HttpResponse<StatusMessageResponse>> {
return this.http.patch<StatusMessageResponse>(this.apiUrl + `/${sectionId}/name`, null, {
params: {
name: name
},
Expand All @@ -52,15 +41,15 @@ export class SectionService {
});
}

public deleteSection(sectionId: number) {
return this.http.delete(this.apiUrl + `/${sectionId}`, {
public deleteSection(sectionId: number): Observable<HttpResponse<StatusMessageResponse>> {
return this.http.delete<StatusMessageResponse>(this.apiUrl + `/${sectionId}`, {
responseType: 'json',
observe: 'response'
}
);
}

public getAllSectionsNoPaging() {
public getAllSectionsNoPaging(): Observable<HttpResponse<Section[]>> {
return this.http.get<Section[]>(this.apiUrl + "/all", {
params: {
noPaging: true
Expand All @@ -70,7 +59,7 @@ export class SectionService {
});
}

public getAllSections(page: number, size: number, orderBy: SortDirection = SortDirection.ASC, sortBy = "sectionName"): Observable<any> {
public getAllSections(page: number, size: number, orderBy: SortDirection = SortDirection.ASC, sortBy = "sectionName") {
return this.http.get(this.apiUrl + "/all", {
params: {
page: page,
Expand All @@ -83,7 +72,7 @@ export class SectionService {
});
}

public getSectionById(sectionId: number): Observable<any> {
public getSectionById(sectionId: number) {
return this.http.get(this.apiUrl + `/${sectionId}`, {responseType: 'json', observe: 'response'});
}

Expand Down
10 changes: 3 additions & 7 deletions src/app/services/student/student.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ export class StudentService {
})
}

countStudentsBySection(sectionId: number) {
countStudentsBySection(sectionId: number): Observable<HttpResponse<CountDTO>> {
return this.http.get<CountDTO>(this.apiUrl + `/api/v1/students/statistics/section?section=${sectionId}`, {
observe: 'response',
responseType: 'json'
});
}

public getAllStudents(page: number, size: number): Observable<any> {
return this.http.get(this.apiUrl + `/api/v1/students/all?page=${page}&size=${size}`);
public getAllStudents(page: number, size: number): Observable<StudentPaging> {
return this.http.get<StudentPaging>(this.apiUrl + `/api/v1/students/all?page=${page}&size=${size}`);
}

public createStudent(student: Student): Observable<HttpResponse<StatusMessageResponse>> {
Expand Down Expand Up @@ -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
}
}
7 changes: 4 additions & 3 deletions src/app/services/teacher/teacher.service.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -11,8 +12,8 @@ export class TeacherService {
private apiUrl: string = environment.apiUrl;
private http: HttpClient = inject(HttpClient);

getTeacherByUserId(userId: number): Observable<any> {
return this.http.get(this.apiUrl + `/api/v1/teachers/user?id=${userId}`, {
getTeacherByUserId(userId: number): Observable<HttpResponse<Teacher>> {
return this.http.get<Teacher>(this.apiUrl + `/api/v1/teachers/user?id=${userId}`, {
observe: 'response',
responseType: 'json'
});
Expand Down
Loading