feat: introduce service-based availability filtering for collaborator schedules and overrides
This commit is contained in:
@@ -173,6 +173,14 @@ class SchedulesManager implements ISchedulesManager {
|
||||
return await this.schedules.find(filters);
|
||||
}
|
||||
|
||||
private isScheduleAvailableForService(schedule: ScheduleItem, serviceId?: string): boolean {
|
||||
if (!serviceId || !schedule.serviceScope || schedule.serviceScope === "all") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return schedule.serviceScope === "specific" && (schedule.serviceIds || []).includes(serviceId);
|
||||
}
|
||||
|
||||
private async getScheduleByFrom(data: AvailableSchedulesParams): Promise<ScheduleItem | null> {
|
||||
const schedule = await this.schedules.findOne({
|
||||
employeeId: data.employeeId,
|
||||
@@ -185,6 +193,9 @@ class SchedulesManager implements ISchedulesManager {
|
||||
if (horario.disabled) {
|
||||
continue;
|
||||
}
|
||||
if (!this.isScheduleAvailableForService(horario, data.serviceId)) {
|
||||
continue;
|
||||
}
|
||||
if (horario.from == data.from) {
|
||||
return horario;
|
||||
}
|
||||
@@ -236,6 +247,7 @@ class SchedulesManager implements ISchedulesManager {
|
||||
weekDay: data.weekDay,
|
||||
from: scheduleFrom.to,
|
||||
to: data.to,
|
||||
serviceId: data.serviceId,
|
||||
});
|
||||
|
||||
if (!scheduleTo) {
|
||||
|
||||
Reference in New Issue
Block a user