Prashikshak / Web /src /api /eventDay.api.ts
Abhisingh-18's picture
Initial commit: Prashikshak - disaster management training platform
9a92a42
Raw
History Blame Contribute Delete
5.29 kB
import api from './axiosInstance.api';
// Types
export interface IEventDayPhoto {
_id: string;
url: string;
publicId: string;
caption?: string;
uploadedBy: {
_id: string;
username: string;
};
uploadedAt: string;
}
export interface IEventDayAttendance {
_id: string;
user: {
_id: string;
username: string;
email: string;
profilePhoto?: string;
};
checkInTime: string;
checkInMethod: 'gps' | 'qr' | 'manual' | 'hotspot';
checkInLocation?: {
type: 'Point';
coordinates: [number, number];
};
verifiedBy?: {
_id: string;
username: string;
};
}
export interface IEventDay {
_id: string;
event: {
_id: string;
title: string;
code: string;
};
date: string;
dayNumber: number;
startTime: string; // Planned start time
endTime: string; // Planned end time
photos: IEventDayPhoto[];
attendance?: IEventDayAttendance[];
photoCount?: number;
attendanceCount?: number;
hasStarted: boolean; // Event day has been started
isCompleted: boolean;
completedAt?: string;
status?: 'green' | 'red' | 'blue'; // Calendar status
notes?: string;
weatherCondition?: string;
activitiesConducted?: string[];
incidentsReported?: string;
equipmentUsed?: string[];
}
// Get all days for an event
export const getEventDays = async (eventId: string): Promise<{ eventDays: IEventDay[]; stats: any }> => {
const response = await api.get(`/event-days/event/${eventId}`);
return response.data;
};
// Get specific day details
export const getEventDayDetails = async (eventDayId: string): Promise<IEventDay> => {
const response = await api.get(`/event-days/${eventDayId}`);
return response.data;
};
// Upload photos to a day
export const uploadDayPhotos = async (
eventDayId: string,
files: File[],
captions?: string[]
): Promise<{ message: string; photos: IEventDayPhoto[] }> => {
const formData = new FormData();
files.forEach((file) => {
formData.append('photos', file);
});
if (captions) {
captions.forEach((caption) => {
formData.append('captions', caption);
});
}
const response = await api.post(`/event-days/${eventDayId}/photos`, formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
return response.data;
};
// Delete a photo
export const deleteDayPhoto = async (eventDayId: string, photoId: string): Promise<{ message: string }> => {
const response = await api.delete(`/event-days/${eventDayId}/photos/${photoId}`);
return response.data;
};
// Mark attendance
export const markAttendance = async (
eventDayId: string,
userId: string,
checkInMethod: 'gps' | 'qr' | 'manual' | 'hotspot',
location?: { latitude: number; longitude: number }
): Promise<{ message: string; attendance: IEventDayAttendance }> => {
const response = await api.post(
`/event-days/${eventDayId}/attendance`,
{
userId,
checkInMethod,
...location,
}
);
return response.data;
};
// Update day metadata
export const updateDayMetadata = async (
eventDayId: string,
metadata: {
notes?: string;
weatherCondition?: string;
activitiesConducted?: string[];
incidentsReported?: string;
equipmentUsed?: string[];
isCompleted?: boolean;
}
): Promise<{ message: string; eventDay: IEventDay }> => {
const response = await api.patch(`/event-days/${eventDayId}`, metadata);
return response.data;
};
// Get attendance report for entire event
export const getAttendanceReport = async (eventId: string): Promise<any> => {
const response = await api.get(`/event-days/event/${eventId}/attendance-report`);
return response.data;
};
// Start event day
export const startEventDay = async (eventDayId: string): Promise<{ message: string; eventDay: Partial<IEventDay> }> => {
const response = await api.post(`/event-days/${eventDayId}/start`, {});
return response.data;
};
// End event day
export const endEventDay = async (eventDayId: string): Promise<{ message: string; eventDay: Partial<IEventDay> }> => {
const response = await api.post(`/event-days/${eventDayId}/end`, {});
return response.data;
};
// Get event day status (green/red/blue)
export const getEventDayStatus = async (eventDayId: string): Promise<{ status: 'green' | 'red' | 'blue'; message: string; eventDay: Partial<IEventDay> }> => {
const response = await api.get(`/event-days/${eventDayId}/status`);
return response.data;
};
// Bulk mark attendance (hotspot)
export const bulkMarkAttendance = async (
eventDayId: string,
userIds: string[],
checkInMethod: 'gps' | 'qr' | 'manual' | 'hotspot' = 'hotspot',
location?: { latitude: number; longitude: number }
): Promise<{ message: string; results: { marked: string[]; alreadyMarked: string[]; notParticipant: string[] } }> => {
const response = await api.post(
`/event-days/${eventDayId}/attendance/bulk`,
{
userIds,
checkInMethod,
...location,
}
);
return response.data;
};