Skip to content

Commit acaa26f

Browse files
committed
chore: eslint fixes
1 parent 3bcd752 commit acaa26f

File tree

11 files changed

+408
-484
lines changed

11 files changed

+408
-484
lines changed

.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ module.exports = {
1010
sourceType: 'module',
1111
},
1212
rules: {},
13+
globals: {
14+
describe: true,
15+
it: true,
16+
beforeEach: true,
17+
},
1318
};

index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const bodyParser = require('body-parser');
33
const express = require('express');
44
const mongoose = require('mongoose');
55
const morgan = require('morgan');
6+
67
const app = express();
78

89
const http = require('http').Server(app);
@@ -27,19 +28,20 @@ app.use(bodyParser.json());
2728

2829
app.use(morgan('dev'));
2930

30-
app.use(express.static(__dirname + '/public'));
31+
app.use(express.static(`${__dirname}/public`));
32+
33+
const api = require('./server/routes/index')(app, express);
3134

32-
var api = require('./server/routes/index')(app, express);
3335
app.use('/api', api);
3436

35-
app.get('*', function (req, res) {
37+
app.get('*', (req, res) => {
3638
res.send('System Under Construction...');
3739
});
3840

39-
http.listen(config.port, function (err) {
41+
http.listen(config.port, (err) => {
4042
if (err) {
4143
console.log(err);
4244
} else {
43-
console.log('Listening on port: ' + config.port);
45+
console.log(`Listening on port: ${config.port}`);
4446
}
4547
});

seeders/index.js

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,66 @@
11
require('dotenv').config();
2-
3-
const User = require('../server/models/users'),
4-
mongoose = require('mongoose'),
5-
config = require('../server/config/config');
2+
const mongoose = require('mongoose');
3+
const User = require('../server/models/users');
4+
const config = require('../server/config/config');
65

76
// seed users
87
const seedUsers = async () => {
98
const users = [
10-
new User({
9+
{
1110
firstname: 'Sadiq',
1211
lastname: 'Malika',
1312
password: '12345',
1413
email: 'smalik@gmail.com',
1514
username: 'smalik',
1615
role: 'User',
17-
}),
18-
new User({
16+
},
17+
{
1918
firstname: 'Thomas',
2019
lastname: 'Nyambati',
2120
password: '12345',
2221
email: 'tnyambati@gmail.com',
2322
username: 'tn',
2423
role: 'User',
25-
}),
26-
new User({
24+
},
25+
{
2726
username: 'Sonnie',
2827
password: '12345',
2928
firstname: 'Sonia',
3029
lastname: 'Granger',
3130
email: 'sgranger@gmail.com',
3231
role: 'Administrator',
33-
}),
32+
},
3433
];
3534

36-
return await Promise.all(
35+
return Promise.all(
3736
users.map(async (user) => {
38-
user.password = User.hashPassword(user.password);
37+
const modelUser = new User({ ...user });
38+
modelUser.password = User.hashPassword(user.password);
3939
// find a role based on the input on the body
40-
return await user
40+
return modelUser
4141
.save()
42-
.then((data) => console.log(`Seeded user ${data.firstname}`))
43-
.catch((err) => console.error(err));
42+
.then((data) => data)
43+
.catch((err) => {
44+
throw new Error(err);
45+
});
4446
}),
4547
);
4648
};
4749

48-
const seeder = async () => {
49-
return await mongoose
50+
const seeder = async () =>
51+
mongoose
5052
.connect(config.database)
51-
.then(
52-
async () =>
53-
await mongoose.connection.db
54-
.dropDatabase()
55-
.then(async () => await Promise.all([seedUsers()]))
56-
.then(() => process.exit())
57-
.catch((err) => {
58-
throw new Error(err);
59-
}),
53+
.then(async () =>
54+
mongoose.connection.db
55+
.dropDatabase()
56+
.then(async () => Promise.all([seedUsers()]))
57+
.then(() => process.exit())
58+
.catch((err) => {
59+
throw new Error(err);
60+
}),
6061
)
61-
.catch((err) => console.error(err));
62-
};
62+
.catch((err) => {
63+
throw new Error(err);
64+
});
6365

6466
seeder();

server/controllers/auth.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
(function () {
2-
'use strict';
3-
// require the module jsonwebtoken
4-
var config = require('../config/config'),
5-
jsonwebtoken = require('jsonwebtoken'),
6-
secretKey = config.secretKey;
1+
const jsonwebtoken = require('jsonwebtoken');
2+
const config = require('../config/config');
3+
4+
const { secretKey } = config;
75

6+
(function () {
87
module.exports = {
98
// function checks for the token
10-
authenticate: function (req, res, next) {
9+
authenticate(req, res, next) {
1110
const token =
1211
req.body.token || req.params.token || req.headers['x-access-token'];
1312
// check if token exists
1413
if (token) {
15-
jsonwebtoken.verify(token, secretKey, function (err, decoded) {
14+
jsonwebtoken.verify(token, secretKey, (err, decoded) => {
1615
if (err) {
1716
res.status(403).send({
1817
success: false,

0 commit comments

Comments
 (0)