-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initialize db * Update .gitignore to ignore local env * Add dockerfile for db setup * Add nx commands for db setup * Change docker container name, add trigram index for event name * Implement api endpoints * Attempt to implement calendar widget Only the outline, hardcoded values * Add calendar event display and correct margins * Implement events page styling * Interface with backend, implement admin functionality * Implement event tagging - Updated PUT /events endpoint to also update tags - Scroll overflow for calendar * Add prod env vars * Disable admin enpoints temporarily Until auth service is developed * Refector to Chalice * Fix project structure to allow Chalice to deploy * Add Nx command for serving locally through Chalice * Fix error when installing dependencies for event service * Refactor to use UUID instead of serial * Fix missing semicolons in sql files * Update nx deploy command to work with chalice * Outline event service mobile list * Add styling for event service mobile list * Use cockroachdb * Connect event calendar to API * Show events in mobile in calendar * Fix mobile view transition bugs, show pinned events with toggle * Uncomment admin endpoints, add RBAC * Implement API auth on frontend * Add delete event endpoint, fix add event endpoint when undefined params * Fix leaderboard and other battlepas API (move to nextjs api routes) * Redesign, cherry pick from Adam's branch * Update .env.example to include events api * Update package.json
- Loading branch information
1 parent
9c28eee
commit 1605307
Showing
48 changed files
with
4,869 additions
and
1,355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
import { getEnv } from '@hibiscus/env'; | ||
import axios, { AxiosError } from 'axios'; | ||
|
||
// Type definitions | ||
|
||
export type Event = { | ||
eventId: string; | ||
eventName: string; | ||
startTime: Date; | ||
endTime: Date; | ||
location: string; | ||
description?: string; | ||
eventTags?: string[]; | ||
industryTags?: string[]; | ||
bpPoints: number; | ||
}; | ||
|
||
export class EventServiceError extends Error { | ||
constructor(message?: string) { | ||
super(message ?? 'Unknown error occured'); | ||
} | ||
|
||
static handleAxiosError(e: AxiosError): EventServiceError { | ||
if ( | ||
e.response && | ||
typeof e.response.data === 'object' && | ||
'error' in e.response.data && | ||
typeof e.response.data.error === 'string' | ||
) { | ||
return new EventServiceError(e.response.data.error); | ||
} else if (e.response) { | ||
return new EventServiceError('Unknown API error occured'); | ||
} else if (e.request) { | ||
return new EventServiceError( | ||
'The request was made but no response was received' | ||
); | ||
} else { | ||
return new EventServiceError(e.message); | ||
} | ||
} | ||
} | ||
|
||
// Util functions | ||
export function isSameDate(date1: Date, date2: Date): boolean { | ||
return ( | ||
date1.getFullYear() === date2.getFullYear() && | ||
date1.getMonth() === date2.getMonth() && | ||
date1.getDate() === date2.getDate() | ||
); | ||
} | ||
|
||
export function getDayDate(d: Date): Date { | ||
return new Date(d.getFullYear(), d.getMonth(), d.getDate()); | ||
} | ||
|
||
// Event service API client | ||
export async function getEvent( | ||
eventId: string, | ||
accessToken: string | ||
): Promise<Event> { | ||
const apiUrl = getEnv().Hibiscus.Events.ApiUrl; | ||
|
||
try { | ||
const res = await axios(`${apiUrl}/events/${eventId}`, { | ||
method: 'GET', | ||
headers: { Authorization: `Bearer ${accessToken}` }, | ||
}); | ||
const event = res.data; | ||
event.startTime = new Date(event.startTime); | ||
event.endTime = new Date(event.endTime); | ||
return event; | ||
} catch (e) { | ||
if (axios.isAxiosError(e)) { | ||
throw EventServiceError.handleAxiosError(e); | ||
} else { | ||
throw new EventServiceError(); | ||
} | ||
} | ||
} | ||
|
||
export async function getAllEvents(accessToken: string): Promise<Event[]> { | ||
const apiUrl = getEnv().Hibiscus.Events.ApiUrl; | ||
|
||
// Display all events after Sep 1 2023 | ||
const startDate = new Date(2023, 8, 1).toISOString(); | ||
|
||
try { | ||
const res = await axios(`${apiUrl}/events?after=${startDate}&pageSize=-1`, { | ||
method: 'GET', | ||
headers: { Authorization: `Bearer ${accessToken}` }, | ||
}); | ||
const events = res.data.events; | ||
for (const e of events) { | ||
e.startTime = new Date(e.startTime); | ||
e.endTime = new Date(e.endTime); | ||
} | ||
return events; | ||
} catch (e) { | ||
if (axios.isAxiosError(e)) { | ||
throw EventServiceError.handleAxiosError(e); | ||
} else { | ||
throw new EventServiceError(); | ||
} | ||
} | ||
} | ||
|
||
export async function getPinnedEvents( | ||
userId: string, | ||
accessToken: string | ||
): Promise<Event[]> { | ||
const apiUrl = getEnv().Hibiscus.Events.ApiUrl; | ||
|
||
try { | ||
const res = await axios(`${apiUrl}/events/pinned-events/${userId}`, { | ||
method: 'GET', | ||
headers: { Authorization: `Bearer ${accessToken}` }, | ||
}); | ||
const events = res.data.pinnedEvents; | ||
for (const e of events) { | ||
e.startTime = new Date(e.startTime); | ||
e.endTime = new Date(e.endTime); | ||
} | ||
return events; | ||
} catch (e) { | ||
if (axios.isAxiosError(e)) { | ||
throw EventServiceError.handleAxiosError(e); | ||
} else { | ||
throw new EventServiceError(); | ||
} | ||
} | ||
} | ||
|
||
export async function pinEvent( | ||
userId: string, | ||
eventId: string, | ||
accessToken: string | ||
): Promise<number> { | ||
const apiUrl = getEnv().Hibiscus.Events.ApiUrl; | ||
|
||
try { | ||
const res = await axios(`${apiUrl}/events/pinned-events/${userId}`, { | ||
method: 'POST', | ||
headers: { Authorization: `Bearer ${accessToken}` }, | ||
data: { | ||
pin_event: eventId, | ||
}, | ||
}); | ||
const pinned = res.data.pinned_event; | ||
return pinned; | ||
} catch (e) { | ||
if (axios.isAxiosError(e)) { | ||
throw EventServiceError.handleAxiosError(e); | ||
} else { | ||
throw new EventServiceError(); | ||
} | ||
} | ||
} | ||
|
||
export async function unpinEvent( | ||
userId: string, | ||
eventId: string, | ||
accessToken: string | ||
): Promise<number> { | ||
const apiUrl = getEnv().Hibiscus.Events.ApiUrl; | ||
|
||
try { | ||
const res = await axios(`${apiUrl}/events/pinned-events/${userId}`, { | ||
method: 'DELETE', | ||
headers: { Authorization: `Bearer ${accessToken}` }, | ||
data: { | ||
unpin_event: eventId, | ||
}, | ||
}); | ||
const unpinned = res.data.unpinned_event; | ||
return unpinned; | ||
} catch (e) { | ||
if (axios.isAxiosError(e)) { | ||
throw EventServiceError.handleAxiosError(e); | ||
} else { | ||
throw new EventServiceError(); | ||
} | ||
} | ||
} | ||
|
||
export async function updateEvent( | ||
eventId: string, | ||
props: Partial<Event>, | ||
accessToken: string | ||
): Promise<Event> { | ||
const apiUrl = getEnv().Hibiscus.Events.ApiUrl; | ||
|
||
try { | ||
const res = await axios(`${apiUrl}/events/${eventId}`, { | ||
method: 'PUT', | ||
headers: { Authorization: `Bearer ${accessToken}` }, | ||
data: { | ||
...props, | ||
}, | ||
}); | ||
const event = res.data; | ||
return event; | ||
} catch (e) { | ||
if (axios.isAxiosError(e)) { | ||
throw EventServiceError.handleAxiosError(e); | ||
} else { | ||
throw new EventServiceError(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
1605307
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
pointr – ./
pointr-git-main-hacksc.vercel.app
pointr-hacksc.vercel.app
pointr.vercel.app
www.hack.sc
1605307
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
recruitment – ./
recruitment-git-main-hacksc.vercel.app
recruitment-hacksc.vercel.app
1605307
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
www-2023 – ./
www-2023-hacksc.vercel.app
2023.hacksc.com
www-2023-git-main-hacksc.vercel.app
www-2023.vercel.app
1605307
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
dashboard – ./
dashboard-sable-sigma.vercel.app
dashboard-git-main-hacksc.vercel.app
dashboard-hacksc.vercel.app
dashboard.hacksc.com