Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Commit

Permalink
fix: run lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KenNoYu committed Aug 13, 2024
1 parent 0705fa8 commit 155bced
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 56 deletions.
4 changes: 1 addition & 3 deletions client/src/pages/user/homepage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ const Home: PageComponent = (props) => {
<div className="p-6">
<a href="/feedback" className="block bg-primary-dark">
<img src=""></img>
<p className="p-6 font-semibold">
Provide Your Feedback
</p>
<p className="p-6 font-semibold">Provide Your Feedback</p>
</a>
</div>
<div className="p-6">
Expand Down
23 changes: 17 additions & 6 deletions client/src/pages/user/join-events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ const EventJoin: PageComponent = () => {
<Button
variant="default"
className="mx-auto mt-5 !bg-primary-light px-6 py-5 text-base font-semibold !text-text-dark"
onClick={() => {joinEvent(event.id, user.id); setShowModal(true)}}
onClick={() => {
joinEvent(event.id, user.id);
setShowModal(true);
}}
>
Join
</Button>
Expand All @@ -105,10 +108,18 @@ const EventJoin: PageComponent = () => {
},
)}
>
<div className="relative flex flex-col size-fit items-center justify-center rounded-lg p-10">
<h2 className='text-lg font-semibold mb-4 underline'>Registration For Event</h2>
<p className='text-center mb-6'>You have successfully registered for: {event.title}</p>
<InternalLink href='/events' className='font-semibold'>
<div className="relative flex size-fit flex-col items-center justify-center rounded-lg p-10">
<h2 className="mb-4 text-lg font-semibold underline">
Registration For Event
</h2>
<p className="mb-6 text-center">
You have successfully registered for:{' '}
{event.title}
</p>
<InternalLink
href="/events"
className="font-semibold"
>
Back To Events
</InternalLink>
{/* Close button */}
Expand Down Expand Up @@ -136,7 +147,7 @@ const EventJoin: PageComponent = () => {
</div>
</>
))}
</div >
</div>
) : (
<p>Event Not found</p>
)}
Expand Down
72 changes: 40 additions & 32 deletions client/src/pages/user/my-events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ const EventView: PageComponent = () => {
setEvents(response.data);
} catch (err) {
setError('Error retrieveing event! Please try again later.');
console.error('Fetching error:', err);
console.log(error);
console.log(err);
}
};

Expand All @@ -63,8 +62,8 @@ const EventView: PageComponent = () => {
setShowModal(false);
window.location.href = '/my-events';
} catch (err) {
setError('Error deleting event! Please try again later.');
console.error('Delete error:', err);
setError('Error leaving event! Please try again later.');
console.log(error);
}
};

Expand Down Expand Up @@ -98,34 +97,43 @@ const EventView: PageComponent = () => {
Leave
</Button>
<div
className={cn(
'left-1/2 -translate-x-1/2 top-1/2 transition-all flex -translate-y-1/2 flex-col items-center justify-center rounded-md bg-accent-dark drop-shadow w-4/5',
{
absolute: showModal,
hidden: !showModal,
'opatity-0': !showModal,
'opacity-100': showModal,
},
)}
>
<div className="relative flex flex-col size-fit items-center justify-center rounded-lg p-10">
<h2 className='text-lg font-semibold mb-4 underline'>Leaving Event</h2>
<p className='text-center mb-6'>Are you sure you want to leave the event: {event.title}?</p>
<Button variant="destructive" className='font-semibold' onClick={ () => leaveEvent(event.id, user.id)}>
Confirm
</Button>
{/* Close button */}
<Button
onClick={() => setShowModal(false)}
className="absolute right-1 top-1"
size="icon"
variant="ghost"
>
<X className="size-6 text-red-500 drop-shadow" />
</Button>
className={cn(
'left-1/2 -translate-x-1/2 top-1/2 transition-all flex -translate-y-1/2 flex-col items-center justify-center rounded-md bg-accent-dark drop-shadow w-4/5',
{
absolute: showModal,
hidden: !showModal,
'opatity-0': !showModal,
'opacity-100': showModal,
},
)}
>
<div className="relative flex size-fit flex-col items-center justify-center rounded-lg p-10">
<h2 className="mb-4 text-lg font-semibold underline">
Leaving Event
</h2>
<p className="mb-6 text-center">
Are you sure you want to leave the event:{' '}
{event.title}?
</p>
<Button
variant="destructive"
className="font-semibold"
onClick={() => leaveEvent(event.id, user.id)}
>
Confirm
</Button>
{/* Close button */}
<Button
onClick={() => setShowModal(false)}
className="absolute right-1 top-1"
size="icon"
variant="ghost"
>
<X className="size-6 text-red-500 drop-shadow" />
</Button>
</div>
</div>
</div>
</>
</>
) : (
<p>Cannot leave when u are not logged in</p>
)}
Expand All @@ -136,7 +144,7 @@ const EventView: PageComponent = () => {
))}
</div>
) : (
<p className='mx-auto'>You have not joined any events yet!</p>
<p className="mx-auto">You have not joined any events yet!</p>
)}
</div>
);
Expand Down
46 changes: 31 additions & 15 deletions server/src/v1/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export const getAnEvent: IAuthedRouteHandler = async (req, res) => {
const id = parseInt(req.params.id, 10);

// Fetch a specific event by ID
const events = await db.select().from(eventTable).where(eq(eventTable.id, id));
const events = await db
.select()
.from(eventTable)
.where(eq(eventTable.id, id));

// Check if events were found
if (events.length === 0) {
Expand Down Expand Up @@ -89,10 +92,13 @@ export const joinEvent: IAuthedRouteHandler = async (req, res) => {
// get event ID from query parameter
const eventId = parseInt(req.params.id, 10);
// get user ID
const userId = req.user.id
const userId = req.user.id;

// Fetch a specific event by ID
const event = await db.select().from(eventTable).where(eq(eventTable.id, eventId));
const event = await db
.select()
.from(eventTable)
.where(eq(eventTable.id, eventId));

// Check if events were found
if (event.length === 0) {
Expand All @@ -103,8 +109,12 @@ export const joinEvent: IAuthedRouteHandler = async (req, res) => {
}

// Check if the user is already joined to the event
const existingJoin = await db.select().from(usersToEvent)
.where(and(eq(usersToEvent.eventId, eventId), eq(usersToEvent.userId, userId)))
const existingJoin = await db
.select()
.from(usersToEvent)
.where(
and(eq(usersToEvent.eventId, eventId), eq(usersToEvent.userId, userId)),
);

if (existingJoin.length > 0) {
return res.status(400).json({
Expand All @@ -131,12 +141,12 @@ export const joinEvent: IAuthedRouteHandler = async (req, res) => {

// Handle /v1/user/event GET
export const getUserJoinedEvent: IAuthedRouteHandler = async (req, res) => {
const userId = req.user.id
const userId = req.user.id;
// Fetch event ID that match with current user ID
const eventID = await db
.select({ eventId: usersToEvent.eventId })
.from(usersToEvent)
.where(eq(usersToEvent.userId, userId));
.select({ eventId: usersToEvent.eventId })
.from(usersToEvent)
.where(eq(usersToEvent.userId, userId));

// check if ID is empty
if (eventID.length === 0) {
Expand All @@ -146,13 +156,15 @@ export const getUserJoinedEvent: IAuthedRouteHandler = async (req, res) => {
} satisfies GetEventFailAPI);
}

const eventIDArray: number[] = eventID.map(result => result.eventId).filter((id): id is number => id !== null);
const eventIDArray: number[] = eventID
.map((result) => result.eventId)
.filter((id): id is number => id !== null);

// Fetch all events where it matches eventID
const events = await db
.select()
.from(eventTable)
.where(inArray(eventTable.id, eventIDArray));
.select()
.from(eventTable)
.where(inArray(eventTable.id, eventIDArray));

// Check if events were found
if (events.length === 0) {
Expand Down Expand Up @@ -182,7 +194,7 @@ export const getUserJoinedEvent: IAuthedRouteHandler = async (req, res) => {
// Handle /v1/user/event/:id DELETE
export const leaveEvent: IAuthedRouteHandler = async (req, res) => {
const eventId = parseInt(req.params.id, 10);
const userId = req.user.id
const userId = req.user.id;

if (isNaN(eventId) || eventId < 0) {
return res.status(400).json({
Expand All @@ -191,7 +203,11 @@ export const leaveEvent: IAuthedRouteHandler = async (req, res) => {
} satisfies DeleteEventFailAPI);
}

await db.delete(usersToEvent).where(and(eq(usersToEvent.eventId, eventId), eq(usersToEvent.userId, userId)));
await db
.delete(usersToEvent)
.where(
and(eq(usersToEvent.eventId, eventId), eq(usersToEvent.userId, userId)),
);

return res.status(200).json({
status: 200,
Expand Down

0 comments on commit 155bced

Please sign in to comment.