diff --git a/.env b/.env new file mode 100644 index 0000000..ee7ba66 --- /dev/null +++ b/.env @@ -0,0 +1,8 @@ +#Common +BACKEND_PORT=3300 +# Database +POSTGRES_USER=postgres +POSTGRES_PASSWORD=postgres +POSTGRES_DB=schbody +POSTGRES_PORT=5432 +DATABASE_URL=postgresql://postgres:postgres@localhost:5432/schbody?schema=public diff --git a/apps/backend/prisma/migrations/20241109181906_/migration.sql b/apps/backend/prisma/migrations/20241109181906_/migration.sql new file mode 100644 index 0000000..a8150fa --- /dev/null +++ b/apps/backend/prisma/migrations/20241109181906_/migration.sql @@ -0,0 +1,112 @@ +-- CreateEnum +CREATE TYPE "Role" AS ENUM ('USER', 'GATEKEEPER', 'ADMIN'); + +-- CreateEnum +CREATE TYPE "ReservationStatus" AS ENUM ('OVERTIME', 'NORMAL'); + +-- CreateEnum +CREATE TYPE "BandMembershipStatus" AS ENUM ('PENDING', 'ACCEPTED'); + +-- CreateTable +CREATE TABLE "User" ( + "id" SERIAL NOT NULL, + "name" TEXT NOT NULL, + "email" TEXT NOT NULL, + "phone" TEXT NOT NULL, + "isDormResident" BOOLEAN NOT NULL, + "roomNumber" TEXT NOT NULL, + "role" "Role" NOT NULL, + + CONSTRAINT "User_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Reservation" ( + "id" SERIAL NOT NULL, + "userId" INTEGER, + "bandId" INTEGER, + "startTime" TIMESTAMP(3) NOT NULL, + "endTime" TIMESTAMP(3) NOT NULL, + "gateKeeperId" INTEGER, + "status" "ReservationStatus" NOT NULL, + + CONSTRAINT "Reservation_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Genre" ( + "id" SERIAL NOT NULL, + "name" TEXT NOT NULL, + + CONSTRAINT "Genre_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Band" ( + "id" SERIAL NOT NULL, + "name" TEXT NOT NULL, + "email" TEXT, + "webPage" TEXT, + "description" TEXT, + + CONSTRAINT "Band_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "BandMembership" ( + "id" SERIAL NOT NULL, + "userId" INTEGER, + "bandId" INTEGER, + "status" "BandMembershipStatus" NOT NULL, + + CONSTRAINT "BandMembership_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Comment" ( + "id" SERIAL NOT NULL, + "comment" TEXT NOT NULL, + "startTime" TIMESTAMP(3) NOT NULL, + "endTime" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "Comment_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "_BandToGenre" ( + "A" INTEGER NOT NULL, + "B" INTEGER NOT NULL +); + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_phone_key" ON "User"("phone"); + +-- CreateIndex +CREATE UNIQUE INDEX "_BandToGenre_AB_unique" ON "_BandToGenre"("A", "B"); + +-- CreateIndex +CREATE INDEX "_BandToGenre_B_index" ON "_BandToGenre"("B"); + +-- AddForeignKey +ALTER TABLE "Reservation" ADD CONSTRAINT "Reservation_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Reservation" ADD CONSTRAINT "Reservation_bandId_fkey" FOREIGN KEY ("bandId") REFERENCES "Band"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Reservation" ADD CONSTRAINT "Reservation_gateKeeperId_fkey" FOREIGN KEY ("gateKeeperId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "BandMembership" ADD CONSTRAINT "BandMembership_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "BandMembership" ADD CONSTRAINT "BandMembership_bandId_fkey" FOREIGN KEY ("bandId") REFERENCES "Band"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_BandToGenre" ADD CONSTRAINT "_BandToGenre_A_fkey" FOREIGN KEY ("A") REFERENCES "Band"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_BandToGenre" ADD CONSTRAINT "_BandToGenre_B_fkey" FOREIGN KEY ("B") REFERENCES "Genre"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/apps/backend/prisma/migrations/migration_lock.toml b/apps/backend/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..fbffa92 --- /dev/null +++ b/apps/backend/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "postgresql" \ No newline at end of file diff --git a/apps/backend/prisma/schema.prisma b/apps/backend/prisma/schema.prisma index ac63787..1fcb3eb 100644 --- a/apps/backend/prisma/schema.prisma +++ b/apps/backend/prisma/schema.prisma @@ -13,7 +13,77 @@ datasource db { url = env("DATABASE_URL") } +enum Role { + USER + GATEKEEPER + ADMIN +} + model User { - authSchId String @id - email String @unique + id Int @id @default(autoincrement()) + name String + email String @unique + phone String @unique + isDormResident Boolean + roomNumber String + role Role + bandMemberships BandMembership[] + reservations Reservation[] @relation("Reservations") + gateKeeping Reservation[] @relation("GateKeeping") +} + +enum ReservationStatus { + OVERTIME + NORMAL +} + +model Reservation { + id Int @id @default(autoincrement()) + user User? @relation("Reservations", fields: [userId], references: [id]) + userId Int? + band Band? @relation(fields: [bandId], references: [id]) + bandId Int? + startTime DateTime + endTime DateTime + gateKeeper User? @relation("GateKeeping", fields: [gateKeeperId], references: [id]) + gateKeeperId Int? + status ReservationStatus +} + +model Genre { + id Int @id @default(autoincrement()) + name String + bands Band[] +} + +model Band { + id Int @id @default(autoincrement()) + name String + genres Genre[] + members BandMembership[] + reservations Reservation[] + email String? + webPage String? + description String? +} + +enum BandMembershipStatus { + PENDING + ACCEPTED +} + +model BandMembership { + id Int @id @default(autoincrement()) + user User? @relation(fields: [userId], references: [id]) + userId Int? + band Band? @relation(fields: [bandId], references: [id]) + bandId Int? + status BandMembershipStatus +} + +model Comment { + id Int @id @default(autoincrement()) + comment String + startTime DateTime + endTime DateTime } diff --git a/yarn.lock b/yarn.lock index 7f0f1d2..aa0c21e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -328,10 +328,10 @@ path-to-regexp "3.2.0" swagger-ui-dist "5.11.2" -"@next/env@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/env/-/env-14.2.10.tgz#1d3178340028ced2d679f84140877db4f420333c" - integrity sha512-dZIu93Bf5LUtluBXIv4woQw2cZVZ2DJTjax5/5DOs3lzEOeKLy7GxRSr4caK9/SCPdaW6bCgpye6+n4Dh9oJPw== +"@next/env@14.2.13": + version "14.2.13" + resolved "https://registry.yarnpkg.com/@next/env/-/env-14.2.13.tgz#ba341ba9eb70db428fc1c754f49c3c516f7bab47" + integrity sha512-s3lh6K8cbW1h5Nga7NNeXrbe0+2jIIYK9YaA9T7IufDWnZpozdFUp6Hf0d5rNWUKu4fEuSX2rCKlGjCrtylfDw== "@next/eslint-plugin-next@14.2.2": version "14.2.2" @@ -340,50 +340,50 @@ dependencies: glob "10.3.10" -"@next/swc-darwin-arm64@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.10.tgz#49d10ca4086fbd59ee68e204f75d7136eda2aa80" - integrity sha512-V3z10NV+cvMAfxQUMhKgfQnPbjw+Ew3cnr64b0lr8MDiBJs3eLnM6RpGC46nhfMZsiXgQngCJKWGTC/yDcgrDQ== - -"@next/swc-darwin-x64@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.10.tgz#0ebeae3afb8eac433882b79543295ab83624a1a8" - integrity sha512-Y0TC+FXbFUQ2MQgimJ/7Ina2mXIKhE7F+GUe1SgnzRmwFY3hX2z8nyVCxE82I2RicspdkZnSWMn4oTjIKz4uzA== - -"@next/swc-linux-arm64-gnu@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.10.tgz#7e602916d2fb55a3c532f74bed926a0137c16f20" - integrity sha512-ZfQ7yOy5zyskSj9rFpa0Yd7gkrBnJTkYVSya95hX3zeBG9E55Z6OTNPn1j2BTFWvOVVj65C3T+qsjOyVI9DQpA== - -"@next/swc-linux-arm64-musl@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.10.tgz#6b143f628ccee490b527562e934f8de578d4be47" - integrity sha512-n2i5o3y2jpBfXFRxDREr342BGIQCJbdAUi/K4q6Env3aSx8erM9VuKXHw5KNROK9ejFSPf0LhoSkU/ZiNdacpQ== - -"@next/swc-linux-x64-gnu@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.10.tgz#086f2f16a0678890a1eb46518c4dda381b046082" - integrity sha512-GXvajAWh2woTT0GKEDlkVhFNxhJS/XdDmrVHrPOA83pLzlGPQnixqxD8u3bBB9oATBKB//5e4vpACnx5Vaxdqg== - -"@next/swc-linux-x64-musl@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.10.tgz#1befef10ed8dbcc5047b5d637a25ae3c30a0bfc3" - integrity sha512-opFFN5B0SnO+HTz4Wq4HaylXGFV+iHrVxd3YvREUX9K+xfc4ePbRrxqOuPOFjtSuiVouwe6uLeDtabjEIbkmDA== - -"@next/swc-win32-arm64-msvc@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.10.tgz#731f52c3ae3c56a26cf21d474b11ae1529531209" - integrity sha512-9NUzZuR8WiXTvv+EiU/MXdcQ1XUvFixbLIMNQiVHuzs7ZIFrJDLJDaOF1KaqttoTujpcxljM/RNAOmw1GhPPQQ== - -"@next/swc-win32-ia32-msvc@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.10.tgz#32723ef7f04e25be12af357cc72ddfdd42fd1041" - integrity sha512-fr3aEbSd1GeW3YUMBkWAu4hcdjZ6g4NBl1uku4gAn661tcxd1bHs1THWYzdsbTRLcCKLjrDZlNp6j2HTfrw+Bg== - -"@next/swc-win32-x64-msvc@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.10.tgz#ee1d036cb5ec871816f96baee7991035bb242455" - integrity sha512-UjeVoRGKNL2zfbcQ6fscmgjBAS/inHBh63mjIlfPg/NG8Yn2ztqylXt5qilYb6hoHIwaU2ogHknHWWmahJjgZQ== +"@next/swc-darwin-arm64@14.2.13": + version "14.2.13" + resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.13.tgz#76f08d78360c4d27d444df7f35a56f59a48f4808" + integrity sha512-IkAmQEa2Htq+wHACBxOsslt+jMoV3msvxCn0WFSfJSkv/scy+i/EukBKNad36grRxywaXUYJc9mxEGkeIs8Bzg== + +"@next/swc-darwin-x64@14.2.13": + version "14.2.13" + resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.13.tgz#1d4821d54bb01dacc6a6c32408f8468a4f4af269" + integrity sha512-Dv1RBGs2TTjkwEnFMVL5XIfJEavnLqqwYSD6LXgTPdEy/u6FlSrLBSSfe1pcfqhFEXRAgVL3Wpjibe5wXJzWog== + +"@next/swc-linux-arm64-gnu@14.2.13": + version "14.2.13" + resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.13.tgz#79d9af8d3408df9990c8911889eca1ca6a308f19" + integrity sha512-yB1tYEFFqo4ZNWkwrJultbsw7NPAAxlPXURXioRl9SdW6aIefOLS+0TEsKrWBtbJ9moTDgU3HRILL6QBQnMevg== + +"@next/swc-linux-arm64-musl@14.2.13": + version "14.2.13" + resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.13.tgz#b13180645865b120591db2f1e831743ebc02ab36" + integrity sha512-v5jZ/FV/eHGoWhMKYrsAweQ7CWb8xsWGM/8m1mwwZQ/sutJjoFaXchwK4pX8NqwImILEvQmZWyb8pPTcP7htWg== + +"@next/swc-linux-x64-gnu@14.2.13": + version "14.2.13" + resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.13.tgz#8cb8480dfeee512648e4e08c2095aac0461b876f" + integrity sha512-aVc7m4YL7ViiRv7SOXK3RplXzOEe/qQzRA5R2vpXboHABs3w8vtFslGTz+5tKiQzWUmTmBNVW0UQdhkKRORmGA== + +"@next/swc-linux-x64-musl@14.2.13": + version "14.2.13" + resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.13.tgz#df5ca922fa1e1ee81b15a06a2d3d3ace0efd2bd7" + integrity sha512-4wWY7/OsSaJOOKvMsu1Teylku7vKyTuocvDLTZQq0TYv9OjiYYWt63PiE1nTuZnqQ4RPvME7Xai+9enoiN0Wrg== + +"@next/swc-win32-arm64-msvc@14.2.13": + version "14.2.13" + resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.13.tgz#8a7db6e71f526212587975f743b28e4d1cb829d1" + integrity sha512-uP1XkqCqV2NVH9+g2sC7qIw+w2tRbcMiXFEbMihkQ8B1+V6m28sshBwAB0SDmOe0u44ne1vFU66+gx/28RsBVQ== + +"@next/swc-win32-ia32-msvc@14.2.13": + version "14.2.13" + resolved "https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.13.tgz#6aa664f36f2d70c5ae6ffcbbc56784d33f24522d" + integrity sha512-V26ezyjPqQpDBV4lcWIh8B/QICQ4v+M5Bo9ykLN+sqeKKBxJVDpEc6biDVyluTXTC40f5IqCU0ttth7Es2ZuMw== + +"@next/swc-win32-x64-msvc@14.2.13": + version "14.2.13" + resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.13.tgz#5a920eea82a58affa6146192586716cec6c87fed" + integrity sha512-WwzOEAFBGhlDHE5Z73mNU8CO8mqMNLqaG+AO9ETmzdCQlJhVtWZnOl2+rqgVQS+YHunjOWptdFmNfbpwcUuEsw== "@nodelib/fs.scandir@2.1.5": version "2.1.5" @@ -3329,12 +3329,12 @@ nestjs-prisma@^0.23.0: "@angular-devkit/schematics" "^13.3.0" "@schematics/angular" "~13.3.0" -next@14.2.10: - version "14.2.10" - resolved "https://registry.yarnpkg.com/next/-/next-14.2.10.tgz#331981a4fecb1ae8af1817d4db98fc9687ee1cb6" - integrity sha512-sDDExXnh33cY3RkS9JuFEKaS4HmlWmDKP1VJioucCG6z5KuA008DPsDZOzi8UfqEk3Ii+2NCQSJrfbEWtZZfww== +next@14.2.13: + version "14.2.13" + resolved "https://registry.yarnpkg.com/next/-/next-14.2.13.tgz#32da2ee0afbe729e2d4a467c3570def90e1c974d" + integrity sha512-BseY9YNw8QJSwLYD7hlZzl6QVDoSFHL/URN5K64kVEVpCsSOWeyjbIGK+dZUaRViHTaMQX8aqmnn0PHBbGZezg== dependencies: - "@next/env" "14.2.10" + "@next/env" "14.2.13" "@swc/helpers" "0.5.5" busboy "1.6.0" caniuse-lite "^1.0.30001579" @@ -3342,15 +3342,15 @@ next@14.2.10: postcss "8.4.31" styled-jsx "5.1.1" optionalDependencies: - "@next/swc-darwin-arm64" "14.2.10" - "@next/swc-darwin-x64" "14.2.10" - "@next/swc-linux-arm64-gnu" "14.2.10" - "@next/swc-linux-arm64-musl" "14.2.10" - "@next/swc-linux-x64-gnu" "14.2.10" - "@next/swc-linux-x64-musl" "14.2.10" - "@next/swc-win32-arm64-msvc" "14.2.10" - "@next/swc-win32-ia32-msvc" "14.2.10" - "@next/swc-win32-x64-msvc" "14.2.10" + "@next/swc-darwin-arm64" "14.2.13" + "@next/swc-darwin-x64" "14.2.13" + "@next/swc-linux-arm64-gnu" "14.2.13" + "@next/swc-linux-arm64-musl" "14.2.13" + "@next/swc-linux-x64-gnu" "14.2.13" + "@next/swc-linux-x64-musl" "14.2.13" + "@next/swc-win32-arm64-msvc" "14.2.13" + "@next/swc-win32-ia32-msvc" "14.2.13" + "@next/swc-win32-x64-msvc" "14.2.13" node-abort-controller@^3.0.1: version "3.1.1"