Filter-appointments
TS
export class AppointmentFilterContainerComponent {
private _notificationService = inject(SnackbarMessageService)
private _appointmentService = inject(AppointmentService)
searchedAppointments$!: Observable<AppointmentModel[][]>;
searchForm: FormGroup;
constructor(private fb: FormBuilder) {
this.searchForm = this.fb.group({
startDate: [null, Validators.required],
endDate: [null, Validators.required],
});
}
submit(): void {
const { startDate, endDate } = this.searchForm.value;
if (!this.checkValid(startDate, endDate)) return
if (!this.checkOrdered(startDate, endDate)) return
this.searchedAppointments$ = this._appointmentService.getFilteredAppointments(startDate, endDate);
}
checkValid(startDate:string, endDate:string): boolean {
if(isNaN(Date.parse(startDate)) && isNaN(Date.parse(endDate))){
this._notificationService.showMessage("A data inserida deve ser válida.");
return false;
}
return true
}
checkOrdered(startDate:string, endDate:string): boolean {
if(startDate > endDate){
this._notificationService.showMessage("A data inicial deve ser menor ou igual à data final.");
return false;
}
return true;
}
}```