Rest API using Express, TypeScript and MongoDB
Clone the repository to your local machine
git clone https://github.com/gabriel-dsdc/shopzone.gitNavigate into root of repository
cd shopzoneInstall dependencies
npm installCreate a .env file based on the .env.example file and populate following variables
PORT=3001
MONGODB_URI=<mongodb-connection-uri>
JWT_SECRET=<your-jwt-secret-key>
CLIENT_ID=<imgur-api-client-id>
CLIENT_SECRET=<imgur-api-client-secret>
REFRESH_TOKEN=<imgur-api-refresh-token>
ALBUM_HASH=<imgur-album-hash>
APP_URL=<app-url-for-stripe>
STRIPE_SECRET_KEY=<stripe-secret-key>
endpointSecret=<stripe-webhook-secret>
*Imgur is optional as it is only used to upload product images, but you can use external image URLs instead.
Stripe variables are only used in the payment route, you can use the application without them.*
Development
npm run devProduction
npm start
POST {{hostname}}/users/register
{
"name": "",
"email": "",
"password": "",
"confirmPassword": ""
}{
"token": ""
}POST {{hostname}}/users/login
{
"email": "",
"password": ""
}{
"token": ""
}GET {{hostname}}/users/:id
{
"id": "",
"name": "",
"email": "",
"role": ""
}PUT {{hostname}}/users/:id
{
"name": "",
"email": "",
"password": "",
"confirmPassword": ""
}{
"name": "New name",
"email": "new@email.com"
}DELETE {{hostname}}/users/:id
{
"message": "User deleted successfully!"
}POST {{hostname}}/products
{
"name": "",
"images": ["https://image.png"],
"description": "",
"price": 0,
"quantity": 1,
"category": "",
"brand": "", // Optional
"authors": "" // Optional
}{
"name": "",
"images": ["https://image.png"],
"description": "",
"price": 0,
"quantity": 1,
"category": "",
"brand": "", // Optional
"authors": "" // Optional
}GET {{hostname}}/products
[
{
"id": "",
"name": "",
"images": ["https://image.png"],
"description": "",
"price": 0,
"quantity": 1,
"category": "",
"brand": "", // Optional
"authors": "" // Optional
}
]GET {{hostname}}/products/:id
{
"id": "",
"name": "",
"images": ["https://image.png"],
"description": "",
"price": 0,
"quantity": 1,
"category": "",
"brand": "", // Optional
"authors": "" // Optional
}PUT {{hostname}}/products/:id
{
"name": "",
"images": ["https://image.png"],
"description": "",
"price": 0,
"quantity": 1,
"category": "",
"brand": "", // Optional
"authors": "" // Optional
}DELETE {{hostname}}/products/:id
POST {{hostname}}/admin/createUser
{
"name": "",
"email": "",
"password": "",
"confirmPassword": "",
"role": "client" // client or admin
}GET {{hostname}}/admin/users
[
{
{
"name": "",
"email": "",
"password": "",
"confirmPassword": "",
"role": "client" // client or admin
}
}
]GET {{hostname}}/admin/getConfigs
{
"allowNewUsers": true,
"allowUserModifications": true
}PUT {{hostname}}/updateConfigs
{
"allowNewUsers": false,
"allowUserModifications": false
}