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

Merge user management to Main #54

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ PREFIX="api/v1/"

# Security
ADMIN_KEY="admin"
COOKIE_SECRET="cookie"
SECURE_COOKIE="false"
SESSION_EXPIRATION=1209600# In seconds
MAX_SESSIONS=5
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@fastify/cookie": "^9.3.1",
"@fastify/helmet": "^11.1.1",
"@fastify/static": "^7.0.4",
"@nestjs/common": "^10.3.10",
Expand All @@ -29,6 +30,7 @@
"@nestjs/swagger": "^7.3.1",
"@nestjs/throttler": "^5.2.0",
"@prisma/client": "5.16.1",
"argon2": "^0.40.3",
"axios": "^1.7.2",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
Expand All @@ -40,7 +42,8 @@
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",
"sharp": "^0.33.4",
"swagger-themes": "^1.4.3"
"swagger-themes": "^1.4.3",
"uuid": "^10.0.0"
},
"devDependencies": {
"@nestjs/cli": "^10.3.2",
Expand All @@ -50,6 +53,7 @@
"@types/jsdom": "^21.1.7",
"@types/node": "^20.14.9",
"@types/supertest": "^6.0.2",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.14.1",
"eslint": "8.57.0",
Expand Down
65 changes: 65 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions prisma/migrations/20240701221340_users/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-- CreateTable
CREATE TABLE "users" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"email" TEXT NOT NULL,
"username" TEXT NOT NULL,
"password" TEXT NOT NULL,
"avatar_id" INTEGER,
"type_id" INTEGER NOT NULL,
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "users_avatar_id_fkey" FOREIGN KEY ("avatar_id") REFERENCES "images" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT "users_type_id_fkey" FOREIGN KEY ("type_id") REFERENCES "user_types" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "user_types" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" TEXT NOT NULL
);

-- CreateTable
CREATE TABLE "sessions" (
"uuid" TEXT NOT NULL PRIMARY KEY,
"user_id" INTEGER NOT NULL,
"user_agent_sum" TEXT NOT NULL,
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "sessions_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "favorites" (
"user_id" INTEGER NOT NULL,
"webtoon_id" INTEGER NOT NULL,

PRIMARY KEY ("user_id", "webtoon_id"),
CONSTRAINT "favorites_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "favorites_webtoon_id_fkey" FOREIGN KEY ("webtoon_id") REFERENCES "webtoons" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "progress" (
"user_id" INTEGER NOT NULL,
"episode_id" INTEGER NOT NULL,
"progress" INTEGER NOT NULL DEFAULT 0,

PRIMARY KEY ("user_id", "episode_id"),
CONSTRAINT "progress_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "progress_episode_id_fkey" FOREIGN KEY ("episode_id") REFERENCES "episodes" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateIndex
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");
60 changes: 60 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,63 @@ datasource db {
url = "file:./database.db"
}

model Users {
id Int @id @default(autoincrement())
email String @unique
username String
password String
avatar_id Int?
avatar Images? @relation(fields: [avatar_id], references: [id])
type_id Int
type UserTypes @relation(fields: [type_id], references: [id])
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
sessions Sessions[]
favorites Favorites[]
progress Progress[]

@@map("users")
}

model UserTypes {
id Int @id @default(autoincrement())
name String
user Users[]

@@map("user_types")
}

model Sessions {
uuid String @id
user_id Int
user Users @relation(fields: [user_id], references: [id], onDelete: Cascade)
user_agent_sum String
created_at DateTime @default(now())

@@map("sessions")
}

model Favorites {
user_id Int
user Users @relation(fields: [user_id], references: [id], onDelete: Cascade)
webtoon_id Int
webtoon Webtoons @relation(fields: [webtoon_id], references: [id], onDelete: Cascade)

@@id([user_id, webtoon_id])
@@map("favorites")
}

model Progress {
user_id Int
user Users @relation(fields: [user_id], references: [id], onDelete: Cascade)
episode_id Int
episode Episodes @relation(fields: [episode_id], references: [id], onDelete: Cascade)
progress Int @default(0)

@@id([user_id, episode_id])
@@map("progress")
}

model ImageTypes {
id Int @id @default(autoincrement())
name String
Expand All @@ -32,6 +89,7 @@ model Images {
mobile_banner Webtoons? @relation("mobile_banner")
episodes Episodes[]
episode_images EpisodeImages[]
users Users[]

@@map("images")
}
Expand Down Expand Up @@ -71,6 +129,7 @@ model Webtoons {
updated_at DateTime @default(now()) @updatedAt
genres WebtoonGenres[]
episodes Episodes[]
favorites Favorites[]

@@unique([title, author, language])
@@map("webtoons")
Expand All @@ -86,6 +145,7 @@ model Episodes {
thumbnail Images @relation(fields: [thumbnail_id], references: [id])
created_at DateTime @default(now())
episode_images EpisodeImages[]
progress Progress[]

@@unique([webtoon_id, number])
@@map("episodes")
Expand Down
Loading