forked from docker/awesome-compose
-
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.
to fix some syntax issues in the existing code, the commit put in place prettier and format the code Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com>
- Loading branch information
Showing
12 changed files
with
149 additions
and
140 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 |
---|---|---|
|
@@ -2,3 +2,4 @@ frontend/node_modules/ | |
server/node_modules/ | ||
.idea/ | ||
data | ||
*.log |
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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
var env = process.env.NODE_ENV || 'development'; | ||
const env = process.env.NODE_ENV || "development"; | ||
|
||
if(env === 'development' || env === 'test'){ | ||
if (env === "development" || env === "test") { | ||
const config = require("./config.json"); | ||
const envConfig = config[env]; | ||
console.log(envConfig); | ||
|
||
const config = require('./config.json') | ||
let envConfig = config[env]; | ||
console.log(envConfig); | ||
|
||
Object.keys(envConfig).forEach((key) => { | ||
process.env[key] = envConfig[key] | ||
}) | ||
Object.keys(envConfig).forEach((key) => { | ||
process.env[key] = envConfig[key]; | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,62 +1,62 @@ | ||
module.exports = { | ||
AUTHENTICATION_FAILED: { | ||
code: 400, | ||
message: 'Authentication failed. Please login with valid credentials.', | ||
success: false, | ||
}, | ||
SUCCESSFUL_LOGIN: { | ||
code: 200, | ||
message: 'Successfully logged in', | ||
success: true, | ||
}, | ||
INTERNAL_SERVER_ERROR: { | ||
code: 500, | ||
message: 'Something unexpected happened', | ||
success: false, | ||
}, | ||
UNAUTHORIZED: { | ||
code: 401, | ||
message: 'You session is expired. Please login again', | ||
success: false, | ||
}, | ||
SUCCESSFUL_DELETE: { | ||
code: 200, | ||
message: 'Successfully deleted', | ||
success: true, | ||
}, | ||
SUCCESSFUL_UPDATE: { | ||
code: 200, | ||
message: 'Updated successfully', | ||
success: true, | ||
}, | ||
SUCCESSFUL: { | ||
code: 200, | ||
success: true, | ||
message: 'Successfully completed', | ||
}, | ||
NOT_FOUND: { | ||
code: 404, | ||
success: true, | ||
message: 'Requested API not found', | ||
}, | ||
ALREADY_EXIST: { | ||
code: 200, | ||
success: true, | ||
message: 'Already exists', | ||
}, | ||
FORBIDDEN: { | ||
code: 403, | ||
message: 'You are not authorized to complete this action', | ||
success: false, | ||
}, | ||
BAD_REQUEST: { | ||
code: 400, | ||
message: 'Bad request. Please try again with valid parameters', | ||
success: false, | ||
}, | ||
IN_COMPLETE_REQUEST: { | ||
code: 422, | ||
message: 'Required parameter missing', | ||
success: false, | ||
}, | ||
AUTHENTICATION_FAILED: { | ||
code: 400, | ||
message: "Authentication failed. Please login with valid credentials.", | ||
success: false, | ||
}, | ||
SUCCESSFUL_LOGIN: { | ||
code: 200, | ||
message: "Successfully logged in", | ||
success: true, | ||
}, | ||
INTERNAL_SERVER_ERROR: { | ||
code: 500, | ||
message: "Something unexpected happened", | ||
success: false, | ||
}, | ||
UNAUTHORIZED: { | ||
code: 401, | ||
message: "You session is expired. Please login again", | ||
success: false, | ||
}, | ||
SUCCESSFUL_DELETE: { | ||
code: 200, | ||
message: "Successfully deleted", | ||
success: true, | ||
}, | ||
SUCCESSFUL_UPDATE: { | ||
code: 200, | ||
message: "Updated successfully", | ||
success: true, | ||
}, | ||
SUCCESSFUL: { | ||
code: 200, | ||
success: true, | ||
message: "Successfully completed", | ||
}, | ||
NOT_FOUND: { | ||
code: 404, | ||
success: true, | ||
message: "Requested API not found", | ||
}, | ||
ALREADY_EXIST: { | ||
code: 200, | ||
success: true, | ||
message: "Already exists", | ||
}, | ||
FORBIDDEN: { | ||
code: 403, | ||
message: "You are not authorized to complete this action", | ||
success: false, | ||
}, | ||
BAD_REQUEST: { | ||
code: 400, | ||
message: "Bad request. Please try again with valid parameters", | ||
success: false, | ||
}, | ||
IN_COMPLETE_REQUEST: { | ||
code: 422, | ||
message: "Required parameter missing", | ||
success: false, | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1,30 +1,32 @@ | ||
/** | ||
* Created by Syed Afzal | ||
*/ | ||
const mongoose = require('mongoose'); | ||
const {log} = require('../utils/helpers/logger'); | ||
const mongoose = require("mongoose"); | ||
|
||
exports.connect = (app) => { | ||
const options = { | ||
useNewUrlParser: true, | ||
autoIndex: false, // Don't build indexes | ||
reconnectTries: 30, // Retry up to 30 times | ||
reconnectInterval: 500, // Reconnect every 500ms | ||
poolSize: 10, // Maintain up to 10 socket connections | ||
// If not connected, return errors immediately rather than waiting for reconnect | ||
bufferMaxEntries: 0 | ||
} | ||
const options = { | ||
useNewUrlParser: true, | ||
autoIndex: false, // Don't build indexes | ||
reconnectTries: 30, // Retry up to 30 times | ||
reconnectInterval: 500, // Reconnect every 500ms | ||
poolSize: 10, // Maintain up to 10 socket connections | ||
// If not connected, return errors immediately rather than waiting for reconnect | ||
bufferMaxEntries: 0, | ||
}; | ||
|
||
const connectWithRetry = () => { | ||
mongoose.Promise = global.Promise; | ||
console.log('MongoDB connection with retry') | ||
mongoose.connect(process.env.MONGODB_URI, options).then(()=>{ | ||
console.log('MongoDB is connected'); | ||
app.emit('ready'); | ||
}).catch(err=>{ | ||
console.log('MongoDB connection unsuccessful, retry after 2 seconds.') | ||
setTimeout(connectWithRetry, 2000) | ||
}) | ||
} | ||
connectWithRetry(); | ||
const connectWithRetry = () => { | ||
mongoose.Promise = global.Promise; | ||
console.log("MongoDB connection with retry"); | ||
mongoose | ||
.connect(process.env.MONGODB_URI, options) | ||
.then(() => { | ||
console.log("MongoDB is connected"); | ||
app.emit("ready"); | ||
}) | ||
.catch((err) => { | ||
console.log("MongoDB connection unsuccessful, retry after 2 seconds."); | ||
setTimeout(connectWithRetry, 2000); | ||
}); | ||
}; | ||
connectWithRetry(); | ||
}; |
Empty file.
Binary file not shown.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,38 +1,38 @@ | ||
const express = require('express'); | ||
const serverResponses = require('../utils/helpers/server.responses'); | ||
const messages = require('../config/messages'); | ||
var {Todo} = require('../models/todos/todo.model'); | ||
const express = require("express"); | ||
const serverResponses = require("../utils/helpers/responses"); | ||
const messages = require("../config/messages"); | ||
const { Todo } = require("../models/todos/todo"); | ||
|
||
const routes = (app) => { | ||
const router = express.Router(); | ||
const router = express.Router(); | ||
|
||
router.post('/todos', (req,res)=>{ | ||
var todo = new Todo({ | ||
text: req.body.text | ||
}); | ||
|
||
todo.save() | ||
.then((result)=>{ | ||
serverResponses.sendSuccess(res,messages.SUCCESSFUL, result); | ||
}) | ||
.catch((e) => { | ||
serverResponses.sendError(res,messages.BAD_REQUEST,e) | ||
}) | ||
router.post("/todos", (req, res) => { | ||
const todo = new Todo({ | ||
text: req.body.text, | ||
}); | ||
|
||
router.get('/', (req,res) => { | ||
Todo.find({}, {__v:0}) | ||
.then((todos)=>{ | ||
serverResponses.sendSuccess(res,messages.SUCCESSFUL, todos); | ||
todo | ||
.save() | ||
.then((result) => { | ||
serverResponses.sendSuccess(res, messages.SUCCESSFUL, result); | ||
}) | ||
.catch((e) => { | ||
serverResponses.sendError(res, messages.BAD_REQUEST, e); | ||
}); | ||
}); | ||
|
||
}) | ||
.catch((e) => { | ||
serverResponses.sendError(res,messages.BAD_REQUEST,e) | ||
}) | ||
}); | ||
router.get("/", (req, res) => { | ||
Todo.find({}, { __v: 0 }) | ||
.then((todos) => { | ||
serverResponses.sendSuccess(res, messages.SUCCESSFUL, todos); | ||
}) | ||
.catch((e) => { | ||
serverResponses.sendError(res, messages.BAD_REQUEST, e); | ||
}); | ||
}); | ||
|
||
//it's a prefix before api it is useful when you have many modules and you want to | ||
//differentiate b/w each module you can use this technique | ||
app.use('/api', router); | ||
//it's a prefix before api it is useful when you have many modules and you want to | ||
//differentiate b/w each module you can use this technique | ||
app.use("/api", router); | ||
}; | ||
module.exports = routes; | ||
module.exports = routes; |
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
File renamed without changes.