Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

users and projects #10

Merged
merged 10 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9,499 changes: 8,256 additions & 1,243 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,25 @@
"description": "Back-End Repo for Team 1 of Baboon/Bald Eagle Practicum",
"main": "app.js",
"scripts": {
"dev": "nodemon src/server.js"
"dev": "nodemon src/server.js",
"test": "jest"
},
"author": "",
"license": "ISC",
"dependencies": {
"@prisma/client": "^6.1.0",
"cors": "^2.8.5",
"express": "^4.18.2",
"dotenv": "^16.4.7",
"express": "^4.21.2",
"express-favicon": "^2.0.4",
"mongoose": "^7.0.1",
"morgan": "^1.10.0"
"morgan": "^1.10.0",
"pg": "^8.13.1",
"prisma": "^6.1.0"
},
"devDependencies": {
"nodemon": "^2.0.21"
"jest": "^29.7.0",
"nodemon": "^2.0.21",
"supertest": "^7.0.0"
}
}
90 changes: 90 additions & 0 deletions prisma/migrations/20241220170548_add_tags_column/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
-- CreateTable
CREATE TABLE "comments" (
"comment_id" SERIAL NOT NULL,
"user_id" INTEGER,
"project_id" INTEGER,
"content" TEXT NOT NULL,
"created_at" TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "comments_pkey" PRIMARY KEY ("comment_id")
);

-- CreateTable
CREATE TABLE "likes" (
"like_id" SERIAL NOT NULL,
"user_id" INTEGER,
"project_id" INTEGER,
"created_at" TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "likes_pkey" PRIMARY KEY ("like_id")
);

-- CreateTable
CREATE TABLE "projects" (
"project_id" SERIAL NOT NULL,
"name" VARCHAR(100),
"description" TEXT,
"github_link" VARCHAR(255),
"youtube_video_link" VARCHAR(255),
"is_public" BOOLEAN,
"created_by" INTEGER,
"created_at" TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP,
"tags" TEXT[] DEFAULT ARRAY[]::TEXT[],

CONSTRAINT "projects_pkey" PRIMARY KEY ("project_id")
);

-- CreateTable
CREATE TABLE "roles" (
"role_id" SERIAL NOT NULL,
"role_name" VARCHAR(50),

CONSTRAINT "roles_pkey" PRIMARY KEY ("role_id")
);

-- CreateTable
CREATE TABLE "user_role" (
"user_id" INTEGER,
"role_id" INTEGER
);

-- CreateTable
CREATE TABLE "users" (
"user_id" SERIAL NOT NULL,
"username" VARCHAR(50),
"email" VARCHAR(100),
"password_hash" VARCHAR(255),

CONSTRAINT "users_pkey" PRIMARY KEY ("user_id")
);

-- CreateIndex
CREATE UNIQUE INDEX "unique_like" ON "likes"("user_id", "project_id");

-- CreateIndex
CREATE UNIQUE INDEX "users_username_key" ON "users"("username");

-- CreateIndex
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");

-- AddForeignKey
ALTER TABLE "comments" ADD CONSTRAINT "comments_project_id_fkey" FOREIGN KEY ("project_id") REFERENCES "projects"("project_id") ON DELETE CASCADE ON UPDATE NO ACTION;

-- AddForeignKey
ALTER TABLE "comments" ADD CONSTRAINT "comments_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("user_id") ON DELETE CASCADE ON UPDATE NO ACTION;

-- AddForeignKey
ALTER TABLE "likes" ADD CONSTRAINT "likes_project_id_fkey" FOREIGN KEY ("project_id") REFERENCES "projects"("project_id") ON DELETE CASCADE ON UPDATE NO ACTION;

-- AddForeignKey
ALTER TABLE "likes" ADD CONSTRAINT "likes_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("user_id") ON DELETE CASCADE ON UPDATE NO ACTION;

-- AddForeignKey
ALTER TABLE "projects" ADD CONSTRAINT "projects_created_by_fkey" FOREIGN KEY ("created_by") REFERENCES "users"("user_id") ON DELETE SET NULL ON UPDATE NO ACTION;

-- AddForeignKey
ALTER TABLE "user_role" ADD CONSTRAINT "user_role_role_id_fkey" FOREIGN KEY ("role_id") REFERENCES "roles"("role_id") ON DELETE CASCADE ON UPDATE NO ACTION;

-- AddForeignKey
ALTER TABLE "user_role" ADD CONSTRAINT "user_role_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("user_id") ON DELETE CASCADE ON UPDATE NO ACTION;
11 changes: 11 additions & 0 deletions prisma/migrations/20241220175923_update_user_role/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Warnings:

- Made the column `user_id` on table `user_role` required. This step will fail if there are existing NULL values in that column.
- Made the column `role_id` on table `user_role` required. This step will fail if there are existing NULL values in that column.

*/
-- AlterTable
ALTER TABLE "user_role" ALTER COLUMN "user_id" SET NOT NULL,
ALTER COLUMN "role_id" SET NOT NULL,
ADD CONSTRAINT "user_role_pkey" PRIMARY KEY ("user_id", "role_id");
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "postgresql"
73 changes: 73 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model comments {
comment_id Int @id @default(autoincrement())
user_id Int?
project_id Int?
content String
created_at DateTime? @default(now()) @db.Timestamp(6)
updated_at DateTime? @default(now()) @db.Timestamp(6)
projects projects? @relation(fields: [project_id], references: [project_id], onDelete: Cascade, onUpdate: NoAction)
users users? @relation(fields: [user_id], references: [user_id], onDelete: Cascade, onUpdate: NoAction)
}

model likes {
like_id Int @id @default(autoincrement())
user_id Int?
project_id Int?
created_at DateTime? @default(now()) @db.Timestamp(6)
projects projects? @relation(fields: [project_id], references: [project_id], onDelete: Cascade, onUpdate: NoAction)
users users? @relation(fields: [user_id], references: [user_id], onDelete: Cascade, onUpdate: NoAction)

@@unique([user_id, project_id], map: "unique_like")
}

model projects {
project_id Int @id @default(autoincrement())
name String? @db.VarChar(100)
description String?
github_link String? @db.VarChar(255)
youtube_video_link String? @db.VarChar(255)
is_public Boolean?
created_by Int?
created_at DateTime? @default(now()) @db.Timestamp(6)
tags String[] @default([])
comments comments[]
likes likes[]
users users? @relation(fields: [created_by], references: [user_id], onUpdate: NoAction)
}

model roles {
role_id Int @id @default(autoincrement())
role_name String? @db.VarChar(50)
user_role user_role[] @ignore
}

/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
model user_role {
user_id Int
role_id Int
roles roles? @relation(fields: [role_id], references: [role_id], onDelete: Cascade, onUpdate: NoAction)
users users? @relation(fields: [user_id], references: [user_id], onDelete: Cascade, onUpdate: NoAction)

@@id([user_id, role_id]) // Composite primary key (if applicable)

}

model users {
user_id Int @id @default(autoincrement())
username String? @unique @db.VarChar(50)
email String? @unique @db.VarChar(100)
password_hash String? @db.VarChar(255)
comments comments[]
likes likes[]
projects projects[]
user_role user_role[] @ignore
}
4 changes: 4 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const favicon = require('express-favicon');
const logger = require('morgan');

const mainRouter = require('./routes/mainRouter.js');
const userRouter = require('./routes/userRouter.js');
const projectRouter = require('./routes/projectRouter.js');

// middleware
app.use(cors());
Expand All @@ -16,5 +18,7 @@ app.use(favicon(__dirname + '/public/favicon.ico'));

// routes
app.use('/api/v1', mainRouter);
app.use('/api/v1', userRouter);
app.use('/api/v1', projectRouter);

module.exports = app;
Loading
Loading