GithubHelp home page GithubHelp logo

2color / real-world-grading-app Goto Github PK

View Code? Open in Web Editor NEW
296.0 8.0 88.0 416 KB

An example of a real-world REST API backend built with TypeScript, Hapi, Prisma, and PostgreSQL.

JavaScript 0.08% TypeScript 99.62% Shell 0.23% Procfile 0.06%
typescript prisma orm postgresql hapi database-schema rest-api

real-world-grading-app's Introduction

Real-world class grading backend

⚠️ Warning

This repo is no longer actively maintained, however it's still a great educational resource for building REST APIs in Node.js.

Intro

A real-world class grading application built with Prisma.

The grading application is used to manage enrollment in online classes, tests (as in exams) for classes, and test results.

The goal if this application is to showcase a real-world scenario of an application using Prisma. the following aspects of Prisma

  • Data modeling
  • CRUD
  • Aggregations
  • API layer
  • Validation
  • Testing
  • Authentication
  • Authorization
  • Integration with other APIs
  • Deployment

Check out the associated tutorial to learn more about how the backend was built.

Data model

The development of this project is driven by the database schema (also known as the data model). The schema is first designed to represent the following concepts:

  • User: this can be a student or a teacher, or both. The role of the user is determined through their association with a course.
  • Course: represent a course that can have multiple students/teachers. Each user can be associated with multiple courses either as a student or as a teacher.
  • CourseEnrollment:
  • Test: Each course can have many tests
  • TestResult: Each Test can have many TestReusults that is associated with a student

These are defined in the Prisma schema. The database schema will be created by Prisma Migrate.

Tech Stack

  • Backend:
    • PostgreSQL
    • Node.js
    • Prisma
    • TypeScript
    • Jest
    • Hapi.js

How to use

Install npm dependencies:

npm install

real-world-grading-app's People

Contributors

2color avatar dependabot[bot] avatar renovate-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

real-world-grading-app's Issues

P1010: User `prisma` was denied access on the database `grading-app.public`

Following along with https://www.prisma.io/blog/backend-prisma-typescript-orm-with-postgresql-data-modeling-tsjs1ps7kip1 once I get to npx prisma migrate dev --preview-feature --skip-generate --name "init" I get the following error:

$ npx prisma migrate dev --preview-feature --skip-generate --name "init"
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "grading-app", schema "public" at "127.0.0.1:5432"

Error: P1010: User `prisma` was denied access on the database `grading-app.public`

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

Rate Limited

These updates are currently rate limited. Click on a checkbox below to force their creation now.

  • fix(deps): update dependency @hapi/hapi to v20.2.2
  • chore(deps): update dependency postgres to v14.4
  • chore(deps): update dependency ts-node to v10.8.1
  • fix(deps): update dependency @sendgrid/mail to v7.7.0
  • chore(deps): update actions/checkout action to v3
  • chore(deps): update actions/setup-node action to v3
  • chore(deps): update dependency ts-node-dev to v2
  • chore(deps): update jest monorepo to v28 (major) (@types/jest, jest, ts-jest)
  • fix(deps): update dependency @hapi/boom to v10
  • fix(deps): update dependency dotenv to v16
  • fix(deps): update dependency hapi-pino to v10

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
docker-compose.yml
  • postgres 14.1
github-actions
.github/workflows/grading-app.yaml
  • actions/checkout v2
  • actions/setup-node v1
  • actions/checkout v2
  • akhileshns/heroku-deploy v3.12.12
npm
package.json
  • @hapi/boom 9.1.4
  • @hapi/hapi 20.2.1
  • joi 17.4.2
  • @prisma/client 3.5.0
  • @sendgrid/mail 7.4.6
  • prisma 3.5.0
  • date-fns 2.22.1
  • dotenv 10.0.0
  • hapi-auth-jwt2 10.2.0
  • hapi-pino 8.3.0
  • jsonwebtoken 8.5.1
  • @types/hapi-pino 8.0.2
  • @types/hapi__hapi 20.0.9
  • @types/jest 27.0.3
  • @types/jsonwebtoken 8.5.6
  • jest 27.3.1
  • ts-jest 27.0.7
  • ts-node 10.4.0
  • ts-node-dev 1.1.8
  • typescript 4.3.5
  • node 16.x

  • Check this box to trigger a request for Renovate to run again on this repository

Migratation error

Hi, thank you for your article series.
I have been following your first article, but got stuck on the error.

The migration log is below.

$ npx prisma migrate up --experimental
Environment variables loaded from prisma/.env
🏋️‍  migrate up

Datamodel that will initialize the db:

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["aggregateApi"]
}

datasource db {
  provider = "postgresql"
  url = "***"
}

model User {
  id        Int    @default(autoincrement()) @id
  email     String @unique
  firstName String
  lastName  String
  social    Json?
  // Relation fields
  courses     CourseEnrollment[]
  testResults TestResult[]       @relation(name: "results")
  testsGraded TestResult[]       @relation(name: "graded")
}

model Course {
  id            Int     @default(autoincrement()) @id
  name          String
  courseDetails String?
  // Relation fields
  members CourseEnrollment[]
  tests   Test[]
}

model CourseEnrollment {
  createdAt DateTime @default(now())
  role      UserRole
  // Relation Fields
  userId   Int
  courseId Int
  user     User   @relation(fields: [userId], references: [id])
  course   Course @relation(fields: [courseId], references: [id])
  @@id([userId, courseId])
}

model Test {
  id        Int      @default(autoincrement()) @id
  updatedAt DateTime @updatedAt
  name      String
  date      DateTime
  // Relation Fields
  courseId   Int
  course     Course       @relation(fields: [courseId], references: [id])
  testResults TestResult[]
}

model TestResult {
  id        Int      @default(autoincrement()) @id
  createdAt DateTime @default(now())
  result    Int // Percentage precise to one decimal point represented as `result * 10^-1`
  // Relation Fields
  studentId Int
  student   User @relation(name: "results", fields: [studentId], references: [id])
  graderId  Int
  gradedBy  User @relation(name: "graded", fields: [graderId], references: [id])
  testId    Int
  test      Test @relation(fields: [testId], references: [id])
}

enum UserRole {
  STUDENT
  TEACHER
}
Checking the datasource for potential data loss...

Database Changes:

Migration               Database actions           Status

20201001155133-init-db  2 DropTable statements.    

You can get the detailed db changes with prisma migrate up --experimental --verbose
Or read about them here:
      ./migrations/20201001155133-init-db/README.md

Error: Failure during a migration command: Connector error. (error: Error querying the database: Error querying the database: db error: ERROR: column "studentId" cannot be cast automatically to type integer
   0: migration_core::api::ApplyMigration
           with migration_id="20201001155133-init-db"
             at migration-engine/core/src/api.rs:87)

I used your schema.solved.prisma file. But still failed.
I also tried recent version of @prisma/cli which is 2.7.1, but still failed.

  • the version which is described in package.json was 2.3.0.
  • two versions are both failed.

I am beginner of Prisma, so I couldn't determine whether the error occurs from prisma or the schema file.
Could you check the schema file whether cool or not?

below is the schema file, I used, which of name was schema.solved.prisma.

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["aggregateApi"]
}

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

model User {
  id        Int    @default(autoincrement()) @id
  email     String @unique
  firstName String
  lastName  String
  social    Json?

  // Relation fields
  courses     CourseEnrollment[]
  testResults TestResult[]       @relation(name: "results")
  testsGraded TestResult[]       @relation(name: "graded")
}

model Course {
  id            Int     @default(autoincrement()) @id
  name          String
  courseDetails String?

  // Relation fields
  members CourseEnrollment[]
  tests   Test[]
}

model CourseEnrollment {
  createdAt DateTime @default(now())
  role      UserRole

  // Relation Fields
  userId   Int
  courseId Int
  user     User   @relation(fields: [userId], references: [id])
  course   Course @relation(fields: [courseId], references: [id])

  @@id([userId, courseId])
}

model Test {
  id        Int      @default(autoincrement()) @id
  updatedAt DateTime @updatedAt
  name      String
  date      DateTime

  // Relation Fields
  courseId   Int
  course     Course       @relation(fields: [courseId], references: [id])
  testResults TestResult[]
}

model TestResult {
  id        Int      @default(autoincrement()) @id
  createdAt DateTime @default(now())
  result    Int // Percentage precise to one decimal point represented as `result * 10^-1`

  // Relation Fields
  studentId Int
  student   User @relation(name: "results", fields: [studentId], references: [id])
  graderId  Int
  gradedBy  User @relation(name: "graded", fields: [graderId], references: [id])
  testId    Int
  test      Test @relation(fields: [testId], references: [id])
}

enum UserRole {
  STUDENT
  TEACHER
}

By the way, thank you for your articles.

kindly add Refresh Token

Good day, thanks for the great work... please how do i add refresh token to this project for scenarios where access token expires and i dont want to logout the user but make use of refresh token to get a new access token. thanks

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.