-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Brand model and CRUD operations for models with Express
- Loading branch information
Showing
31 changed files
with
4,198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
PORT= | ||
HOST= | ||
NODE_ENV= | ||
DB_USER= | ||
DB_PASSWORD= | ||
DB_NAME= | ||
DB_HOST= | ||
STATIC_FOLDER= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules/ | ||
!.sequelizerc | ||
!.env-template | ||
public/images/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"semi": true, | ||
"trailingComma": "es5", | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const path = require('path'); | ||
require('dotenv').config(); | ||
|
||
module.exports = { | ||
config: path.resolve('config', 'config.js'), | ||
'models-path': path.resolve('db', 'models'), | ||
'seeders-path': path.resolve('db', 'seeders'), | ||
'migrations-path': path.resolve('db', 'migrations'), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
{ | ||
"info": { | ||
"_postman_id": "eb990b76-e90c-45d0-adac-896700846c2c", | ||
"name": "Phones", | ||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", | ||
"_exporter_id": "37224117" | ||
}, | ||
"item": [ | ||
{ | ||
"name": "Brand", | ||
"item": [ | ||
{ | ||
"name": "brands", | ||
"request": { | ||
"method": "GET", | ||
"header": [], | ||
"url": { | ||
"raw": "{{url}}/brands", | ||
"host": [ | ||
"{{url}}" | ||
], | ||
"path": [ | ||
"brands" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "brands/id/phones", | ||
"request": { | ||
"method": "GET", | ||
"header": [], | ||
"url": { | ||
"raw": "{{url}}/brands/{{id}}/phones", | ||
"host": [ | ||
"{{url}}" | ||
], | ||
"path": [ | ||
"brands", | ||
"{{id}}", | ||
"phones" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "brands/id/phones", | ||
"request": { | ||
"method": "POST", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\r\n \"model\": \"iPhone 14\",\r\n \"year\": 2023,\r\n \"ram\": 6,\r\n \"processor\": \"A16 Bionic\",\r\n \"screenSize\": 6.1,\r\n \"hasNFC\": true,\r\n \"image\": \"\"\r\n}", | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "{{url}}/brands/{{id}}/phones", | ||
"host": [ | ||
"{{url}}" | ||
], | ||
"path": [ | ||
"brands", | ||
"{{id}}", | ||
"phones" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "phone", | ||
"request": { | ||
"method": "POST", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\r\n \"model\": \"iPhone 14\",\r\n \"year\": 2023,\r\n \"ram\": 6,\r\n \"processor\": \"A16 Bionic\",\r\n \"screenSize\": 6.1,\r\n \"hasNFC\": true,\r\n \"image\": \"\",\r\n \"brandId\": 1\r\n}", | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "{{url}}/phones", | ||
"host": [ | ||
"{{url}}" | ||
], | ||
"path": [ | ||
"phones" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "phones", | ||
"request": { | ||
"method": "GET", | ||
"header": [], | ||
"url": { | ||
"raw": "{{url}}/phones?page=1&results=5", | ||
"host": [ | ||
"{{url}}" | ||
], | ||
"path": [ | ||
"phones" | ||
], | ||
"query": [ | ||
{ | ||
"key": "page", | ||
"value": "1" | ||
}, | ||
{ | ||
"key": "results", | ||
"value": "5" | ||
} | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "phones/id", | ||
"request": { | ||
"method": "GET", | ||
"header": [], | ||
"url": { | ||
"raw": "{{url}}/phones/{{id}}", | ||
"host": [ | ||
"{{url}}" | ||
], | ||
"path": [ | ||
"phones", | ||
"{{id}}" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "phones/id", | ||
"request": { | ||
"method": "PATCH", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\n \"model\": \"iPhone 14\",\n \"year\": 2023,\n \"ram\": 6,\n \"processor\": \"A16 Bionic\",\n \"screenSize\": 6.1,\n \"hasNFC\": true,\n \"image\": \"123\",\n \"brandId\": 1\n}", | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "{{url}}/phones/{{id}}", | ||
"host": [ | ||
"{{url}}" | ||
], | ||
"path": [ | ||
"phones", | ||
"{{id}}" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "phones/id/image", | ||
"request": { | ||
"method": "PATCH", | ||
"header": [], | ||
"body": { | ||
"mode": "formdata", | ||
"formdata": [ | ||
{ | ||
"key": "phoneImage", | ||
"type": "file", | ||
"src": [] | ||
} | ||
] | ||
}, | ||
"url": { | ||
"raw": "{{url}}/phones/{{id}}/image", | ||
"host": [ | ||
"{{url}}" | ||
], | ||
"path": [ | ||
"phones", | ||
"{{id}}", | ||
"image" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "phones/id", | ||
"request": { | ||
"method": "PUT", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\r\n \"model\": \"iPhone 14\",\r\n \"year\": 2023,\r\n \"ram\": 6,\r\n \"processor\": \"A16 Bionic\",\r\n \"screenSize\": 6.1,\r\n \"hasNFC\": true,\r\n \"image\": \"\",\r\n \"brandId\": 1\r\n}", | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "{{url}}/phones/{{id}}", | ||
"host": [ | ||
"{{url}}" | ||
], | ||
"path": [ | ||
"phones", | ||
"{{id}}" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "phones/id", | ||
"request": { | ||
"method": "DELETE", | ||
"header": [], | ||
"url": { | ||
"raw": "{{url}}/phones/{{id}}", | ||
"host": [ | ||
"{{url}}" | ||
], | ||
"path": [ | ||
"phones", | ||
"{{id}}" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"id": "3baf009c-9094-4733-b034-01806cdedcb0", | ||
"name": "Phones", | ||
"values": [ | ||
{ | ||
"key": "url", | ||
"value": "http://localhost:5555/api", | ||
"type": "default", | ||
"enabled": true | ||
}, | ||
{ | ||
"key": "id", | ||
"value": "1", | ||
"type": "default", | ||
"enabled": true | ||
} | ||
], | ||
"_postman_variable_scope": "environment", | ||
"_postman_exported_at": "2024-12-21T21:51:20.039Z", | ||
"_postman_exported_using": "Postman/11.23.3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const express = require('express'); | ||
const { STATIC_PATH } = require('./constants'); | ||
const router = require('./routes'); | ||
const { errorHandlers } = require('./middleware'); | ||
|
||
const app = express(); | ||
|
||
app.use(express.static(STATIC_PATH)); | ||
|
||
app.use(express.json()); | ||
|
||
app.use('/api', router); | ||
|
||
app.use(errorHandlers.dbErrorHandler, errorHandlers.errorHandler); | ||
|
||
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module.exports = { | ||
development: { | ||
username: process.env.DB_USER, | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_NAME, | ||
host: process.env.DB_HOST, | ||
dialect: 'postgres', | ||
seederStorage: 'sequelize', | ||
}, | ||
test: { | ||
username: 'root', | ||
password: null, | ||
database: 'database_test', | ||
host: '127.0.0.1', | ||
dialect: 'mysql', | ||
}, | ||
production: { | ||
username: 'root', | ||
password: null, | ||
database: 'database_production', | ||
host: '127.0.0.1', | ||
dialect: 'mysql', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const path = require('path'); | ||
|
||
const CONSTANTS = { | ||
STATIC_PATH: path.join(__dirname, process.env.STATIC_FOLDER), | ||
}; | ||
|
||
module.exports = CONSTANTS; |
Oops, something went wrong.