Introduces BaseEntityService and SyncPlugin to eliminate code duplication across entity services Improves: - Code reusability through inheritance and composition - Sync infrastructure for all entity types - Polymorphic sync status management - Reduced boilerplate code by ~75% Supports generic sync for Event, Booking, Customer, and Resource entities
92 lines
2.8 KiB
TypeScript
92 lines
2.8 KiB
TypeScript
import { ICustomer } from '../types/CustomerTypes';
|
|
import { EntityType } from '../types/CalendarTypes';
|
|
import { Configuration } from '../configurations/CalendarConfig';
|
|
import { IApiRepository } from './IApiRepository';
|
|
|
|
/**
|
|
* ApiCustomerRepository
|
|
* Handles communication with backend API for customers
|
|
*
|
|
* Implements IApiRepository<ICustomer> for generic sync infrastructure.
|
|
* Used by SyncManager to send queued customer operations to the server.
|
|
*/
|
|
export class ApiCustomerRepository implements IApiRepository<ICustomer> {
|
|
readonly entityType: EntityType = 'Customer';
|
|
private apiEndpoint: string;
|
|
|
|
constructor(config: Configuration) {
|
|
this.apiEndpoint = config.apiEndpoint;
|
|
}
|
|
|
|
/**
|
|
* Send create operation to API
|
|
*/
|
|
async sendCreate(customer: ICustomer): Promise<ICustomer> {
|
|
// TODO: Implement API call
|
|
// const response = await fetch(`${this.apiEndpoint}/customers`, {
|
|
// method: 'POST',
|
|
// headers: { 'Content-Type': 'application/json' },
|
|
// body: JSON.stringify(customer)
|
|
// });
|
|
//
|
|
// if (!response.ok) {
|
|
// throw new Error(`API create failed: ${response.statusText}`);
|
|
// }
|
|
//
|
|
// return await response.json();
|
|
|
|
throw new Error('ApiCustomerRepository.sendCreate not implemented yet');
|
|
}
|
|
|
|
/**
|
|
* Send update operation to API
|
|
*/
|
|
async sendUpdate(id: string, updates: Partial<ICustomer>): Promise<ICustomer> {
|
|
// TODO: Implement API call
|
|
// const response = await fetch(`${this.apiEndpoint}/customers/${id}`, {
|
|
// method: 'PATCH',
|
|
// headers: { 'Content-Type': 'application/json' },
|
|
// body: JSON.stringify(updates)
|
|
// });
|
|
//
|
|
// if (!response.ok) {
|
|
// throw new Error(`API update failed: ${response.statusText}`);
|
|
// }
|
|
//
|
|
// return await response.json();
|
|
|
|
throw new Error('ApiCustomerRepository.sendUpdate not implemented yet');
|
|
}
|
|
|
|
/**
|
|
* Send delete operation to API
|
|
*/
|
|
async sendDelete(id: string): Promise<void> {
|
|
// TODO: Implement API call
|
|
// const response = await fetch(`${this.apiEndpoint}/customers/${id}`, {
|
|
// method: 'DELETE'
|
|
// });
|
|
//
|
|
// if (!response.ok) {
|
|
// throw new Error(`API delete failed: ${response.statusText}`);
|
|
// }
|
|
|
|
throw new Error('ApiCustomerRepository.sendDelete not implemented yet');
|
|
}
|
|
|
|
/**
|
|
* Fetch all customers from API
|
|
*/
|
|
async fetchAll(): Promise<ICustomer[]> {
|
|
// TODO: Implement API call
|
|
// const response = await fetch(`${this.apiEndpoint}/customers`);
|
|
//
|
|
// if (!response.ok) {
|
|
// throw new Error(`API fetch failed: ${response.statusText}`);
|
|
// }
|
|
//
|
|
// return await response.json();
|
|
|
|
throw new Error('ApiCustomerRepository.fetchAll not implemented yet');
|
|
}
|
|
}
|