|
|
|
@ -10,8 +10,8 @@ import Trainer from "../interfaces/trainer";
|
|
|
|
import { ReservedTimeslots, Timeslot, WeeklyTimeslot } from "../interfaces/timeslot";
|
|
|
|
import { ReservedTimeslots, Timeslot, WeeklyTimeslot } from "../interfaces/timeslot";
|
|
|
|
import { idSchema, timeSchema } from "../schemas";
|
|
|
|
import { idSchema, timeSchema } from "../schemas";
|
|
|
|
|
|
|
|
|
|
|
|
dayjs.extend(isoWeek)
|
|
|
|
dayjs.extend(isoWeek);
|
|
|
|
dayjs.extend(utc)
|
|
|
|
dayjs.extend(utc);
|
|
|
|
|
|
|
|
|
|
|
|
const router: Router = express.Router();
|
|
|
|
const router: Router = express.Router();
|
|
|
|
|
|
|
|
|
|
|
|
@ -29,8 +29,8 @@ const timeslotFiltersSchema = Joi.object({
|
|
|
|
interface TimeslotFilters {
|
|
|
|
interface TimeslotFilters {
|
|
|
|
trainer?: number[]
|
|
|
|
trainer?: number[]
|
|
|
|
center?: number
|
|
|
|
center?: number
|
|
|
|
startDate: Date
|
|
|
|
startDate: string
|
|
|
|
endDate: Date
|
|
|
|
endDate: string
|
|
|
|
startTime?: string
|
|
|
|
startTime?: string
|
|
|
|
endTime?: string
|
|
|
|
endTime?: string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -85,8 +85,8 @@ router.get("/timeslot", async (req: Request, res: Response) => {
|
|
|
|
'end_time', end_time
|
|
|
|
'end_time', end_time
|
|
|
|
)) FROM public.reserved_timeslots
|
|
|
|
)) FROM public.reserved_timeslots
|
|
|
|
WHERE
|
|
|
|
WHERE
|
|
|
|
(start_time between '2023-04-16' AND '2023-04-20'
|
|
|
|
(start_time between $1 AND $2
|
|
|
|
OR end_time between '2023-04-16' AND '2023-04-20')
|
|
|
|
OR end_time between $1 AND $2)
|
|
|
|
AND weekly_timeslots.trainer_id = reserved_timeslots.trainer_id
|
|
|
|
AND weekly_timeslots.trainer_id = reserved_timeslots.trainer_id
|
|
|
|
) as reserved_timeslots
|
|
|
|
) as reserved_timeslots
|
|
|
|
FROM
|
|
|
|
FROM
|
|
|
|
@ -95,9 +95,9 @@ router.get("/timeslot", async (req: Request, res: Response) => {
|
|
|
|
JOIN users ON trainers.user_id = users.id
|
|
|
|
JOIN users ON trainers.user_id = users.id
|
|
|
|
JOIN centers ON trainers.center_id = centers.id
|
|
|
|
JOIN centers ON trainers.center_id = centers.id
|
|
|
|
WHERE
|
|
|
|
WHERE
|
|
|
|
((trainer_id = ANY($1)) OR $2)
|
|
|
|
((trainer_id = ANY($3)) OR $4)
|
|
|
|
AND (day_of_week = ANY($3))
|
|
|
|
AND (day_of_week = ANY($5))
|
|
|
|
AND (trainers.center_id = $4 OR $5)
|
|
|
|
AND (trainers.center_id = $6 OR $7)
|
|
|
|
GROUP BY
|
|
|
|
GROUP BY
|
|
|
|
weekly_timeslots.trainer_id,
|
|
|
|
weekly_timeslots.trainer_id,
|
|
|
|
users.first_name,
|
|
|
|
users.first_name,
|
|
|
|
@ -106,6 +106,8 @@ router.get("/timeslot", async (req: Request, res: Response) => {
|
|
|
|
centers.name,
|
|
|
|
centers.name,
|
|
|
|
trainer_id;
|
|
|
|
trainer_id;
|
|
|
|
`, [
|
|
|
|
`, [
|
|
|
|
|
|
|
|
new Date(timeslotFilters.startDate).toISOString(),
|
|
|
|
|
|
|
|
new Date(timeslotFilters.endDate).toISOString(),
|
|
|
|
timeslotFilters.trainer !== undefined ? timeslotFilters.trainer : [1],
|
|
|
|
timeslotFilters.trainer !== undefined ? timeslotFilters.trainer : [1],
|
|
|
|
timeslotFilters.trainer === undefined,
|
|
|
|
timeslotFilters.trainer === undefined,
|
|
|
|
weekdays,
|
|
|
|
weekdays,
|
|
|
|
@ -125,7 +127,7 @@ router.get("/timeslot", async (req: Request, res: Response) => {
|
|
|
|
|
|
|
|
|
|
|
|
for (let day: dayjs.Dayjs = filterStartDate; !day.isAfter(filterEndDate); day = day.add(1, "day")) {
|
|
|
|
for (let day: dayjs.Dayjs = filterStartDate; !day.isAfter(filterEndDate); day = day.add(1, "day")) {
|
|
|
|
const weekDay = day.isoWeekday();
|
|
|
|
const weekDay = day.isoWeekday();
|
|
|
|
const reservedTimeslots = trainer.reserved_timeslots;
|
|
|
|
const reservedTimeslots = trainer.reserved_timeslots !== null ? trainer.reserved_timeslots : [];
|
|
|
|
|
|
|
|
|
|
|
|
timeslots: for (const timeslot of trainer.timeslots) {
|
|
|
|
timeslots: for (const timeslot of trainer.timeslots) {
|
|
|
|
if (timeslot.day_of_week !== weekDay)
|
|
|
|
if (timeslot.day_of_week !== weekDay)
|
|
|
|
|