refactor utils

This commit is contained in:
2024-05-13 12:31:27 -04:00
parent 78211a33ae
commit b0921ccf32
4 changed files with 15 additions and 17 deletions

View File

@@ -101,9 +101,9 @@ import { ref, computed, watch } from 'vue';
import { useAuthStore } from 'src/stores/auth'; import { useAuthStore } from 'src/stores/auth';
import { Boat, useBoatStore } from 'src/stores/boat'; import { Boat, useBoatStore } from 'src/stores/boat';
import { date } from 'quasar'; import { date } from 'quasar';
import { useScheduleStore } from 'src/stores/schedule';
import { Interval } from 'src/stores/schedule.types'; import { Interval } from 'src/stores/schedule.types';
import BoatScheduleTableComponent from 'src/components/scheduling/boat/BoatScheduleTableComponent.vue'; import BoatScheduleTableComponent from 'src/components/scheduling/boat/BoatScheduleTableComponent.vue';
import { getNewId } from 'src/utils/misc';
interface BookingForm { interface BookingForm {
bookingId: string; bookingId: string;
@@ -118,10 +118,9 @@ interface BookingForm {
const auth = useAuthStore(); const auth = useAuthStore();
const dateFormat = 'MMM D, YYYY h:mm A'; const dateFormat = 'MMM D, YYYY h:mm A';
const resourceView = ref(true); const resourceView = ref(true);
const scheduleStore = useScheduleStore();
const timeblock = ref<Interval>(); const timeblock = ref<Interval>();
const bookingForm = ref<BookingForm>({ const bookingForm = ref<BookingForm>({
bookingId: scheduleStore.getNewId(), bookingId: getNewId(),
name: auth.currentUser?.name, name: auth.currentUser?.name,
boat: <Boat | undefined>undefined, boat: <Boat | undefined>undefined,
startDate: date.formatDate(new Date(), dateFormat), startDate: date.formatDate(new Date(), dateFormat),

View File

@@ -145,9 +145,9 @@ import {
blocksOverlapped, blocksOverlapped,
buildInterval, buildInterval,
useScheduleStore, useScheduleStore,
buildISODate,
} from 'src/stores/schedule'; } from 'src/stores/schedule';
import { onMounted, ref } from 'vue'; import { onMounted, ref } from 'vue';
import { buildISODate } from 'src/utils/misc';
import type { import type {
Interval, Interval,
IntervalTemplate, IntervalTemplate,

View File

@@ -16,6 +16,7 @@ import {
} from './schedule.types'; } from './schedule.types';
import { AppwriteIds, databases } from 'src/boot/appwrite'; import { AppwriteIds, databases } from 'src/boot/appwrite';
import { ID, Models } from 'appwrite'; import { ID, Models } from 'appwrite';
import { buildISODate } from 'src/utils/misc';
export function arrayToTimeTuples(arr: string[]) { export function arrayToTimeTuples(arr: string[]) {
const timeTuples: TimeTuple[] = []; const timeTuples: TimeTuple[] = [];
@@ -65,10 +66,6 @@ export function copyIntervalTemplate(
}; };
} }
export function buildISODate(date: string, time: string | null): string {
return new Date(date + 'T' + time || '00:00').toISOString();
}
export function buildInterval( export function buildInterval(
resource: Boat, resource: Boat,
time: TimeTuple, time: TimeTuple,
@@ -212,14 +209,6 @@ export const useScheduleStore = defineStore('schedule', () => {
); );
}; };
const getNewId = (): string => {
return [...Array(20)]
.map(() => Math.floor(Math.random() * 16).toString(16))
.join('');
// Trivial placeholder
//return Math.max(...reservations.value.map((item) => item.id)) + 1;
};
const addOrCreateReservation = (reservation: Reservation) => { const addOrCreateReservation = (reservation: Reservation) => {
const index = reservations.value.findIndex( const index = reservations.value.findIndex(
(res) => res.id == reservation.id (res) => res.id == reservation.id
@@ -339,7 +328,6 @@ export const useScheduleStore = defineStore('schedule', () => {
getIntervals, getIntervals,
fetchIntervals, fetchIntervals,
fetchIntervalTemplates, fetchIntervalTemplates,
getNewId,
createInterval, createInterval,
updateInterval, updateInterval,
deleteInterval, deleteInterval,

11
src/utils/misc.ts Normal file
View File

@@ -0,0 +1,11 @@
export function buildISODate(date: string, time: string | null): string {
return new Date(date + 'T' + time || '00:00').toISOString();
}
export function getNewId(): string {
return [...Array(20)]
.map(() => Math.floor(Math.random() * 16).toString(16))
.join('');
// Trivial placeholder
//return Math.max(...reservations.value.map((item) => item.id)) + 1;
}