Skip to content

Commit

Permalink
fix: Unique email
Browse files Browse the repository at this point in the history
  • Loading branch information
alllenshibu committed Feb 29, 2024
1 parent 02f765b commit c7ccc50
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
5 changes: 5 additions & 0 deletions apps/core-admin/src/controllers/participants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ export const addNewParticipant = async (req: Request, res: Response) => {
return res.status(200).json({ newParticipant });
}
} catch (err: any) {
if (err.code === 'P2002') {
return res
.status(400)
.json({ error: 'An email present in CSV data already exists in the event' });
}
console.error(err);
return res.status(500).json({ error: 'Something went wrong' });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function NewParticipantByCSVUpload() {
duration: 10000,
});
setCSVData(null);
e.target.value = '';
//e.target.value = '';
return;
}

Expand Down Expand Up @@ -77,7 +77,7 @@ export default function NewParticipantByCSVUpload() {
duration: 10000,
});
setCSVData(null);
e.target.value = '';
//e.target.value = '';
}

if (
Expand Down Expand Up @@ -120,7 +120,7 @@ export default function NewParticipantByCSVUpload() {
duration: 10000,
});
setCSVData(null);
e.target.value = '';
//e.target.value = '';
setColumns([
{ field: 'firstName', headerName: 'First Name' },
{ field: 'lastName', headerName: 'Last Name' },
Expand Down Expand Up @@ -148,7 +148,7 @@ export default function NewParticipantByCSVUpload() {
duration: 10000,
});
setCSVData(null);
e.target.value = '';
// e.target.value = '';
setColumns([
{ field: 'firstName', headerName: 'First Name' },
{ field: 'lastName', headerName: 'Last Name' },
Expand Down
12 changes: 12 additions & 0 deletions packages/database/prisma/migrations/20240229114739_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Warnings:
- A unique constraint covering the columns `[email,eventId]` on the table `Participant` will be added. If there are existing duplicate values, this will fail.
- Made the column `email` on table `Participant` required. This step will fail if there are existing NULL values in that column.
*/
-- AlterTable
ALTER TABLE "Participant" ALTER COLUMN "email" SET NOT NULL;

-- CreateIndex
CREATE UNIQUE INDEX "Participant_email_eventId_key" ON "Participant"("email", "eventId");
4 changes: 3 additions & 1 deletion packages/database/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ model Participant {
updatedAt DateTime @updatedAt
firstName String
lastName String?
email String?
email String
phone String?
checkInKey String?
eventId String @db.Uuid
Expand All @@ -82,6 +82,8 @@ model Participant {
participantAttributes ParticipantAttributes[]
participantExtras ParticipantExtras[]
participantExtrasCheckIn ParticipantExtrasCheckIn[]
@@unique([email, eventId])
}

model ParticipantCheckIn {
Expand Down

0 comments on commit c7ccc50

Please sign in to comment.