import {Injectable} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {Appointment} from '../models/appointment'; import {environment} from '../../environments/environment'; import {AuthService} from './auth.service'; @Injectable({ providedIn: 'root', }) export class AppointmentService { baseApi = `${environment.baseApi}/appointments`; constructor(private http: HttpClient, private authService: AuthService) { } getAllAppointments() { return this.http.get(`${this.baseApi}`); } getAppointmentsByDate(date: Date) { const day = date.getDate().toString().padStart(2, '0') const month = (date.getMonth() + 1).toString().padStart(2, '0') const year = date.getFullYear(); return this.http.get(`${this.baseApi}/date?start=${year}-${month}-${day}`, {}); } addAppointment(appointment: Appointment) { let companyId = this.authService.getCurrentCompany().id return this.http.post(`${this.baseApi}/${companyId}`, appointment); } deleteAppointment(appointment: Appointment) { return this.http.delete(`${this.baseApi}?id=${appointment.id}`) } updateAppointment(appointment: Appointment) { return this.http.put(`${this.baseApi}`, appointment); } getAppointment(id: string) { return this.http.get(`${this.baseApi}/${id}`); } getMostRecentAppointment(id: number) { return this.http.get(`${this.baseApi}/recent/${id}`); } }