-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add basic checkin functionality (#260)
Some bugs have been fixed.
- Loading branch information
1 parent
ad53705
commit 19cc985
Showing
18 changed files
with
759 additions
and
41 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,148 @@ | ||
import { Request, Response } from 'express'; | ||
|
||
import prisma from '../utils/database'; | ||
|
||
export const addNewParticipant = async (req: Request, res: Response) => { | ||
try { | ||
const { orgId, eventId } = req?.params; | ||
const { firstName, lastName } = req?.body; | ||
|
||
const newParticipant = await prisma.participant.create({ | ||
data: { | ||
firstName, | ||
lastName, | ||
organizationId: orgId, | ||
eventId, | ||
}, | ||
}); | ||
|
||
if (!newParticipant) { | ||
return res.status(500).json({ error: 'Something went wrong' }); | ||
} | ||
|
||
return res.status(200).json({ newParticipant }); | ||
} catch (err: any) { | ||
console.error(err); | ||
return res.status(500).json({ error: 'Something went wrong' }); | ||
} | ||
}; | ||
|
||
export const getAllParticipants = async (req: Request, res: Response) => { | ||
try { | ||
const { orgId, eventId } = req?.params; | ||
const participants = await prisma.participant.findMany({ | ||
where: { | ||
organizationId: orgId, | ||
eventId, | ||
}, | ||
}); | ||
|
||
if (!participants) { | ||
return res.status(500).json({ error: 'Something went wrong' }); | ||
} | ||
|
||
return res.status(200).json({ participants }); | ||
} catch (err: any) { | ||
console.error(err); | ||
return res.status(500).json({ error: 'Something went wrong' }); | ||
} | ||
}; | ||
|
||
export const getAllParticipantsCheckInDetails = async (req: Request, res: Response) => { | ||
try { | ||
const { orgId, eventId } = req?.params; | ||
|
||
const participantsCheckIn = await prisma.participant.findMany({ | ||
where: { | ||
organizationId: orgId, | ||
eventId, | ||
}, | ||
include: { | ||
participantCheckIn: { | ||
select: { | ||
checkedInAt: true, | ||
checkedInByUser: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
if (!participantsCheckIn) { | ||
return res.status(500).json({ error: 'Something went wrong' }); | ||
} | ||
|
||
return res.status(200).json({ participantsCheckIn }); | ||
} catch (err: any) { | ||
console.error(err); | ||
return res.status(500).json({ error: 'Something went wrong' }); | ||
} | ||
}; | ||
|
||
export const getParticipantById = async (req: Request, res: Response) => { | ||
try { | ||
const { orgId, eventId, participantId } = req?.params; | ||
const participant = await prisma.participant.findUnique({ | ||
where: { | ||
id: participantId, | ||
}, | ||
include: { | ||
participantCheckIn: { | ||
select: { | ||
checkedInAt: true, | ||
checkedInByUser: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
if (!participant) { | ||
return res.status(500).json({ error: 'Something went wrong' }); | ||
} | ||
|
||
return res.status(200).json({ participant }); | ||
} catch (err: any) { | ||
console.error(err); | ||
return res.status(500).json({ error: 'Something went wrong' }); | ||
} | ||
}; | ||
|
||
export const checkInParticipant = async (req: Request, res: Response) => { | ||
try { | ||
const userId = req?.auth?.payload?.sub; | ||
|
||
const { orgId, eventId, participantId } = req?.params; | ||
|
||
const { checkedInAt } = req?.body; | ||
|
||
const participantAlreadyCheckedIn = await prisma.participantCheckIn.findFirst({ | ||
where: { | ||
participantId, | ||
organizationId: orgId, | ||
eventId, | ||
}, | ||
}); | ||
|
||
if (participantAlreadyCheckedIn) { | ||
return res.status(400).json({ error: 'Participant already checked in' }); | ||
} | ||
|
||
const participantCheckIn = await prisma.participantCheckIn.create({ | ||
data: { | ||
participantId, | ||
organizationId: orgId, | ||
eventId, | ||
checkedInBy: userId, | ||
checkedInAt, | ||
}, | ||
}); | ||
|
||
if (!participantCheckIn) { | ||
return res.status(500).json({ error: 'Something went wrong' }); | ||
} | ||
|
||
return res.status(200).json({ participantCheckIn }); | ||
} catch (err: any) { | ||
console.error(err); | ||
return res.status(500).json({ error: 'Something went wrong' }); | ||
} | ||
}; |
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
12 changes: 12 additions & 0 deletions
12
apps/web-admin/src/pages/organizations/[orgId]/events/[eventId]/index.jsx
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,12 @@ | ||
import { useRouter } from 'next/router'; | ||
import { useEffect } from 'react'; | ||
|
||
export default function Event() { | ||
const router = useRouter(); | ||
|
||
const { orgId, eventId } = router.query; | ||
|
||
useEffect(() => { | ||
router.push(`/organizations/${orgId}/events/${eventId}/participants`); | ||
}, [orgId, eventId]); | ||
} |
64 changes: 64 additions & 0 deletions
64
...n/src/pages/organizations/[orgId]/events/[eventId]/participants/[participantId]/index.jsx
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,64 @@ | ||
import { useRouter } from 'next/router'; | ||
|
||
import { | ||
Box, | ||
Flex, | ||
Table, | ||
TableCaption, | ||
Tbody, | ||
Td, | ||
Tfoot, | ||
Th, | ||
Thead, | ||
Tr, | ||
TableContainer, | ||
Text, | ||
} from '@chakra-ui/react'; | ||
|
||
import { useFetch } from '@/hooks/useFetch'; | ||
|
||
import DashboardLayout from '@/layouts/DashboardLayout'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
export default function Events() { | ||
const router = useRouter(); | ||
|
||
const { orgId, eventId, participantId } = router.query; | ||
|
||
const { loading, get } = useFetch(); | ||
|
||
const [participant, setParticipant] = useState({}); | ||
|
||
useEffect(() => { | ||
const fetchParticipant = async () => { | ||
const { data, status } = await get( | ||
`/core/organizations/${orgId}/events/${eventId}/participants/${participantId}`, | ||
); | ||
setParticipant(data.participant || []); | ||
console.log(data); | ||
}; | ||
fetchParticipant(); | ||
}, [orgId, eventId, participantId]); | ||
|
||
return ( | ||
<DashboardLayout> | ||
<Flex | ||
direction="column" | ||
height="100%" | ||
width="100%" | ||
alignItems="center" | ||
justifyContent="center" | ||
gap={8} | ||
> | ||
<Box width="100%" p={8}> | ||
<Text fontSize="4xl" fontWeight="bold"> | ||
Participant Details | ||
</Text> | ||
</Box> | ||
<Box width="100%" height="100%"> | ||
{JSON.stringify(participant)} | ||
</Box> | ||
</Flex> | ||
</DashboardLayout> | ||
); | ||
} |
Oops, something went wrong.