mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-04 12:46:04 +02:00
Create guest user in user table when creating a participant
This commit is contained in:
parent
346ef136f0
commit
65192f95c9
5 changed files with 20 additions and 7 deletions
|
@ -92,9 +92,14 @@ export const participants = router({
|
|||
|
||||
const participant = await prisma.participant.create({
|
||||
data: {
|
||||
pollId: pollId,
|
||||
name: name,
|
||||
email,
|
||||
locale: user.locale ?? undefined,
|
||||
poll: {
|
||||
connect: {
|
||||
id: pollId,
|
||||
},
|
||||
},
|
||||
user: {
|
||||
connectOrCreate: {
|
||||
where: {
|
||||
|
@ -102,12 +107,15 @@ export const participants = router({
|
|||
},
|
||||
create: {
|
||||
id: user.id,
|
||||
isGuest: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
locale: user.locale ?? undefined,
|
||||
},
|
||||
include: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
email: true,
|
||||
poll: {
|
||||
select: {
|
||||
id: true,
|
||||
|
|
|
@ -9,8 +9,9 @@ BEGIN
|
|||
WHERE user_id IS NULL
|
||||
LOOP
|
||||
WITH new_user AS (
|
||||
INSERT INTO users (is_guest, created_at)
|
||||
INSERT INTO users (id, is_guest, created_at)
|
||||
VALUES (
|
||||
gen_random_uuid()::text,
|
||||
TRUE,
|
||||
NOW()
|
||||
)
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
- Made the column `user_id` on table `participants` required. This step will fail if there are existing NULL values in that column.
|
||||
|
||||
*/
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "participants" ALTER COLUMN "user_id" SET NOT NULL;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
-- DropForeignKey
|
||||
ALTER TABLE "participants" DROP CONSTRAINT "participants_user_id_fkey";
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "participants" ADD CONSTRAINT "participants_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@ -194,7 +194,7 @@ model Participant {
|
|||
|
||||
votes Vote[] @relation("ParticipantToVotes")
|
||||
poll Poll @relation("PollToParticipants", fields: [pollId], references: [id], onDelete: Cascade)
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([pollId], type: Hash)
|
||||
@@map("participants")
|
||||
|
|
Loading…
Add table
Reference in a new issue