From 4cbb458ef693a43bf1b742c3dda9507175d38849 Mon Sep 17 00:00:00 2001 From: vaidyanath b <82041246+vaidyanath-b@users.noreply.github.com> Date: Tue, 6 Feb 2024 21:04:11 +0530 Subject: [PATCH] feat(core-admin): Add participants in bulk (#277) * add participants in bulk * removed email,phone --- .../src/controllers/participants.ts | 58 +++++++++++++++++++ apps/core-admin/src/routes.ts | 3 + .../participants/new/upload-csv/index.jsx | 2 - 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/apps/core-admin/src/controllers/participants.ts b/apps/core-admin/src/controllers/participants.ts index 6ba5fca8..9ef2d87a 100644 --- a/apps/core-admin/src/controllers/participants.ts +++ b/apps/core-admin/src/controllers/participants.ts @@ -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; diff --git a/apps/core-admin/src/routes.ts b/apps/core-admin/src/routes.ts index 01688843..d4c37fd4 100644 --- a/apps/core-admin/src/routes.ts +++ b/apps/core-admin/src/routes.ts @@ -10,6 +10,7 @@ import { getParticipantAttributes, setParticipantAttribute, checkOutParticipant, + addNewParticipantInBulk, } from './controllers/participants'; import { addNewAttribute, getAllAttributes, getAttributeById } from './controllers/attributes'; @@ -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, diff --git a/apps/web-admin/src/pages/organizations/[orgId]/events/[eventId]/participants/new/upload-csv/index.jsx b/apps/web-admin/src/pages/organizations/[orgId]/events/[eventId]/participants/new/upload-csv/index.jsx index 1fb2f3c5..0b085739 100644 --- a/apps/web-admin/src/pages/organizations/[orgId]/events/[eventId]/participants/new/upload-csv/index.jsx +++ b/apps/web-admin/src/pages/organizations/[orgId]/events/[eventId]/participants/new/upload-csv/index.jsx @@ -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 (