GithubHelp home page GithubHelp logo

fokaaas / comments-system Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 659 KB

System for leaving comments with auth

License: MIT License

JavaScript 3.48% TypeScript 94.99% Handlebars 1.02% Dockerfile 0.52%
api auth comments docker jwt

comments-system's Introduction

Comments System

This application is powerful and scalable REST API for commenting.

Check out Swagger Documentation: https://comments-system-zlpi.onrender.com/api

Tech Stack:

  • NestJS
  • PostgreSQL
  • Prisma ORM
  • JWT
  • Passport.js
  • Docker
  • Swagger

How to set up it locally?

Firstly, clone this repo:

git clone https://github.com/fokaaas/comments-system.git

Then install pnpm globally:

npm install -g pnpm

Install dependencies in project directory:

pnpm install

Create .env file with environment variables, that has this structure:

DATABASE_URL=
PORT=

SMTP_HOST=
SMTP_USERNAME=
SMTP_PASSWORD=

SECRET=
ACCESS_TTL=
REFRESH_TTL=

FRONT_BASE_URL=

Apply schema to your database:

pnpm dlx prisma migrate

Run application:

pnpm start:dev

Database Schema

generator client {
  provider = "prisma-client-js"
}

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

enum State {
  PENDING
  APPROVED
  DECLINED
}

enum TokenType {
  EMAIL
  PASSWORD
  REFRESH
}

enum FileType {
  PICTURE
  TXT
}

model User {
  id                  String         @id @default(uuid())
  username            String         @unique
  email               String         @unique
  password            String
  avatar              String
  state               State          @default(PENDING)
  homepage            String?
  lastPasswordUpdated DateTime       @default(now()) @map("last_password_updated")
  createdAt           DateTime       @default(now()) @map("created_at")
  tokens              Token[]
  comments            Comment[]
  savedComments       SavedComment[]

  @@map("users")
}

model Token {
  value     String    @unique
  user      User      @relation(fields: [userId], references: [id], onDelete: Cascade)
  userId    String    @map("user_id")
  type      TokenType
  createdAt DateTime  @default(now()) @map("created_at")

  @@map("tokens")
}

model Comment {
  id        String         @id @default(uuid())
  user      User?          @relation(fields: [userId], references: [id], onDelete: SetNull)
  userId    String?        @map("user_id")
  parentId  String?        @map("parent_id")
  parent    Comment?       @relation("CommentRelation", fields: [parentId], references: [id], onDelete: Cascade)
  responses Comment[]      @relation("CommentRelation")
  text      String
  createdAt DateTime       @default(now()) @map("created_at")
  saves     SavedComment[]
  files     File[]

  @@map("comments")
}

model File {
  id        String   @id @default(uuid())
  link      String
  type      FileType
  comment   Comment  @relation(fields: [commentId], references: [id], onDelete: Cascade)
  commentId String   @map("comment_id")

  @@map("files")
}

model SavedComment {
  user      User     @relation(fields: [userId], references: [id], onDelete: Cascade)
  userId    String   @map("user_id")
  comment   Comment  @relation(fields: [commentId], references: [id], onDelete: Cascade)
  commentId String   @map("comment_id")
  createdAt DateTime @default(now()) @map("created_at")

  @@id([userId, commentId])
  @@map("saved_comments")
}

Auth Model

image

File Saving & Storing

All files are stored locally on the server using a hash in their name. A certain type of file has its own static folders.

static/images for images and static/txt for txt files

You can then access these files by following the link. (ex: http://127.0.0.1:3000/images/name.png or http://127.0.0.1:3000/txt/name.png)

But currently the current host doesn't support it because it's free.

Dockerization

Check out Dockerfile to create image. Also project have github workflows.

comments-system's People

Contributors

fokaaas avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.