Skip to content

Commit

Permalink
feat(core-admin): Add participants in bulk (#277)
Browse files Browse the repository at this point in the history
* add participants in bulk

* removed email,phone
  • Loading branch information
vaidyanath-b authored Feb 6, 2024
1 parent 28e6872 commit 4cbb458
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
58 changes: 58 additions & 0 deletions apps/core-admin/src/controllers/participants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,64 @@ export const addNewParticipant = async (req: Request, res: Response) => {
}
};

export const addNewParticipantInBulk = async (req: Request, res: Response) => {
try {
const { orgId, eventId } = req?.params;
const { participants } = req?.body;

const newParticipants = await prisma.participant.createMany({
data: participants.map((participant: any) => {
return {
firstName: participant.firstName,
lastName: participant.lastName,
organizationId: orgId,
eventId,
};
}),
});
return res.status(200).json(newParticipants);
} catch (err: any) {
console.error(err);
return res.status(500).json({ error: 'Something went wrong' });
}
};
// export const addNewParticipantInBulk = async (req: Request, res: Response) => {
// try {
// const { orgId, eventId } = req?.params;
// const { participants } = req?.body;

// const newParticipants = [];
// const failedParticipants = [];

// for (const participant of participants) {
// try {
// const newParticipant = await prisma.participant.create({
// data: {
// firstName: participant.firstName,
// lastName: participant.lastName,
// email: participant.email,
// phone: participant.phoneNumber,
// organizationId: orgId,
// eventId,
// },
// });
// newParticipants.push(newParticipant);
// } catch (error) {
// console.error(`Failed to add participant: ${participant.firstName} ${participant.lastName}`);
// failedParticipants.push(participant);
// }
// }

// if (failedParticipants.length > 0) {
// return res.status(201).json({ message: 'Some participants were not added', success: newParticipants, failed: failedParticipants });
// }
// return res.status(200).json({ newParticipants });
// } 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;
Expand Down
3 changes: 3 additions & 0 deletions apps/core-admin/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getParticipantAttributes,
setParticipantAttribute,
checkOutParticipant,
addNewParticipantInBulk,
} from './controllers/participants';
import { addNewAttribute, getAllAttributes, getAttributeById } from './controllers/attributes';

Expand All @@ -32,6 +33,8 @@ router.post('/organizations/:orgId/events', createNewEvent);

router.get('/organizations/:orgId/events/:eventId/participants', getAllParticipants);
router.post('/organizations/:orgId/events/:eventId/participants', addNewParticipant);
router.post('/organizations/:orgId/events/:eventId/bulkParticipants', addNewParticipantInBulk);

router.get(
'/organizations/:orgId/events/:eventId/participants/check-in',
getAllParticipantsCheckInDetails,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ export default function NewOrganization() {
const columns = [
{ field: 'FirstName', headerName: 'First Name', width: 150 },
{ field: 'LastName', headerName: 'Last Name', width: 150 },
{ field: 'Email', headerName: 'Email', width: 150 },
{ field: 'PhoneNumber', headerName: 'Phone Number', width: 150 },
];

return (
Expand Down

0 comments on commit 4cbb458

Please sign in to comment.