Make company global travel and accommodation easy and convenient for the strong workforce of savvy members of staff, by leveraging the modern web.
-
This application is deployed on heroku, we have two different versions, which are different by the app status, in testing mode or ready for production.
- When the app is in testing mode is available on this link stackup2-barefoot-backend-staging
This deployment happens automatically, whenever there is a new merging to develop branch
=> This helps whoever wants to test our application if it is giving the accurate outputs
- When the app is ready for production is available on this link stackup2-barefoot-backend
-
Whenever a new PR is opened, there is a new review app which is created and accessible in the browser which helps to access visualize your PR in the browser to check if it working as you wanted it to work.
-
If your PR needs some environment variables, click here and click on the Reveal Config Vars button, a new small window opens which shows you where to enter your env variable key and value. Those env variables are accessed ass process.env.{VARIABLE_NAME} =>Make sure you don't delete other env variables which were there previously.
If the aforementioned link says ACCESS DENIED, then contact me here to add you
-
After raising a PR, and after setting up everything, you can click here and look at the tab called REVIEW APPS and scroll down to find your PR and click on Open App button.
-
Another easy way to check your PR's deployment, after TravisCI build passes, scroll down to the PR's page and click on the
View Deployment
button.
This API uses Sequelize as its ORM. To get you started, we will configure sequelize using .sequelizerc file.
The .sequelizerc file will in turn be used by sequelize-cli to setup the the sequelize folder structure.
The following are example environment variables needed:
- DEV_DB_USERNAME
- DEV_DB_PASSWORD
- DEV_DB_NAME
- DEV_DB_HOSTNAME
- DEV_DB_PORT
- NODE_ENV=development
We will use npm sequelize-cli model:generate
command to generate a new model. This command requires two options:
--name
, Name of the model--attributes
, List of model attributes
Let's create a model named User.
$ npx sequelize-cli model:generate --name User --attributes firstName:string,lastName:string,email:string
This above will do following:
- Create a model file
user.js
insrc/database/models
folder - Create a migration file with name like
XXXXXXXXXXXXXX-create-user.js
insrc/database/migrations
folder
According to the docs, sequelize will only use Model files, it's the table representation. On the other hand, the migration file is a change in that model or more specifically that table, used by CLI. Treat migrations like a commit or a log for some change in database.
Until this step, we haven't inserted anything into the database. We have just created required model and migration files for our first model User. Now to actually create that table in database you need to run db:migrate
command.
$ npx sequelize-cli db:migrate
This command will execute these steps:
- Will ensure a table called SequelizeMeta in database. This table is used to record which migrations have run on the current database
- Start looking for any migration files which haven't run yet. This is possible by checking
SequelizeMeta table
. In this case it will runXXXXXXXXXXXXXX-create-user.js
migration, which we created in last step. - Creates a table called
Users
with all columns as specified in its migration file.
Now our table has been created and saved in database. With migration you can revert to old state by just running a command.
You can use db:migrate:undo
, this command will revert most recent migration.
$ npx sequelize-cli db:migrate:undo
You can revert back to initial state by undoing all migrations with db:migrate:undo:all
command. You can also revert back to a specific migration by passing its name in --to
option.
$ npx sequelize-cli db:migrate:undo:all --to XXXXXXXXXXXXXX-create-user.js
Refer to the sequelize and sequelize-cli docs for more information.
Endpoint | Request | Status | Description |
---|---|---|---|
/ | GET | 200 OK | Helps users to access to the parent api for the whole application |
/api/auth/signup | POST | 201 CREATED | Makes a post request to signup a new user and return access token |
/api/auth/login | POST | 200 OK | Makes a post request to login an existing user and return an access token |
/api/auth/resetpassword | POST | 200 OK | Makes a post request, for for requesting to reset a password by sending the user's email and it returns a token to send with the next route of resetting password |
/api/auth/resetpassord/:token | POST | 200 OK | Makes a POST request reset user's password |
/api/profile | GET | 200 OK | Makes a GET request, to help a logged-in user to see his profile after successful login |
/api/profile/:username | GET | 200 OK | Makes a GET request to help a user to see other users' profiles by adding their usernames in URL |
/api/profile | PATCH | 200 OK | Makes a PATCH request when a user wants to update his profile |
/api/profile/password | PATCH | 200 OK | Makes a PATCH request to help password changes, whenever a user needs to change his/her password directly from his/her profile |
/api/auth/verify?token=eyWWWSDHFGC | GET | 200 OK | Makes a GET request when a user clicks on the link that is sent to him/her via Email to verify his/her email |
More Details about all of the above endpoints, their responses form, and when there is an error how they respond, please click here for further documentation Documentation |