jscodegeek / msj-classroom-api-app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MSJ-CLASSROOM-API

REST API for msj-classroom-apps.

Requirements

latest stable version of Node.js.

latest stable version of PostgreSQL

project uses sequelize-cli in order to apply migrations and seeders to database

latest version of npx installed with -g flag

project uses Swagger in order to document and visualize api endpoints. In addition you can perform http requests to server for testing purposes.

Getting Started

Application requires next actions to be done before using it:

  1. Create PostgreSQL database according to db options of development config file

  2. Clone repository git clone git@github.com:jscodegeek/msj-classroom-api-app.git

  3. In order to install required dependencies run npm i or yarn install

  4. In order to bootstrap PostgreSQL database follow next instructions:

    • run npm run db:migrate:up
    • run npm run db:seed

SWAGGER:

Add route documentation for swagger in route config, for instance:

	config: {
		handler: broadcastsCtrl.fetchAllBroadcasts,
		tags: ['api', 'broadcasts'],
		description: 'get all broadcasts',
	}

open {host}:{port}/api/documentation in browser and be happy hapi

Contributing:

PUSH PREPARATION

  • run npm run build
  • run npm run lint:fix
  • perform steps described in Swagger section

Changing db configs:

NOTE: It is important to keep them in sync!


HOW TO add endpoint:

  • create route in routes folder. handler creation described several steps below
  • in case you create new file(for routes) you should add it to index
  • create handler for route in controllers folder
  • in case you create new file(for handlers) you should add it to index
  • perform steps described in Swagger section

HOW TO add model:

  • create model in models folder using sequelize-cli npx sequelize model:generate --name YOUR_MODEL_NAME --attributes columnName:columnType or you can apply your favourite approach, whatever it is.
  • in case you create new file(model) you should add it to index models object which will be exported.

NOTE: In case you create model or change its schema you should create migration. That is described in migrations section


HOW TO add migration:

  • create migration in migrations folder using sequelize-cli npx sequelize migration:generate --name YOUR_MIGRATION_NAME or you can apply your favourite approach, whatever it is.

HOW TO add seeder:

  • create seeder in seeders folder using sequelize-cli npx sequelize seed:generate --name YOUR_SEEDER_NAME or you can apply your favourite approach, whatever it is.

PS:

In case something went wrong(that is unlikely to happen) I recommend to shut down server and run:

  • npm run db:migrate:down
  • npm run db:migrate:up
  • npm run db:seed

About


Languages

Language:TypeScript 77.1%Language:JavaScript 22.9%