KristerV / heliumpay-budgetweb-backend

2 stars 2 forks source link

Helium budget proposal

A Budget Proposal system for Helium Payments.

How to run

  1. Clone this repo.
  2. Install dependencies: npm install
  3. Install docker (and docker-compose).
  4. Start the docker daemon with systemctl start docker (Linux)
  5. Build the docker images: docker-compose build (re-run whenever Dockerfile or package.json changes)
  6. Start the containers: docker-compose up
  7. Run the migrations: docker-compose exec api npm run db:migrations:run
  8. Wait until blockchain is downloaded. Check progress on localhost:3000.
  9. Also run the frontend.

Notes

This will start the app along with dashd. Also run the frontend.

Mailer

To enable the mailer, process.env.MAILGUN_API_KEY and process.env.MAILGUN_DOMAIN must be set:

export MAILGUN_API_KEY=[api-key] && export MAILGUN_DOMAIN=[domain] && docker-compose up

Tests

Run the test suite:

npm run test
npm run test */**/createUser.test.js # run tests for a specific file
npm run test */**/user/*.test.js # run tests for a specific directory
npm run test -- --verbose

Tests are run against a separate test database. Make sure you run docker-compose up first. Migrations are automatically run during tests.

API design

v0                                      // Alpha version, subject to constant change
GET   v0/comments?proposalHash=         // Get all comments for a proposal
POST  v0/comments                       // Create a new comment
PUT   v0/comments/:id                   // Update a comment by id
DEL   v0/comments/:id                   // Delete a comment by id
POST  v0/comments/:id/vote              // Vote on a comment  
GET   v0/core/proposals                 // All proposals
GET   v0/core/proposals/:hash           // Single proposal
GET   v0/core/raw-cli/*                 // Raw data from the cli
POST  v0/login                          // Login with username (or email) and password
POST  v0/login/sendPasswordResetEmail   // Trigger password reset workflow for provided email
POST  v0/users                          // Create a new user
GET   v0/users/:id                      // Fetch a user by id
PUT   v0/users/:id                      // Updates a user by id
POST  v0/users/:id/confirmEmail         // Confirms the users email with short-lived token
POST  v0/users/:id/resetPassword        // Updates the users password with short-lived token

Middleware

Middleware adds common behaviour to routes handlers.

Auth scopes

Auth scopes are used to allow JWTs to perform a subset of actions against the api. The set of scopes can be found in scopes.js.

Database migrations

Creates a new migration file in database/migrations:

npm run db:migrations:make [name]

Runs migrations inside the docker container (run docker-compose up first):

docker-compose exec api npm run db:migrations:run

Rollback the latest migration from within the docker container:

docker-compose exec api npm run db:migrations:rollback

Links

Info

Interesting dash services

API design guidelines