Skip to content

Commit

Permalink
feat: Add basic checkin functionality (#260)
Browse files Browse the repository at this point in the history
Some bugs have been fixed.
  • Loading branch information
alllenshibu authored Feb 2, 2024
1 parent ad53705 commit 19cc985
Show file tree
Hide file tree
Showing 18 changed files with 759 additions and 41 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- run: |
docker build -t techno-event-core-admin .
- uses: actions/checkout@v2
- run: |
docker build -t techno-event-core-admin -f apps/core-admin/Dockerfile .
- run: |
docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
- run: |
docker tag techno-event-core-admin ${{ secrets.DOCKER_USER }}/techno-event-core-admin:latest
docker push ${{ secrets.DOCKER_USER }}/techno-event-core-admin:latest
- run: |
docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
- run: |
docker tag techno-event-core-admin ${{ secrets.DOCKER_USER }}/techno-event-core-admin:latest
docker push ${{ secrets.DOCKER_USER }}/techno-event-core-admin:latest
redeploy-backend:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Call deploy hook
run: |
curl -X GET ${{ secrets.BACKEND_DEPLOY_HOOK }}
- name: Call deploy hook
run: |
curl -X GET ${{ secrets.BACKEND_DEPLOY_HOOK }}
4 changes: 1 addition & 3 deletions Dockerfile → apps/core-admin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ WORKDIR /app

RUN npm install -g pnpm turbo

COPY . .
COPY ../../. .

RUN pnpm install

RUN pnpm run build --filter=techno-event-core-admin...

RUN ls -la node_modules

FROM node:18-alpine

COPY --from=builder /app/apps/core-admin/dist .
Expand Down
148 changes: 148 additions & 0 deletions apps/core-admin/src/controllers/participants.ts
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' });
}
};
20 changes: 20 additions & 0 deletions apps/core-admin/src/routes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import express, { Router } from 'express';
import { createNewOrganization, getUsersOrganizations } from './controllers/organizations';
import { createNewEvent, getEvents } from './controllers/events';
import {
addNewParticipant,
getAllParticipants,
getParticipantById,
checkInParticipant,
getAllParticipantsCheckInDetails,
} from './controllers/participants';

const router: Router = express.Router();

router.get('/', (req: any, res: any) => {
Expand All @@ -18,4 +26,16 @@ router.post('/organizations', createNewOrganization);
router.get('/organizations/:orgId/events', getEvents);
router.post('/organizations/:orgId/events', createNewEvent);

router.get('/organizations/:orgId/events/:eventId/participants', getAllParticipants);
router.post('/organizations/:orgId/events/:eventId/participants', addNewParticipant);
router.get(
'/organizations/:orgId/events/:eventId/participants/check-in',
getAllParticipantsCheckInDetails,
);
router.get('/organizations/:orgId/events/:eventId/participants/:participantId', getParticipantById);
router.post(
'/organizations/:orgId/events/:eventId/participants/check-in/:participantId',
checkInParticipant,
);

export default router;
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { useState } from 'react';
import { QrReader } from 'react-qr-reader';
import { Text } from '@chakra-ui/react';

const Scanner = ({ result, setResult }) => {
const handleScan = (result) => {
console.log(result);
setResult(result || '');
//call checkin function
if (result) {
console.log(result);
setResult(result?.text);
}
};

const handleError = (err) => {
Expand All @@ -15,7 +17,6 @@ const Scanner = ({ result, setResult }) => {
return (
<div>
<QrReader onResult={handleScan} onError={handleError} />
<Text>{JSON.stringify(result)}</Text>
</div>
);
};
Expand Down
8 changes: 5 additions & 3 deletions apps/web-admin/src/components/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ const Sidebar = () => {

const { logout } = useAuth0();

const router = useRouter();

const handleLogout = (e) => {
e.preventDefault();
setLoading(true);
logout();
logout({
logoutParams: {
returnTo: process.env.NEXT_PUBLIC_AUTH0_REDIRECT_URI,
},
});
};

return (
Expand Down
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]);
}
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>
);
}
Loading

0 comments on commit 19cc985

Please sign in to comment.