Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | 3x 10x 10x 1x 9x 2x 7x 6x 6x 1x 5x 3x 2x 5x 5x 1x 4x 3x 1x 4x 4x 2x 2x 1x 1x 4x 4x 1x 3x 2x 1x 6x 6x 2x 4x 3x 1x 4x 4x 1x 3x 2x 1x 14x 12x 12x 4x 2x 2x 2x 8x 12x 12x 2x 3x | /**
* Slot Assignment Service (Story 5.7 - Task 4b GREEN Phase)
*
* HTTP client for Slot Assignment APIs in Event Management Service
* Features:
* - Fetch unassigned sessions
* - Assign timing to sessions (drag-drop)
* - Bulk timing assignment
* - Conflict detection
*/
import apiClient from '@/services/api/apiClient';
import { AxiosError } from 'axios';
import type {
Session,
SessionTimingRequest,
BulkTimingRequest,
BulkTimingResponse,
ConflictAnalysisResponse,
} from '@/types/event.types';
import type { TimetableResponse } from '@/services/timetableService/timetableService';
/** Story 15.3: stable slot assignment mode. */
export type SlotAssignmentMode = 'ASSIGN' | 'INSERT' | 'SWAP';
/** Story 15.3: request body for the slotKey-addressed assignment endpoint. */
export interface SlotAssignmentRequestBody {
targetSlotKey: string;
mode: SlotAssignmentMode;
}
// API base path for slot assignment endpoints
const SLOT_ASSIGNMENT_API_PATH = '/events';
/**
* Slot Assignment Service Class
*
* Handles all HTTP requests to the Slot Assignment APIs
*/
class SlotAssignmentService {
/**
* Get sessions without timing (placeholder sessions)
*
* GET /api/v1/events/{eventCode}/sessions/unassigned
*
* @param eventCode - Event code (e.g., "BATbern142")
* @returns Array of unassigned sessions
*/
async getUnassignedSessions(eventCode: string): Promise<Session[]> {
try {
const response = await apiClient.get<Session[]>(
`${SLOT_ASSIGNMENT_API_PATH}/${eventCode}/sessions/unassigned`
);
return response.data;
} catch (error) {
// Re-throw AxiosError to preserve 401/403 auth errors
if (
error instanceof AxiosError &&
(error.response?.status === 401 || error.response?.status === 403)
) {
throw error;
}
throw this.transformError(error);
}
}
/**
* Assign timing to a session
*
* PATCH /api/v1/events/{eventCode}/sessions/{sessionSlug}/timing
*
* @param eventCode - Event code (e.g., "BATbern142")
* @param sessionSlug - Session slug identifier
* @param timing - Timing assignment request
* @returns Updated session with timing
*/
async assignSessionTiming(
eventCode: string,
sessionSlug: string,
timing: SessionTimingRequest
): Promise<Session> {
try {
const response = await apiClient.patch<Session>(
`${SLOT_ASSIGNMENT_API_PATH}/${eventCode}/sessions/${sessionSlug}/timing`,
timing
);
return response.data;
} catch (error) {
// Re-throw AxiosError to preserve 401/403 auth errors and 409 conflict response data
if (
error instanceof AxiosError &&
(error.response?.status === 401 ||
error.response?.status === 403 ||
error.response?.status === 409)
) {
throw error;
}
throw this.transformError(error);
}
}
/**
* Assign / insert / swap a speaker session by stable slot key (Story 15.3)
*
* POST /api/v1/events/{eventCode}/sessions/{sessionSlug}/slot
*
* @param eventCode Event code (e.g., "BATbern142")
* @param sessionSlug Dragged speaker session slug
* @param request Target slotKey + mode (ASSIGN | INSERT | SWAP)
* @returns The recomputed timetable
*/
async assignSessionToSlot(
eventCode: string,
sessionSlug: string,
request: SlotAssignmentRequestBody
): Promise<TimetableResponse> {
try {
const response = await apiClient.post<TimetableResponse>(
`${SLOT_ASSIGNMENT_API_PATH}/${eventCode}/sessions/${sessionSlug}/slot`,
request
);
return response.data;
} catch (error) {
// Preserve auth errors and the 409 (agenda-full / conflict) response body.
if (
error instanceof AxiosError &&
(error.response?.status === 401 ||
error.response?.status === 403 ||
error.response?.status === 409)
) {
throw error;
}
throw this.transformError(error);
}
}
/**
* Unassign a single session's slot — sends it back to the unassigned pool (Story 15.3).
*
* DELETE /api/v1/events/{eventCode}/sessions/{sessionSlug}/timing
*
* @param eventCode Event code (e.g., "BATbern142")
* @param sessionSlug Session slug to clear
* @returns The updated (now unassigned) session
*/
async unassignSessionTiming(eventCode: string, sessionSlug: string): Promise<Session> {
try {
const response = await apiClient.delete<Session>(
`${SLOT_ASSIGNMENT_API_PATH}/${eventCode}/sessions/${sessionSlug}/timing`
);
return response.data;
} catch (error) {
if (
error instanceof AxiosError &&
(error.response?.status === 401 || error.response?.status === 403)
) {
throw error;
}
throw this.transformError(error);
}
}
/**
* Bulk assign timing to multiple sessions
*
* POST /api/v1/events/{eventCode}/sessions/bulk-timing
*
* @param eventCode - Event code (e.g., "BATbern142")
* @param bulkRequest - Bulk timing assignment request
* @returns Bulk assignment result
*/
async bulkAssignTiming(
eventCode: string,
bulkRequest: BulkTimingRequest
): Promise<BulkTimingResponse> {
try {
const response = await apiClient.post<BulkTimingResponse>(
`${SLOT_ASSIGNMENT_API_PATH}/${eventCode}/sessions/bulk-timing`,
bulkRequest
);
return response.data;
} catch (error) {
// Re-throw AxiosError to preserve 401/403 auth errors and 409 conflict response data
if (
error instanceof AxiosError &&
(error.response?.status === 401 ||
error.response?.status === 403 ||
error.response?.status === 409)
) {
throw error;
}
throw this.transformError(error);
}
}
/**
* Detect session timing conflicts
*
* GET /api/v1/events/{eventCode}/sessions/conflicts
*
* @param eventCode - Event code (e.g., "BATbern142")
* @returns Conflict analysis response
*/
async detectConflicts(eventCode: string): Promise<ConflictAnalysisResponse> {
try {
const response = await apiClient.get<ConflictAnalysisResponse>(
`${SLOT_ASSIGNMENT_API_PATH}/${eventCode}/sessions/conflicts`
);
return response.data;
} catch (error) {
// Re-throw AxiosError to preserve 401/403 auth errors
if (
error instanceof AxiosError &&
(error.response?.status === 401 || error.response?.status === 403)
) {
throw error;
}
throw this.transformError(error);
}
}
/**
* Clear all session timings for an event
*
* DELETE /api/v1/events/{eventCode}/sessions/timing
*
* @param eventCode - Event code (e.g., "BATbern142")
* @returns Response with cleared count
*/
async clearAllTimings(eventCode: string): Promise<{ message: string; clearedCount: number }> {
try {
const response = await apiClient.delete<{ message: string; clearedCount: number }>(
`${SLOT_ASSIGNMENT_API_PATH}/${eventCode}/sessions/timing`
);
return response.data;
} catch (error) {
// Re-throw AxiosError to preserve 401/403 auth errors
if (
error instanceof AxiosError &&
(error.response?.status === 401 || error.response?.status === 403)
) {
throw error;
}
throw this.transformError(error);
}
}
/**
* Generate structural sessions (moderation, break, lunch) from event type config
*
* POST /api/v1/events/{eventCode}/sessions/structural
*
* @param eventCode - Event code (e.g., "BATbern142")
* @param overwrite - Whether to overwrite existing structural sessions (default false)
* @returns Array of created structural sessions
*/
async generateStructuralSessions(eventCode: string, overwrite = false): Promise<Session[]> {
try {
const response = await apiClient.post<Session[]>(
`${SLOT_ASSIGNMENT_API_PATH}/${eventCode}/sessions/structural`,
null,
{ params: { overwrite } }
);
return response.data;
} catch (error) {
if (
error instanceof AxiosError &&
(error.response?.status === 401 ||
error.response?.status === 403 ||
error.response?.status === 409)
) {
throw error;
}
throw this.transformError(error);
}
}
/**
* Auto-assign all unassigned sessions to available time slots
*
* POST /api/v1/events/{eventCode}/sessions/auto-assign
*
* @param eventCode - Event code (e.g., "BATbern142")
* @returns Response with assigned count
*/
async autoAssignTimings(eventCode: string): Promise<{ message: string; assignedCount: number }> {
try {
const response = await apiClient.post<{ message: string; assignedCount: number }>(
`${SLOT_ASSIGNMENT_API_PATH}/${eventCode}/sessions/auto-assign`
);
return response.data;
} catch (error) {
// Re-throw AxiosError to preserve 401/403 auth errors
if (
error instanceof AxiosError &&
(error.response?.status === 401 || error.response?.status === 403)
) {
throw error;
}
throw this.transformError(error);
}
}
/**
* Transform Axios errors into user-friendly error messages
*/
private transformError(error: unknown): Error {
if (error instanceof AxiosError) {
// Extract error message from response
const message =
error.response?.data?.message ||
error.response?.data?.error ||
error.message ||
'An unexpected error occurred';
// Handle specific error cases
if (error.response?.status === 404) {
if (message.includes('Event')) {
return new Error('Event not found');
}
Eif (message.includes('Session')) {
return new Error('Session not found');
}
}
// Include correlation ID if available (Story 1.9)
const correlationId = error.response?.headers?.['x-correlation-id'];
const errorMessage = correlationId
? `${message} (Correlation ID: ${correlationId})`
: message;
return new Error(errorMessage);
}
return error instanceof Error ? error : new Error('An unexpected error occurred');
}
}
// Export singleton instance
export const slotAssignmentService = new SlotAssignmentService();
|