Commit 6cdaa3af authored by Clement Brizard's avatar Clement Brizard

Added eslint support

parent bb27a3d4
module.exports = {
env: {
browser: true,
commonjs: true,
es6: true,
node: true,
},
extends: 'airbnb-base',
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parserOptions: {
ecmaVersion: 2018,
},
rules: {
},
};
const express = require('express')
, router = express.Router()
, Debate = require('../models/debate')
const express = require('express');
const Debate = require('../models/debate');
const router = express.Router();
// Get all debates
router.get('/', (req, res) => {
Debate.all(req.db, (err, debates) => {
res.json(debates);
})
})
Debate.all(req.db, (err, debates) => {
res.json(debates);
});
});
// Get one debate
router.get('/:id', (req, res) => {
Debate.one(req.db, req.params.id, (err, debate) => {
res.json(debate);
})
})
Debate.one(req.db, req.params.id, (err, debate) => {
res.json(debate);
});
});
// Create a new debate
router.post('/', (req, res) => {
const obj = {
question : req.params.question,
};
const obj = {
question: req.params.question,
};
Debate.new(req.db, obj, (err, debate) => {
res.json(debate);
});
})
Debate.new(req.db, obj, (err, debate) => {
res.json(debate);
});
});
module.exports = router
module.exports = router;
const express = require('express')
, router = express.Router()
const express = require('express');
router.use('/debates', require('./debate'))
const router = express.Router();
module.exports = router
router.use('/debates', require('./debate'));
module.exports = router;
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const createError = require('http-errors');
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const monk = require('monk');
var mongo = require('mongodb');
var monk = require('monk');
var db = monk('localhost:27017/agoraviz');
const db = monk('localhost:27017/agoraviz');
var app = express();
const app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
......@@ -21,23 +20,24 @@ app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
// Make our db accessible to our router
app.use(function(req,res,next){
req.db = db;
next();
app.use((req, res, next) => {
req.db = db;
next();
});
var indexRouter = require('./controllers');
var apiRouter = require('./api');
const indexRouter = require('./controllers');
const apiRouter = require('./api');
app.use('/', indexRouter);
app.use('/api', apiRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404) );
app.use((req, res, next) => {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
app.use((err, req, res) => {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
......
const express = require('express')
, router = express.Router()
, Debate = require('../models/debate')
const express = require('express');
const Debate = require('../models/debate');
const router = express.Router();
/*
CRUD
......@@ -8,18 +9,17 @@ const express = require('express')
// Create a new debate
router.post('/', (req, res) => {
console.log(req.body);
const obj = {
question : req.body.question,
};
Debate.new(req.db, obj, (err, debate) => {
if (err) {
res.send("Error when trying to create a debate");
}
res.redirect("/");
});
const obj = {
question: req.body.question,
};
Debate.new(req.db, obj, (err) => {
if (err) {
res.send('Error when trying to create a debate');
}
res.redirect('/');
});
});
......@@ -29,10 +29,11 @@ router.post('/', (req, res) => {
// Get new debate form
router.get('/new', (req, res) => {
res.render(
'pages/debate/newDebate',
{ title: 'Lancer un nouveau débat' }
);
res.render(
'pages/debate/newDebate', {
title: 'Lancer un nouveau débat',
},
);
});
module.exports = router;
const express = require('express')
, router = express.Router()
const express = require('express');
router.use('/debates', require('./debate'))
const router = express.Router();
router.use('/debates', require('./debate'));
router.get('/', (req, res) => {
res.render('index', { title: 'AgoraViz' })
})
res.render('index', {
title: 'AgoraViz',
});
});
module.exports = router
module.exports = router;
// Get all debates
exports.all = (db, cb) => {
db.get("debatcollection").find({},{}, (err,docs) => {
if (err) return cb(err);
return cb(null, docs);
});
}
db.get('debatcollection').find({}, {}, (err, docs) => {
if (err) return cb(err);
return cb(null, docs);
});
};
// Get one debate
exports.one = (db, id, cb) => {
db.get("debatcollection").find({
_id : id,
},{}, (err,docs) => {
if (err) return cb(err);
return cb(null, docs[0]);
});
}
db.get('debatcollection').find({
_id: id,
}, {}, (err, docs) => {
if (err) return cb(err);
return cb(null, docs[0]);
});
};
// Create a new debate
exports.new = (db, obj, cb) => {
db.get("debatcollection").insert({
"question" : obj.question,
}, {}, (err, doc) => {
if (err) return cb(err);
return cb(null, doc);
});
}
db.get('debatcollection').insert({
question: obj.question,
}, {}, (err, doc) => {
if (err) return cb(err);
return cb(null, doc);
});
};
This diff is collapsed.
......@@ -14,5 +14,10 @@
"mongodb": "^3.2.4",
"monk": "^6.0.6",
"morgan": "~1.9.1"
},
"devDependencies": {
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.17.3"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment