⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
Refactored schema and added link model.
Danield19204f4c0fe
diff --git a/Layouts/MainLayout.tsx b/Layouts/MainLayout.tsxindex 57ffbf4d..1e9c9243 100644--- a/Layouts/MainLayout.tsx+++ b/Layouts/MainLayout.tsx@@ -27,14 +27,10 @@ export default function Layout({ children }: Props) {<meta name="viewport" content="width=device-width, initial-scale=1" /><link rel="icon" href="/favicon.ico" /></Head>- <div className="flex">- <Sidebar />- <div className="ml-80 w-full">- <div className="mx-auto w-full">- <Navbar />- {children}- </div>- </div>+ <Sidebar />+ <div className="ml-80 w-full">+ <Navbar />+ {children}</div></>);diff --git a/components/Collections.tsx b/components/Collections.tsxindex 99e13498..0cf0a2b9 100644--- a/components/Collections.tsx+++ b/components/Collections.tsx@@ -1,9 +1,9 @@import { useEffect, useState } from "react";interface Collections {- id: any;+ id: number;name: string;- role: string;+ createdAt: string;}export default function Collections() {diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].tsindex 09e21932..2b9b237d 100644--- a/pages/api/auth/[...nextauth].ts+++ b/pages/api/auth/[...nextauth].ts@@ -14,7 +14,7 @@ export const authOptions: AuthOptions = {credentials: {},async authorize(credentials, req) {const { email, password } = credentials as {- id: string;+ id: number;email: string;password: string;};@@ -50,7 +50,7 @@ export const authOptions: AuthOptions = {},callbacks: {session: async ({ session, token }) => {- session.user.id = token?.sub;+ session.user.id = parseInt(token?.sub as any);return session;},diff --git a/pages/api/auth/register.ts b/pages/api/auth/register.tsindex 4d7dab67..2c79af10 100644--- a/pages/api/auth/register.ts+++ b/pages/api/auth/register.ts@@ -38,16 +38,9 @@ export default async function handler(email: body.email,password: hashedPassword,collections: {- create: [- {- role: "owner",- collection: {- create: {- name: "First Collection",- },- },- },- ],+ create: {+ name: "First Collection",+ },},},});diff --git a/pages/api/routes/collections/getCollections.ts b/pages/api/routes/collections/getCollections.tsindex c92faaa6..6ab39d4e 100644--- a/pages/api/routes/collections/getCollections.ts+++ b/pages/api/routes/collections/getCollections.ts@@ -24,16 +24,12 @@ export default async function handler(email: email,},include: {- collections: {- include: {- collection: true,- },- },+ collections: true,},});const collections = findCollection?.collections.map((e) => {- return { id: e.collection.id, name: e.collection.name, role: e.role };+ return { id: e.id, name: e.name, createdAt: e.createdAt };});// console.log(session?.user?.email);diff --git a/pages/api/routes/collections/postCollection.ts b/pages/api/routes/collections/postCollection.tsindex eef1636a..61fc9289 100644--- a/pages/api/routes/collections/postCollection.ts+++ b/pages/api/routes/collections/postCollection.ts@@ -30,17 +30,17 @@ export default async function handler(where: {email,},- include: {+ select: {collections: {where: {- collection: {- name: collectionName,- },+ name: collectionName,},},},});+ console.log(typeof session.user.id);+const checkIfCollectionExists = findCollection?.collections[0];if (checkIfCollectionExists) {@@ -69,12 +69,7 @@ export default async function handler(collections: {create: [{- role: "owner",- collection: {- create: {- name: collectionName,- },- },+ name: collectionName,},],},diff --git a/prisma/migrations/20230131171711_/migration.sql b/prisma/migrations/20230131171711_/migration.sqldeleted file mode 100644index 4aff8b87..00000000--- a/prisma/migrations/20230131171711_/migration.sql+++ /dev/null@@ -1,32 +0,0 @@--- CreateTable-CREATE TABLE "User" (- "id" TEXT NOT NULL,- "name" TEXT NOT NULL,- "email" TEXT NOT NULL,- "password" TEXT NOT NULL,-- CONSTRAINT "User_pkey" PRIMARY KEY ("id")-);---- CreateTable-CREATE TABLE "Collection" (- "id" TEXT NOT NULL,- "name" TEXT NOT NULL,-- CONSTRAINT "Collection_pkey" PRIMARY KEY ("id")-);---- CreateTable-CREATE TABLE "UserAndCollection" (- "userId" TEXT NOT NULL,- "collectionId" TEXT NOT NULL,- "role" TEXT NOT NULL,-- CONSTRAINT "UserAndCollection_pkey" PRIMARY KEY ("userId","collectionId")-);---- AddForeignKey-ALTER TABLE "UserAndCollection" ADD CONSTRAINT "UserAndCollection_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;---- AddForeignKey-ALTER TABLE "UserAndCollection" ADD CONSTRAINT "UserAndCollection_collectionId_fkey" FOREIGN KEY ("collectionId") REFERENCES "Collection"("id") ON DELETE RESTRICT ON UPDATE CASCADE;diff --git a/prisma/migrations/20230213224230_/migration.sql b/prisma/migrations/20230213224230_/migration.sqlnew file mode 100644index 00000000..546f3c0d--- /dev/null+++ b/prisma/migrations/20230213224230_/migration.sql@@ -0,0 +1,57 @@+-- CreateTable+CREATE TABLE "User" (+ "id" SERIAL NOT NULL,+ "name" TEXT NOT NULL,+ "email" TEXT NOT NULL,+ "password" TEXT NOT NULL,+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,++ CONSTRAINT "User_pkey" PRIMARY KEY ("id")+);++-- CreateTable+CREATE TABLE "Collection" (+ "id" SERIAL NOT NULL,+ "name" TEXT NOT NULL,+ "ownerId" INTEGER NOT NULL,+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,++ CONSTRAINT "Collection_pkey" PRIMARY KEY ("id")+);++-- CreateTable+CREATE TABLE "UserAndCollection" (+ "userId" INTEGER NOT NULL,+ "collectionId" INTEGER NOT NULL,+ "canCreate" BOOLEAN NOT NULL,+ "canRead" BOOLEAN NOT NULL,+ "canUpdate" BOOLEAN NOT NULL,+ "canDelete" BOOLEAN NOT NULL,++ CONSTRAINT "UserAndCollection_pkey" PRIMARY KEY ("userId","collectionId")+);++-- CreateTable+CREATE TABLE "Link" (+ "id" SERIAL NOT NULL,+ "name" TEXT NOT NULL,+ "url" TEXT NOT NULL,+ "collectionId" INTEGER NOT NULL,++ CONSTRAINT "Link_pkey" PRIMARY KEY ("id")+);++-- CreateIndex+CREATE UNIQUE INDEX "User_email_key" ON "User"("email");++-- AddForeignKey+ALTER TABLE "Collection" ADD CONSTRAINT "Collection_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;++-- AddForeignKey+ALTER TABLE "UserAndCollection" ADD CONSTRAINT "UserAndCollection_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;++-- AddForeignKey+ALTER TABLE "UserAndCollection" ADD CONSTRAINT "UserAndCollection_collectionId_fkey" FOREIGN KEY ("collectionId") REFERENCES "Collection"("id") ON DELETE RESTRICT ON UPDATE CASCADE;++-- AddForeignKey+ALTER TABLE "Link" ADD CONSTRAINT "Link_collectionId_fkey" FOREIGN KEY ("collectionId") REFERENCES "Collection"("id") ON DELETE RESTRICT ON UPDATE CASCADE;diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 29df03b2..c71b3c0d 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -11,27 +11,44 @@ datasource db {}model User {- id String @id @default(cuid())+ id Int @id @default(autoincrement())name String- email String+ email String @uniquepassword String- collections UserAndCollection[]+ collections Collection[]+ collectionsJoined UserAndCollection[]+ createdAt DateTime @default(now())}model Collection {- id String @id @default(cuid())+ id Int @id @default(autoincrement())name String- users UserAndCollection[]+ owner User @relation(fields: [ownerId], references: [id])+ ownerId Int+ members UserAndCollection[]+ links Link[]+ createdAt DateTime @default(now())}model UserAndCollection {user User @relation(fields: [userId], references: [id])- userId String+ userId Intcollection Collection @relation(fields: [collectionId], references: [id])- collectionId String+ collectionId Int- role String+ canCreate Boolean+ canRead Boolean+ canUpdate Boolean+ canDelete Boolean@@id([userId, collectionId])+}++model Link {+ id Int @id @default(autoincrement())+ name String+ url String+ collection Collection @relation(fields: [collectionId], references: [id])+ collectionId Int}\ No newline at end of filediff --git a/types/next-auth.d.ts b/types/next-auth.d.tsindex ce3db1a1..cb9674bb 100644--- a/types/next-auth.d.ts+++ b/types/next-auth.d.ts@@ -3,7 +3,7 @@ import NextAuth, { DefaultSession } from "next-auth";declare module "next-auth" {interface Session {user: {- id: any;+ id: number;} & DefaultSession["user"];}}