Skip to content

TechLadies/onesg-app

Repository files navigation

OneSG App

This is an application that is made for OneSG, that aims to provide a centralised platform for users to access, create and update cases.

The development of this application was done as part of Techladies Bootcamp #6. Techladies is a community for women in Asia to connect, learn, and advance as programmers.



Table of Contents



Requirements

  • node v12.18.3
  • npm v6.14.6


Project Structure

Installation

Code and setup instructions for frontend and backend can be accessed in their respective subdirectories.

  1. Install dependencies
git clone https://github.com/TechLadies/onesg-app.git
npm install
  1. Get development.js file from the coaches/team lead and put in config > env
  2. Run the application
npm run dev
  1. Go to http://localhost:8080


Database Setup

  1. Install PostgreSQL:
npm install pg
  1. Create the database
createdb onesg
  1. To run the migrations,
npm run db-migrate
  1. Populate the tables with the seed data (in the following sequence due to foreign key restraints)
npx knex seed:run --specific=staff.js
npx knex seed:run --specific=beneficiaries.js
npx knex seed:run --specific=referees.js
npx knex seed:run --specific=case.js
npx knex seed:run --specific=requestType.js
npx knex seed:run --specific=request.js

Ensure that the database onesg exists in the localhost, with the tables populated with the seeded data. You can download Postico or the Postgres.app to check.

  1. Install psql and pg_trgm
\c onesg;

psql;

CREATE EXTENSION pg_trgm;

Setup Keys for Passport

To create keys required for authentication with passport, run the following command,

npm run generate-keys

You should now have the generated public & private keys in a keys folder in root.


Project Structure

onesg-app
+- config/ : configuration folder
|  +- env/
|  |  +- index.js : loads env file based on environment
|  |  +- development.js
|  |  +- production.js
|  +- index.js : home to your configs, can scale by adding folders and files
+- controllers/ : business logic
|  +- <feature>/ : controller container for a specific feature
+- db/ : db initialization scripts
|  +- migrations/
|  +- seeds/
+- docs/ : documentation
+- middleware/ : custom middleware
+- models/ : db models
+- public/ : for serving static files
+- routers/ : route definitions
|  +- <feature>/ : route container for a specific feature
+- utils/ : shared functions
|  +- errors/ : custom error classes
|  +- index.js : entry point to the utils folder
+- .eslintrc.json
+- .gitignore
+- index.js : app entry point
+- package.json
+- README.md


Build and Deployment

We use Heroku and Travis to run the build and deploy the app. The following are the corresponding branches and the app names and links

Setting up Heroku App

Create apps with the aforementioned app names. Add the following config vars to respective apps' config var under Settings.

Config Var

Setting up Heroku postgres

We use Heroku: Postgres as our plugin. More info on Heroku plugin here.

Heroku Postgres

Setting up Travis

Go to https://travis-ci.com/ and login with your Github account. Give Travis access to your repository.

If you already have Travis installed, you can also add Travis to the repository on from page https://github.com/settings/installations.

Create a .travis.yml file. Add the following block code to the file

travis block

Generate your api_key with this code below:

travis encrypt \$(heroku auth:token) --add deploy.api_key --pro

Seeding the database

Run seeds in terminal. Change the app names after -a accordingly.

heroku run knex seed:run --specific=referees.js -a onesg-backend-staging
heroku run knex seed:run --specific=referees.js -a onesg-backend-staging
heroku run knex seed:run --specific=case.js -a onesg-backend-staging

Add TRGM extension

Add the pg_trgm extension to the database. (https://devcenter.heroku.com/articles/heroku-postgres-extensions-postgis-full-text-search)

heroku pg:psql
create extension pg_trgm
\q

Save the file and commit your changes to GitHub.

You should be able to see the build on Travis and the app on Heroku deployed.

Travis Build travisdeploy

Deployed on Heroku

travisdeploy

Login

Log in with email and password.

For this project, the email and password for admin is hard-coded in POST request login

Remain authenticated with Bearer Token

Once bearer token is generated upon login. Put the bearer token under Headers with 'Authorisation' key to access pages. auth

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published