2
0

feat: Add collaboration

This commit is contained in:
Baptiste Arnaud
2022-02-24 11:13:19 +01:00
parent dd671a5d2c
commit b9dafa611e
63 changed files with 1932 additions and 148 deletions

View File

@ -0,0 +1,31 @@
-- CreateEnum
CREATE TYPE "CollaborationType" AS ENUM ('READ', 'WRITE');
-- CreateTable
CREATE TABLE "Invitation" (
"email" TEXT NOT NULL,
"typebotId" TEXT NOT NULL,
"type" "CollaborationType" NOT NULL
);
-- CreateTable
CREATE TABLE "CollaboratorsOnTypebots" (
"userId" TEXT NOT NULL,
"typebotId" TEXT NOT NULL,
"type" "CollaborationType" NOT NULL
);
-- CreateIndex
CREATE UNIQUE INDEX "Invitation_email_typebotId_key" ON "Invitation"("email", "typebotId");
-- CreateIndex
CREATE UNIQUE INDEX "CollaboratorsOnTypebots_userId_typebotId_key" ON "CollaboratorsOnTypebots"("userId", "typebotId");
-- AddForeignKey
ALTER TABLE "Invitation" ADD CONSTRAINT "Invitation_typebotId_fkey" FOREIGN KEY ("typebotId") REFERENCES "Typebot"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "CollaboratorsOnTypebots" ADD CONSTRAINT "CollaboratorsOnTypebots_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "CollaboratorsOnTypebots" ADD CONSTRAINT "CollaboratorsOnTypebots_typebotId_fkey" FOREIGN KEY ("typebotId") REFERENCES "Typebot"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -38,20 +38,21 @@ model Session {
}
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
typebots Typebot[]
folders DashboardFolder[]
plan Plan @default(FREE)
stripeId String? @unique
credentials Credentials[]
customDomains CustomDomain[]
apiToken String?
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
typebots Typebot[]
folders DashboardFolder[]
plan Plan @default(FREE)
stripeId String? @unique
credentials Credentials[]
customDomains CustomDomain[]
apiToken String?
CollaboratorsOnTypebots CollaboratorsOnTypebots[]
}
model CustomDomain {
@ -103,28 +104,54 @@ model DashboardFolder {
}
model Typebot {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
name String
ownerId String
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
publishedTypebotId String?
publishedTypebot PublicTypebot?
results Result[]
folderId String?
folder DashboardFolder? @relation(fields: [folderId], references: [id])
folder DashboardFolder? @relation(fields: [folderId], references: [id])
blocks Json[]
variables Json[]
edges Json[]
theme Json
settings Json
publicId String? @unique
customDomain String? @unique
publicId String? @unique
customDomain String? @unique
collaborators CollaboratorsOnTypebots[]
invitations Invitation[]
@@unique([id, ownerId])
}
model Invitation {
email String
typebotId String
typebot Typebot @relation(fields: [typebotId], references: [id], onDelete: Cascade)
type CollaborationType
@@unique([email, typebotId])
}
model CollaboratorsOnTypebots {
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
typebotId String
typebot Typebot @relation(fields: [typebotId], references: [id], onDelete: Cascade)
type CollaborationType
@@unique([userId, typebotId])
}
enum CollaborationType {
READ
WRITE
}
model PublicTypebot {
id String @id @default(cuid())
createdAt DateTime @default(now())

View File

@ -12,6 +12,18 @@ import { byId, isDefined } from '.'
export const methodNotAllowed = (res: NextApiResponse) =>
res.status(405).json({ message: 'Method Not Allowed' })
export const notAuthenticated = (res: NextApiResponse) =>
res.status(401).json({ message: 'Not authenticated' })
export const notFound = (res: NextApiResponse) =>
res.status(404).json({ message: 'Not found' })
export const badRequest = (res: NextApiResponse) =>
res.status(400).json({ message: 'Bad Request' })
export const forbidden = (res: NextApiResponse) =>
res.status(403).json({ message: 'Bad Request' })
export const initMiddleware =
(
handler: (