react-express-mongodb: lint sources
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>master
parent
be8875c9b6
commit
be7f09b6ba
@ -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 config = require('./config.json')
|
const envConfig = config[env];
|
||||||
let envConfig = config[env];
|
|
||||||
console.log(envConfig);
|
console.log(envConfig);
|
||||||
|
|
||||||
Object.keys(envConfig).forEach((key) => {
|
Object.keys(envConfig).forEach((key) => {
|
||||||
process.env[key] = envConfig[key]
|
process.env[key] = envConfig[key];
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,62 +1,62 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
AUTHENTICATION_FAILED: {
|
AUTHENTICATION_FAILED: {
|
||||||
code: 400,
|
code: 400,
|
||||||
message: 'Authentication failed. Please login with valid credentials.',
|
message: "Authentication failed. Please login with valid credentials.",
|
||||||
success: false,
|
success: false,
|
||||||
},
|
},
|
||||||
SUCCESSFUL_LOGIN: {
|
SUCCESSFUL_LOGIN: {
|
||||||
code: 200,
|
code: 200,
|
||||||
message: 'Successfully logged in',
|
message: "Successfully logged in",
|
||||||
success: true,
|
success: true,
|
||||||
},
|
},
|
||||||
INTERNAL_SERVER_ERROR: {
|
INTERNAL_SERVER_ERROR: {
|
||||||
code: 500,
|
code: 500,
|
||||||
message: 'Something unexpected happened',
|
message: "Something unexpected happened",
|
||||||
success: false,
|
success: false,
|
||||||
},
|
},
|
||||||
UNAUTHORIZED: {
|
UNAUTHORIZED: {
|
||||||
code: 401,
|
code: 401,
|
||||||
message: 'You session is expired. Please login again',
|
message: "You session is expired. Please login again",
|
||||||
success: false,
|
success: false,
|
||||||
},
|
},
|
||||||
SUCCESSFUL_DELETE: {
|
SUCCESSFUL_DELETE: {
|
||||||
code: 200,
|
code: 200,
|
||||||
message: 'Successfully deleted',
|
message: "Successfully deleted",
|
||||||
success: true,
|
success: true,
|
||||||
},
|
},
|
||||||
SUCCESSFUL_UPDATE: {
|
SUCCESSFUL_UPDATE: {
|
||||||
code: 200,
|
code: 200,
|
||||||
message: 'Updated successfully',
|
message: "Updated successfully",
|
||||||
success: true,
|
success: true,
|
||||||
},
|
},
|
||||||
SUCCESSFUL: {
|
SUCCESSFUL: {
|
||||||
code: 200,
|
code: 200,
|
||||||
success: true,
|
success: true,
|
||||||
message: 'Successfully completed',
|
message: "Successfully completed",
|
||||||
},
|
},
|
||||||
NOT_FOUND: {
|
NOT_FOUND: {
|
||||||
code: 404,
|
code: 404,
|
||||||
success: true,
|
success: true,
|
||||||
message: 'Requested API not found',
|
message: "Requested API not found",
|
||||||
},
|
},
|
||||||
ALREADY_EXIST: {
|
ALREADY_EXIST: {
|
||||||
code: 200,
|
code: 200,
|
||||||
success: true,
|
success: true,
|
||||||
message: 'Already exists',
|
message: "Already exists",
|
||||||
},
|
},
|
||||||
FORBIDDEN: {
|
FORBIDDEN: {
|
||||||
code: 403,
|
code: 403,
|
||||||
message: 'You are not authorized to complete this action',
|
message: "You are not authorized to complete this action",
|
||||||
success: false,
|
success: false,
|
||||||
},
|
},
|
||||||
BAD_REQUEST: {
|
BAD_REQUEST: {
|
||||||
code: 400,
|
code: 400,
|
||||||
message: 'Bad request. Please try again with valid parameters',
|
message: "Bad request. Please try again with valid parameters",
|
||||||
success: false,
|
success: false,
|
||||||
},
|
},
|
||||||
IN_COMPLETE_REQUEST: {
|
IN_COMPLETE_REQUEST: {
|
||||||
code: 422,
|
code: 422,
|
||||||
message: 'Required parameter missing',
|
message: "Required parameter missing",
|
||||||
success: false,
|
success: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Binary file not shown.
@ -1,38 +1,38 @@
|
|||||||
const express = require('express');
|
const express = require("express");
|
||||||
const serverResponses = require('../utils/helpers/server.responses');
|
const serverResponses = require("../utils/helpers/responses");
|
||||||
const messages = require('../config/messages');
|
const messages = require("../config/messages");
|
||||||
var {Todo} = require('../models/todos/todo.model');
|
const { Todo } = require("../models/todos/todo");
|
||||||
|
|
||||||
const routes = (app) => {
|
const routes = (app) => {
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
router.post('/todos', (req,res)=>{
|
router.post("/todos", (req, res) => {
|
||||||
var todo = new Todo({
|
const todo = new Todo({
|
||||||
text: req.body.text
|
text: req.body.text,
|
||||||
});
|
});
|
||||||
|
|
||||||
todo.save()
|
todo
|
||||||
.then((result)=>{
|
.save()
|
||||||
serverResponses.sendSuccess(res,messages.SUCCESSFUL, result);
|
.then((result) => {
|
||||||
|
serverResponses.sendSuccess(res, messages.SUCCESSFUL, result);
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
serverResponses.sendError(res,messages.BAD_REQUEST,e)
|
serverResponses.sendError(res, messages.BAD_REQUEST, e);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/', (req,res) => {
|
router.get("/", (req, res) => {
|
||||||
Todo.find({}, {__v:0})
|
Todo.find({}, { __v: 0 })
|
||||||
.then((todos)=>{
|
.then((todos) => {
|
||||||
serverResponses.sendSuccess(res,messages.SUCCESSFUL, todos);
|
serverResponses.sendSuccess(res, messages.SUCCESSFUL, todos);
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
serverResponses.sendError(res,messages.BAD_REQUEST,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
|
//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
|
//differentiate b/w each module you can use this technique
|
||||||
app.use('/api', router);
|
app.use("/api", router);
|
||||||
};
|
};
|
||||||
module.exports = routes;
|
module.exports = routes;
|
Loading…
Reference in New Issue