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({
|
const participant = await prisma.participant.create({
|
||||||
data: {
|
data: {
|
||||||
pollId: pollId,
|
|
||||||
name: name,
|
name: name,
|
||||||
email,
|
email,
|
||||||
|
locale: user.locale ?? undefined,
|
||||||
|
poll: {
|
||||||
|
connect: {
|
||||||
|
id: pollId,
|
||||||
|
},
|
||||||
|
},
|
||||||
user: {
|
user: {
|
||||||
connectOrCreate: {
|
connectOrCreate: {
|
||||||
where: {
|
where: {
|
||||||
|
@ -102,12 +107,15 @@ export const participants = router({
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
|
isGuest: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
locale: user.locale ?? undefined,
|
|
||||||
},
|
},
|
||||||
include: {
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
email: true,
|
||||||
poll: {
|
poll: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
|
|
@ -9,8 +9,9 @@ BEGIN
|
||||||
WHERE user_id IS NULL
|
WHERE user_id IS NULL
|
||||||
LOOP
|
LOOP
|
||||||
WITH new_user AS (
|
WITH new_user AS (
|
||||||
INSERT INTO users (is_guest, created_at)
|
INSERT INTO users (id, is_guest, created_at)
|
||||||
VALUES (
|
VALUES (
|
||||||
|
gen_random_uuid()::text,
|
||||||
TRUE,
|
TRUE,
|
||||||
NOW()
|
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.
|
- Made the column `user_id` on table `participants` required. This step will fail if there are existing NULL values in that column.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
-- AlterTable
|
-- AlterTable
|
||||||
ALTER TABLE "participants" ALTER COLUMN "user_id" SET NOT NULL;
|
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")
|
votes Vote[] @relation("ParticipantToVotes")
|
||||||
poll Poll @relation("PollToParticipants", fields: [pollId], references: [id], onDelete: Cascade)
|
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)
|
@@index([pollId], type: Hash)
|
||||||
@@map("participants")
|
@@map("participants")
|
||||||
|
|
Loading…
Add table
Reference in a new issue