Skip to content

Commit

Permalink
fix: Fix bulk participant addition
Browse files Browse the repository at this point in the history
  • Loading branch information
alllenshibu committed Feb 22, 2024
1 parent a92fef5 commit bd2d753
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
42 changes: 22 additions & 20 deletions apps/core-admin/src/controllers/participants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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({
Expand All @@ -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 {
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ export default function NewOrganization() {
autoHeight
/>
</ThemeProvider>
<Button onClick={handleSubmit}>Confirm and Add</Button>
<Button onClick={handleSubmit} isLoading={loading}>
Confirm and Add
</Button>
</>
)}
</Box>
Expand Down

0 comments on commit bd2d753

Please sign in to comment.