- Express API project using Typescript, Sequalize ORM, and MySQL.
Endpoint | Type | Description |
---|---|---|
/countAllUsers |
GET | Returns the number of rows in the users table. Authentication bearer token is required for this route. |
/profiles |
GET | Returns a list of profiles (limit set to 20). |
/profiles/{id} |
GET | Returns a profile by {id} url parameter. |
/companies |
GET | Returns a list of companies (limit set to 20)parameter. |
/companies/{id} |
GET | Returns a company by {id} url parameter. |
Endpoint | Type | Expected request body | Description |
---|---|---|---|
/register |
POST | { username : string, email : string, password : string, profileName? : string profilePhoto ?: string, companyLogo ?: string, companyName ?: string, } |
Used to insert a new row into the tables users , companies and profiles . |
/profiles |
POST | { name : string, profilePhoto : string, user : number, company : number } |
Used to insert a new row into the profiles table. |
/login |
POST | { name : string, password : string} |
Used to authenticate a user. The name field for the request body can either be an email or a username of an existing user. |
/companies |
POST | { logo : string, name : string} |
Used to insert a new row into the companies table. The field slug is generated from the name field. The field companyOwner is from the id of the user who created the company. |
Please note:
that only a user who's id is present in the foreignKey of a row targeted by these PUT methods can make altering changes to them.
Endpoint | Type | Expected request body | Description |
---|---|---|---|
/profiles/{id} |
PUT | { name ?: string, profilePhoto ?: string, company ?: number } |
Used to updated any or all columns of a specific row (with an id of {id} ) in the profiles table. Field user cannot be updated. |
/companies/{id} |
PUT | { logo ?: string, name ?: string} |
Used to updated any or all columns of a specific row (with an id of {id} ) in the companies table. The field slug is created automatically from the name field. |
Endpoint | Type | Expected request body | Description |
---|---|---|---|
/profiles/{id} |
DELETE | / | Used to delete a row in the profiles table based on the supplied {id} url parameter. |
/companies/{id} |
DELETE | / | Used to delete a row in the companies table based on the supplied {id} url parameter. |
MySQL server 5.7.33
(higher versions should also be compatible)NodeJS v.16.13.0
Prettier - Code formatter
ESlint
cp .env.example .env
... which will create a .env
file. Open it and insert the required environemnt variables (port and database connection parameters).
Make sure to also add a value to the "ACCESS_TOKEN_SECRET" .env parameter with a random string of bytes (leaving it empty will cause errors upon user registration). You can get this string by running the following commands in a terminal:
node
require('crypto').randomBytes(64).toString('hex')
npm install
Last step
: run these two scripts (preferably in different cmd windows) to compile the typescript code and to run the nodemon server (both will be in watch mode).
npm run dev:tsc
npm run dev:server
Perform all the steps not including the Last step
, but instead run the following command:
npm run start
You also might need to leave the PORT variable in .env
empty when deploying this app (such as hosting your server on Heroku, for example).
- id
- username
- password
- role --->
'company-user'
|'company-admin'
|'superadmin'
(default: superadmin).
- id
- status --->
'pending'
|'published'
(default: pending). - name
- profilePhoto
- user --->
foreignKey
- company --->
foreignKey
- id
- logo
- name
- slug
- companyOwner --->
foreignKey
User
toProfile
= One to OneProfile
toCompany
= One to Many (one Company has many Profiles, one Profile belongs to one Company)User
toCompany
= One to Many (one User has many Companies, one Company belongs to one User)
Note:
- one company could have many users
through
the Profile table - still not implemented.