-
+
{{ appointment.title }}
- {{ getFormattedTime(appointment.startHour, appointment.startMinute) }} -
- {{ getFormattedTime(appointment.endHour, appointment.endMinute) }}
+ {{ getFormattedTime(appointment.startDateTime.getHours(), appointment.startDateTime.getMinutes()) }} -
+ {{ getFormattedTime(appointment.endDateTime.getHours(), appointment.endDateTime.getMinutes()) }}
diff --git a/src/app/components/new-item/new-item.component.ts b/src/app/components/new-item/new-item.component.ts
index 56f5adc..ce3eb46 100644
--- a/src/app/components/new-item/new-item.component.ts
+++ b/src/app/components/new-item/new-item.component.ts
@@ -10,7 +10,6 @@ import {
TuiTextareaModule,
TuiTextfieldControllerModule
} from "@taiga-ui/legacy";
-import {Appointment} from '../../models/appointment';
import {TuiDay, TuiValidationError} from '@taiga-ui/cdk';
import {AppointmentService} from '../../services/appointment.service';
import {TuiDataListWrapperComponent, TuiFilterByInputPipe, TuiStringifyContentPipe} from '@taiga-ui/kit';
@@ -75,7 +74,7 @@ export class NewItemComponent implements OnInit {
this.appointmentForm.get('startTime').setValue('', Validators.required)
this.appointmentForm.get('endTime').setValue('', [Validators.required, timeAfterStartValidator('startTime')])
this.appointments.sort((a, b) => {
- return a.startHour - b.startHour || a.startMinute - b.startMinute;
+ return a.startDateTime.getHours() - b.startDateTime.getHours() || a.startDateTime.getMinutes() - b.startDateTime.getMinutes();
});
}
@@ -87,9 +86,13 @@ export class NewItemComponent implements OnInit {
let date = this.appointmentForm.get('date').value
let correctDate = new Date(date.year, date.month, date.day, startTime.hours, startTime.minutes);
+ let startDateTime = new Date(date.year, date.month, date.day, startTime.hours, startTime.minutes)
+ let endDateTime = new Date(date.year, date.month, date.day, endTime.hours, endTime.minutes)
+
const customer = this.customerControl.value;
- const appointment = new AppointmentDto(title, description, startTime.hours, startTime.minutes, endTime.hours, endTime.minutes, correctDate, customer)
+ // constructor(id: string, title: string, description: string, startDateTime: Date, endDateTime: Date, customer: Customer, company: CompanyDTO)
+ const appointment = new AppointmentDto(title, description, startDateTime, endDateTime, customer)
this.waiting = true
this.appointmentService.addAppointment(appointment, this.userService.currentCompany.id).subscribe(() => {
this.waiting = false
diff --git a/src/app/components/week-view/week-view.component.ts b/src/app/components/week-view/week-view.component.ts
index f769f6a..06ff88c 100644
--- a/src/app/components/week-view/week-view.component.ts
+++ b/src/app/components/week-view/week-view.component.ts
@@ -41,6 +41,7 @@ export class WeekViewComponent implements OnInit {
getAppointments() {
console.log(this.days[0], this.days[6])
+ console.log('GETTING APPOINTMENTS')
this.appointmentService.getAppointmentsByWeek(this.days[0], this.days[6]).subscribe(appointments => {
this.appointments = appointments
console.log(appointments);
@@ -86,12 +87,23 @@ export class WeekViewComponent implements OnInit {
}
searchAppointments(day: Date, hour: string) {
- return this.appointments.filter(appointment =>
- appointment.startHour === Number(hour.substring(0, 2)) &&
- appointment.startDate.toString().startsWith(this.formatDateToISO(day))
- );
+ const targetHour = Number(hour.substring(0, 2));
+
+ return this.appointments.filter(appointment => {
+ const date = appointment.startDateTime instanceof Date
+ ? appointment.startDateTime
+ : new Date(appointment.startDateTime); // fallback als het nog een string is
+
+ return (
+ date.getFullYear() === day.getFullYear() &&
+ date.getMonth() === day.getMonth() &&
+ date.getDate() === day.getDate() &&
+ date.getHours() === targetHour
+ );
+ });
}
+
formatDateToISO(date: Date): string {
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0'); // maand is 0-based
@@ -103,4 +115,8 @@ export class WeekViewComponent implements OnInit {
emitAppointment($event: AppointmentDto) {
this.appointmentSelected.emit($event);
}
+
+ getISODate(date: Date) {
+ return date.toISOString();
+ }
}
diff --git a/src/app/models/appointment-dto.ts b/src/app/models/appointment-dto.ts
index 4c39ff2..9b2c64d 100644
--- a/src/app/models/appointment-dto.ts
+++ b/src/app/models/appointment-dto.ts
@@ -2,30 +2,23 @@ import {Customer} from './customer';
import {CompanyDTO} from './app-user-dto';
export class AppointmentDto {
- id: number;
+ id: string;
title: string;
description: string;
- startDate: string | Date;
- startHour: number;
- startMinute: number;
- endHour: number;
- endMinute: number;
+ startDateTime: Date;
+ endDateTime: Date;
durationInMinutes: number;
customer: Customer;
company: CompanyDTO;
-
- constructor(title: string, description: string, startHour: number, startMinute: number, endHour: number, endMinute: number, date: Date, customer: Customer) {
+ constructor(title: string, description: string, startDateTime: Date, endDateTime: Date, customer: Customer) {
this.title = title;
this.description = description;
- this.startHour = startHour;
- this.startMinute = startMinute;
- this.endHour = endHour;
- this.endMinute = endMinute;
- this.startDate = date;
+ this.startDateTime = startDateTime;
+ this.endDateTime = endDateTime;
this.customer = customer;
- // Bereken de totale duur in minuten
- this.durationInMinutes = (endHour * 60 + endMinute) - (startHour * 60 + startMinute);
+ this.durationInMinutes = (startDateTime.getTime() - startDateTime.getTime()) / 1000;
}
+
}
diff --git a/src/app/models/appointment.ts b/src/app/models/appointment.ts
index b0bde88..6fc6d52 100644
--- a/src/app/models/appointment.ts
+++ b/src/app/models/appointment.ts
@@ -4,26 +4,20 @@ export class Appointment {
id: string;
title: string;
description: string;
- startDate: Date;
- startHour: number;
- startMinute: number;
- endHour: number;
- endMinute: number;
+ startDateTime: Date;
+ endDateTime: Date;
durationInMinutes: number;
customer: Customer;
- constructor(title: string, description: string, startHour: number, startMinute: number, endHour: number, endMinute: number, date: Date, customer: Customer) {
+ constructor(id: string, title: string, description: string, startDateTime: Date, endDateTime: Date, customer: Customer) {
+ this.id = id;
this.title = title;
this.description = description;
- this.startHour = startHour;
- this.startMinute = startMinute;
- this.endHour = endHour;
- this.endMinute = endMinute;
- this.startDate = date;
+ this.startDateTime = startDateTime;
+ this.endDateTime = endDateTime;
this.customer = customer;
- // Bereken de totale duur in minuten
- this.durationInMinutes = (endHour * 60 + endMinute) - (startHour * 60 + startMinute);
+ this.durationInMinutes = (startDateTime.getTime() - startDateTime.getTime()) / 1000;
}
}
diff --git a/src/app/pages/agenda/agenda.component.html b/src/app/pages/agenda/agenda.component.html
index 4287836..202ba90 100644
--- a/src/app/pages/agenda/agenda.component.html
+++ b/src/app/pages/agenda/agenda.component.html
@@ -127,8 +127,8 @@
{{ appointment.customer.firstName }} {{ appointment.customer.lastName }}
- {{ getFormattedTime(appointment.startHour, appointment.startMinute) }}
- - {{ getFormattedTime(appointment.endHour, appointment.endMinute) }}
+ {{ getFormattedTime(appointment.startDateTime.getHours(), appointment.startDateTime.getMinutes()) }}
+ - {{ getFormattedTime(appointment.endDateTime.getHours(), appointment.endDateTime.getMinutes()) }}
diff --git a/src/app/pages/agenda/agenda.component.ts b/src/app/pages/agenda/agenda.component.ts
index ca6d782..f57239d 100644
--- a/src/app/pages/agenda/agenda.component.ts
+++ b/src/app/pages/agenda/agenda.component.ts
@@ -81,9 +81,13 @@ export class AgendaComponent implements OnInit {
}
getAppointmentsForHour(hour: number) {
- return this.appointments.filter(appointment => appointment.startHour === hour);
+ return this.appointments.filter(appointment => {
+ const startDateTime = new Date(appointment.startDateTime);
+ return startDateTime.getHours() === hour;
+ });
}
+
getDate(): string {
const date = this.selectedDate
@@ -182,8 +186,8 @@ export class AgendaComponent implements OnInit {
getInlineStyles(appointment: AppointmentDto): { [key: string]: string } {
return {
'--duration': `${appointment.durationInMinutes}`,
- '--start-minute': `${appointment.startMinute}`,
- 'top': `${appointment.startMinute}px`, // Startpositie binnen het uur
+ '--start-minute': `${appointment.startDateTime.getMinutes()}`,
+ 'top': `${appointment.startDateTime.getMinutes()}px`, // Startpositie binnen het uur
'height': `${appointment.durationInMinutes}px`, // Hoogte over meerdere uren
};
}
@@ -193,8 +197,8 @@ export class AgendaComponent implements OnInit {
}
getAppointmentHeight(appointment: AppointmentDto): number {
- const startInMinutes = (appointment.startHour * 60) + appointment.startMinute;
- const endInMinutes = (appointment.endHour * 60) + appointment.endMinute;
+ const startInMinutes = (appointment.startDateTime.getHours() * 60) + appointment.startDateTime.getMinutes();
+ const endInMinutes = (appointment.endDateTime.getHours() * 60) + appointment.endDateTime.getMinutes();
return (endInMinutes - startInMinutes); // 50px per uur
}
diff --git a/src/app/services/appointment.service.ts b/src/app/services/appointment.service.ts
index 3fbea2c..4e11bec 100644
--- a/src/app/services/appointment.service.ts
+++ b/src/app/services/appointment.service.ts
@@ -1,9 +1,8 @@
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';
import {AppointmentDto} from '../models/appointment-dto';
+import {map} from 'rxjs';
@Injectable({
providedIn: 'root',
@@ -22,7 +21,15 @@ export class AppointmentService {
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