Skip to content

Commit

Permalink
Update event API with express checkin route
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorkw7 committed Jan 16, 2024
1 parent 6dd185c commit 8bf036e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/lib/api/EventAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AttendEventRequest, Event } from '@/lib/types/apiRequests';
import {
AttendEventResponse,
CreateEventResponse,
ExpressCheckInResponse,
GetAllEventsResponse,
GetAttendancesForUserResponse,
GetFutureEventsResponse,
Expand Down Expand Up @@ -73,7 +74,7 @@ export const getAllEvents = async (): Promise<PublicEvent[]> => {
};

export const getAttendancesForUser = async (token: string): Promise<PublicAttendance[]> => {
const requestUrl = `${config.api.baseUrl}${config.api.endpoints.attendance}`;
const requestUrl = `${config.api.baseUrl}${config.api.endpoints.attendance.attendance}`;

const response = await axios.get<GetAttendancesForUserResponse>(requestUrl, {
headers: {
Expand All @@ -88,7 +89,7 @@ export const attendEvent = async (
token: string,
attendanceCode: string
): Promise<AttendEventResponse> => {
const requestUrl = `${config.api.baseUrl}${config.api.endpoints.attendance}`;
const requestUrl = `${config.api.baseUrl}${config.api.endpoints.attendance.attendance}`;

const requestBody = { attendanceCode, asStaff: false } as AttendEventRequest;

Expand All @@ -101,6 +102,20 @@ export const attendEvent = async (
return response.data;
};

export const expressCheckin = async (
attendanceCode: string,
email: string
): Promise<ExpressCheckInResponse> => {
const requestUrl = `${config.api.baseUrl}${config.api.endpoints.attendance.expressCheckIn}`;
console.log('requestUrL', requestUrl);

const requestBody = { attendanceCode, email } as AttendEventRequest;

const response = await axios.post<ExpressCheckInResponse>(requestUrl, requestBody);

return response.data;
};

export const createEvent = async (token: string, event: Event): Promise<PublicEvent> => {
const requestUrl = `${config.api.baseUrl}${config.api.endpoints.event.event}`;

Expand Down
6 changes: 5 additions & 1 deletion src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ const config = {
future: '/event/future',
picture: '/event/picture',
},
attendance: '/attendance',
attendance: {
attendance: '/attendance',
expressCheckIn: '/attendance/expressCheckin',
},
leaderboard: '/leaderboard',
store: {
collection: '/merch/collection',
Expand Down Expand Up @@ -71,6 +74,7 @@ const config = {
},
homeRoute: '/',
eventsRoute: '/events',
expressCheckin: '/express',
loginRoute: '/login',
logoutRoute: '/logout',
leaderboardRoute: '/leaderboard',
Expand Down
21 changes: 20 additions & 1 deletion src/lib/managers/EventManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { EventAPI } from '@/lib/api';
import type { APIHandlerProps, AuthAPIHandlerProps } from '@/lib/types';
import type { AttendEventRequest, GetEventRequest } from '@/lib/types/apiRequests';
import type {
AttendEventRequest,
ExpressCheckInRequest,
GetEventRequest,
} from '@/lib/types/apiRequests';
import type { CustomErrorBody, PublicEvent } from '@/lib/types/apiResponses';

/**
Expand Down Expand Up @@ -57,3 +61,18 @@ export const attendEvent = async (
return e.response.data.error;
}
};

export const expressCheckIn = async (
data: ExpressCheckInRequest & APIHandlerProps
): Promise<PublicEvent | CustomErrorBody> => {
const { email, attendanceCode, onSuccessCallback, onFailCallback } = data;

try {
const response = await EventAPI.expressCheckin(email, attendanceCode);
onSuccessCallback?.(response.event);
return response.event;
} catch (e: any) {
onFailCallback?.(e.response.data.error);
return e.response.data.error;
}
};
5 changes: 5 additions & 0 deletions src/lib/types/apiRequests.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ export interface AttendEventRequest {
asStaff?: boolean;
}

export interface ExpressCheckInRequest {
attendanceCode: string;
email: string;
}

export interface SubmitEventFeedbackRequest {
feedback: string[];
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/types/apiResponses.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export interface AttendEventResponse extends ApiResponse {
event: PublicEvent;
}

export interface ExpressCheckInResponse extends ApiResponse {
event: PublicEvent;
}

// AUTH

export interface RegistrationResponse extends ApiResponse {
Expand Down

0 comments on commit 8bf036e

Please sign in to comment.