From bd2d7534f00e3397df14068c90b1a4b37fdd79cd Mon Sep 17 00:00:00 2001
From: Allen Shibu <93600615+alllenshibu@users.noreply.github.com>
Date: Thu, 22 Feb 2024 20:11:24 +0530
Subject: [PATCH] fix: Fix bulk participant addition
---
.../src/controllers/participants.ts | 42 ++++++++++---------
.../participants/new/upload-csv/index.jsx | 4 +-
2 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/apps/core-admin/src/controllers/participants.ts b/apps/core-admin/src/controllers/participants.ts
index 73883245..fcc8d7e2 100644
--- a/apps/core-admin/src/controllers/participants.ts
+++ b/apps/core-admin/src/controllers/participants.ts
@@ -26,7 +26,7 @@ export const addNewParticipant = async (req: Request, res: Response) => {
}
}
- await prisma.$transaction(async (tx) => {
+ await prisma.$transaction(async (tx: typeof prisma) => {
const attributesAlreadyPresent = await tx.attributes.findMany({
where: {
organizationId: orgId,
@@ -35,7 +35,7 @@ export const addNewParticipant = async (req: Request, res: Response) => {
});
const newAttributes = attributesToBeAdded.filter(
- (attribute) => !attributesAlreadyPresent.find((a) => a.name === attribute),
+ (attribute) => !attributesAlreadyPresent.find((a: any) => a.name === attribute),
);
const newAttributesAdded = await tx.attributes.createMany({
@@ -55,28 +55,30 @@ export const addNewParticipant = async (req: Request, res: Response) => {
},
});
- console.log(attributes);
-
- const newParticipants = await tx.participant.createMany({
- data: participants.map((p: any) => {
- return {
+ for (const p of participants) {
+ const newParticipant = await tx.participant.create({
+ data: {
firstName: p.firstName,
- lastName: p.lastName,
+ lastName: p.firstName,
organizationId: orgId,
eventId,
- // participantAttributes: {
- // create: attributes.map((attribute: any) => {
- // return {
- // attributeId: attribute.id,
- // value: p[`_${attribute.name}`],
- // };
- // }),
- // },
- };
- }),
- });
+ participantAttributes: {
+ create: attributes.map((attribute: any) => {
+ return {
+ attributeId: attribute.id,
+ value: p[`_${attribute.name}`],
+ };
+ }),
+ },
+ },
+ });
+
+ if (!newParticipant) {
+ throw new Error('Something went wrong');
+ }
+ }
- return res.status(200).json({ newParticipants });
+ return res.status(200).json({ success: true });
});
} else {
//
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 3975a684..56bc76cb 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
@@ -131,7 +131,9 @@ export default function NewOrganization() {
autoHeight
/>
-
+
>
)}