refactor utils
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
11
src/utils/misc.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user