Coder Social home page Coder Social logo

express-crud-challenge's Introduction

Endpoints

POST /api/v1/auth/register - Signup
POST /api/v1/auth/login - Login
POST /api/v1/auth/refreshToken - RefreshToken
GET /api/v1/users/ - All Users
GET /api/v1/users/feed - Filter Users by location
GET /api/v1/users/profile - User Profile
POST /api/v1/users/update - Update User
POST /api/v1/users/like/:id - Like User
POST /api/v1/users/unlike/:id - UnLike User

Project Structure

./src
├── api/            # Routes and services and socket
├── common/         # configService and errors
├── utils/          # Utility classes and functions
├── middleware.ts   # Custom middlewares
├── app.ts          # Express App
└── index.ts        # App Entrypoint

Database

The structure of our database, the data model presented below.

model User {
  id            String              @id @unique @default(uuid())
  name          String
  email         String              @unique
  password      String
  refreshTokens RefreshToken[]
  avatars       UserAvatar[]
  bio           String? 
  latitude      String?
  longitude     String?
  liked         UserLike[]          @relation("UserLikes")
  likedBy       UserLike[]          @relation("UserIsLiked")
  createdAt     DateTime            @default(now())
  updatedAt     DateTime            @updatedAt
}

model RefreshToken {
  id          String                @id @unique @default(uuid())
  hashedToken String
  userId      String
  User        User                  @relation(fields: [userId], references: [id], onDelete: Cascade)
  revoked     Boolean               @default(false)
  createdAt   DateTime              @default(now())
  updatedAt   DateTime              @updatedAt
}
model UserAvatar {
  id                     String     @id @default(cuid())
  original               String
  p180                   String?
  p320                   String?
  p640                   String?
  p1280                  String?
  userId                 String
  user                   User       @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model UserLike {
  id                      Int       @id @default(autoincrement())
  liker_id                String
  liker                   User      @relation("UserLikes", fields: [liker_id], references: [id], onDelete: Cascade)
  user_id                 String
  user                    User      @relation("UserIsLiked", fields: [user_id], references: [id], onDelete: Cascade)
@@unique([liker_id, user_id])
}

Getting Started

Prerequisites

This project uses Yarn as package manager

Installation

  git clone https://github.com/hosajadi/express-crud-challenge.git

Go to the project directory

  cd express-crud-challenge
  yarn install

Run Locally

Start the server in development mode

Note: Do not forget to define the .env variables you can use .env.sample Note: If you do not have a running MySql server you can run a sample by below command

  yarn docker:db

But if you have one skip the previous command.

  yarn build
  npx prisma generate

If you run the project for the first time you should generate the prisma client, also migrate the migration file.

  yarn migrate:deploy

Too seed database

  yarn seed

Note: The initial user ==> email: '[email protected]', password: 'examplePass'

and finally to run

  yarn start

Run with Docker

Run docker compose

  yarn docker

express-crud-challenge's People

Watchers

hossein 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.