Refactor Schedules

This commit is contained in:
2024-04-29 12:54:54 -04:00
parent e1a784ef45
commit 43e68c8ae7
4 changed files with 151 additions and 146 deletions

View File

@@ -0,0 +1,115 @@
import { DateOptions, date } from 'quasar';
import { Boat, useBoatStore } from '../boat';
import type { StatusTypes, Timeblock, Reservation } from '../schedule.types';
export const weekdayBlocks = [
{
start: { time: '08:00', hour: 8, minute: 0 },
end: { time: '12:00', hour: 12, minute: 0 },
},
{
start: { time: '12:00', hour: 12, minute: 0 },
end: { time: '16:00', hour: 16, minute: 0 },
},
{
start: { time: '17:00', hour: 17, minute: 0 },
end: { time: '21:00', hour: 21, minute: 0 },
},
] as Timeblock[];
export const weekendBlocks = [
{
start: { time: '07:00', hour: 7, minute: 0 },
end: { time: '10:00', hour: 10, minute: 0 },
},
{
start: { time: '10:00', hour: 10, minute: 0 },
end: { time: '13:00', hour: 13, minute: 0 },
},
{
start: { time: '13:00', hour: 13, minute: 0 },
end: { time: '16:00', hour: 16, minute: 0 },
},
{
start: { time: '16:00', hour: 16, minute: 0 },
end: { time: '19:00', hour: 19, minute: 0 },
},
];
export function getSampleReservations(): Reservation[] {
const sampleData = [
{
id: 1,
user: 'John Smith',
start: '12:00',
end: '15:00',
boat: '1',
status: 'confirmed',
},
{
id: 2,
user: 'Bob Barker',
start: '18:00',
end: '21:00',
boat: '1',
status: 'confirmed',
},
{
id: 3,
user: 'Peter Parker',
start: '9:00',
end: '12:00',
boat: '2',
status: 'tentative',
},
{
id: 4,
user: 'Vince McMahon',
start: '15:00',
end: '18:00',
boat: '2',
status: 'pending',
},
{
id: 5,
user: 'Heather Graham',
start: '09:00',
end: '12:00',
boat: '3',
status: 'confirmed',
},
{
id: 6,
user: 'Lawrence Fishburne',
start: '18:00',
end: '21:00',
boat: '3',
},
];
const boatStore = useBoatStore();
const now = new Date();
const splitTime = (x: string): string[] => {
return x.split(':');
};
const makeOpts = (x: string[]): DateOptions => {
return {
hour: parseInt(x[0]),
minute: parseInt(x[1]),
seconds: 0,
milliseconds: 0,
};
};
return sampleData.map((entry): Reservation => {
const boat = <Boat>boatStore.boats.find((b) => b.$id == entry.boat);
return {
id: entry.id,
user: entry.user,
start: date.adjustDate(now, makeOpts(splitTime(entry.start))),
end: date.adjustDate(now, makeOpts(splitTime(entry.end))),
resource: boat,
reservationDate: now,
status: entry.status as StatusTypes,
};
});
}