in progress: integrate swagger, db reconfig
This commit is contained in:
2004
package-lock.json
generated
2004
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node server.js"
|
||||
"start": "nodemon server.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": "v16.13.1"
|
||||
@@ -21,13 +21,16 @@
|
||||
"express": "^4.17.3",
|
||||
"express-session": "^1.17.3",
|
||||
"helmet": "^5.1.0",
|
||||
"js-yaml": "^4.1.0",
|
||||
"oauth2-server": "^3.1.1",
|
||||
"passport": "^0.6.0",
|
||||
"passport-local": "^1.0.0",
|
||||
"pg": "^8.7.3",
|
||||
"swagger-ui-express": "^4.4.0",
|
||||
"uuid": "^8.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/uuid": "^8.3.4"
|
||||
"@types/uuid": "^8.3.4",
|
||||
"nodemon": "^2.0.18"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ productsRouter.route('/:id').get(async (req, res) => {
|
||||
// post a product from req.body
|
||||
productsRouter.route('/').post(async (req, res) => {
|
||||
const newClient = client();
|
||||
const { name, description, category, categoryID } = req.body;
|
||||
const { name, description, category, categoryID, price } = req.body;
|
||||
|
||||
try {
|
||||
newClient.connect((err) => {
|
||||
@@ -51,7 +51,7 @@ productsRouter.route('/').post(async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
await newClient.query(("INSERT INTO products (name, description, category, category_id) VALUES ($1, $2, $3, $4)"), [name, description, category, categoryID]);
|
||||
await newClient.query(("INSERT INTO products (name, description, category, category_id, price) VALUES ($1, $2, $3, $4, $5)"), [name, description, category, categoryID, price]);
|
||||
res.sendStatus(204);
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
|
||||
@@ -5,7 +5,7 @@ const app = express();
|
||||
const session = require('express-session');
|
||||
|
||||
require('dotenv').config();
|
||||
const PORT = process.env.PORT;
|
||||
const PORT = process.env.PORT || 8088;
|
||||
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
@@ -29,3 +29,5 @@ app.use(apiRouter);
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Listening on port ${PORT}`);
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
11
swagger/swagger.js
Normal file
11
swagger/swagger.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const swaggerUI = require('swagger-ui-express');
|
||||
const yaml = require('js-yaml');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Loading via yml.safeLoad to avoid errors with special characters during processing
|
||||
const swaggerDocument = yaml.safeLoad(fs.readFileSync(path.resolve(__dirname, '../swagger.yml'), 'utf8'));
|
||||
|
||||
const app = require('../server');
|
||||
|
||||
app.use('/api-docs', swaggerUI.serve, swaggerUI.setup(swaggerDocument));
|
||||
9
swagger/swagger.json
Normal file
9
swagger/swagger.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"openapi": "3.0.3",
|
||||
"info": {
|
||||
"title": "E-Commerce Project",
|
||||
"description": "Full Stack Portfolio project built using Postgres, Express, React and TypeScript",
|
||||
"version": "0.0.1"
|
||||
},
|
||||
"paths": {}
|
||||
}
|
||||
Reference in New Issue
Block a user