feat: add events app + "multi-tenants" aka multi-events
This commit is contained in:
@@ -37,12 +37,28 @@ interface SubmissionStats {
|
||||
|
||||
// API Service Class
|
||||
export class ApiService {
|
||||
private eventPath: string | null = null
|
||||
|
||||
// Every endpoint this service calls is event-scoped (/api/events/{event_path}/...),
|
||||
// so the owning page sets this once (via provideEventPath()'s value) before any
|
||||
// request is made, instead of threading eventPath through every method signature.
|
||||
setEventPath(eventPath: string) {
|
||||
this.eventPath = eventPath
|
||||
}
|
||||
|
||||
private buildUrl(endpoint: string): string {
|
||||
if (!this.eventPath) {
|
||||
throw new Error('ApiService.setEventPath() must be called before making requests')
|
||||
}
|
||||
return `${API_BASE_URL}/events/${this.eventPath}${endpoint}`
|
||||
}
|
||||
|
||||
private async request<T>(
|
||||
endpoint: string,
|
||||
options: RequestInit = {}
|
||||
): Promise<ApiResponse<T>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
|
||||
const response = await fetch(this.buildUrl(endpoint), {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers,
|
||||
@@ -76,7 +92,7 @@ export class ApiService {
|
||||
formData: FormData
|
||||
): Promise<ApiResponse<T>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
|
||||
const response = await fetch(this.buildUrl(endpoint), {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user