Sets up calendar package with core infrastructure
Adds core calendar package components including: - Base services for events, resources, and settings - Calendar app and orchestrator - Build and bundling configuration - IndexedDB storage setup Prepares foundational architecture for calendar functionality
This commit is contained in:
parent
12e7594f30
commit
ceb44446f0
97 changed files with 13858 additions and 1 deletions
75
packages/calendar/src/extensions/bookings/BookingService.ts
Normal file
75
packages/calendar/src/extensions/bookings/BookingService.ts
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import { IBooking, EntityType, IEventBus, BookingStatus } from '../../types/CalendarTypes';
|
||||
import { BookingStore } from './BookingStore';
|
||||
import { BaseEntityService } from '../../storage/BaseEntityService';
|
||||
import { IndexedDBContext } from '../../storage/IndexedDBContext';
|
||||
|
||||
/**
|
||||
* BookingService - CRUD operations for bookings in IndexedDB
|
||||
*/
|
||||
export class BookingService extends BaseEntityService<IBooking> {
|
||||
readonly storeName = BookingStore.STORE_NAME;
|
||||
readonly entityType: EntityType = 'Booking';
|
||||
|
||||
constructor(context: IndexedDBContext, eventBus: IEventBus) {
|
||||
super(context, eventBus);
|
||||
}
|
||||
|
||||
protected serialize(booking: IBooking): unknown {
|
||||
return {
|
||||
...booking,
|
||||
createdAt: booking.createdAt.toISOString()
|
||||
};
|
||||
}
|
||||
|
||||
protected deserialize(data: unknown): IBooking {
|
||||
const raw = data as Record<string, unknown>;
|
||||
return {
|
||||
...raw,
|
||||
createdAt: new Date(raw.createdAt as string)
|
||||
} as IBooking;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bookings for a customer
|
||||
*/
|
||||
async getByCustomer(customerId: string): Promise<IBooking[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const transaction = this.db.transaction([this.storeName], 'readonly');
|
||||
const store = transaction.objectStore(this.storeName);
|
||||
const index = store.index('customerId');
|
||||
const request = index.getAll(customerId);
|
||||
|
||||
request.onsuccess = () => {
|
||||
const data = request.result as unknown[];
|
||||
const bookings = data.map(item => this.deserialize(item));
|
||||
resolve(bookings);
|
||||
};
|
||||
|
||||
request.onerror = () => {
|
||||
reject(new Error(`Failed to get bookings for customer ${customerId}: ${request.error}`));
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bookings by status
|
||||
*/
|
||||
async getByStatus(status: BookingStatus): Promise<IBooking[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const transaction = this.db.transaction([this.storeName], 'readonly');
|
||||
const store = transaction.objectStore(this.storeName);
|
||||
const index = store.index('status');
|
||||
const request = index.getAll(status);
|
||||
|
||||
request.onsuccess = () => {
|
||||
const data = request.result as unknown[];
|
||||
const bookings = data.map(item => this.deserialize(item));
|
||||
resolve(bookings);
|
||||
};
|
||||
|
||||
request.onerror = () => {
|
||||
reject(new Error(`Failed to get bookings with status ${status}: ${request.error}`));
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue