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

View File

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

View File

@@ -16,6 +16,7 @@ import {
} from './schedule.types';
import { AppwriteIds, databases } from 'src/boot/appwrite';
import { ID, Models } from 'appwrite';
import { buildISODate } from 'src/utils/misc';
export function arrayToTimeTuples(arr: string[]) {
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(
resource: Boat,
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 index = reservations.value.findIndex(
(res) => res.id == reservation.id
@@ -339,7 +328,6 @@ export const useScheduleStore = defineStore('schedule', () => {
getIntervals,
fetchIntervals,
fetchIntervalTemplates,
getNewId,
createInterval,
updateInterval,
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;
}