Skip to content

Commit 7697e61

Browse files
committed
Updated code as per editor config
1 parent 6f1a258 commit 7697e61

File tree

7 files changed

+233
-233
lines changed

7 files changed

+233
-233
lines changed

controllers/login.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ const router = express.Router();
66
const user = require('../helpers/user');
77

88
router.post('/login', (req, res) => {
9-
user.checkLogin(req.body.username, req.body.password)
10-
.then(user => {
11-
if (!!user) {
12-
let token = jwt.sign({username: user.username}, process.env.APP_SECRET, {
13-
expiresIn: process.env.JWT_EXPIRES_IN
14-
});
15-
return res.send({token: token});
16-
}
17-
18-
return res.status(httpStatus.UNAUTHORIZED).send({msg: 'Fail'});
19-
})
20-
.catch(error => {
21-
return res.status(httpStatus.INTERNAL_SERVER_ERROR).send(error)
9+
user.checkLogin(req.body.username, req.body.password)
10+
.then(user => {
11+
if (!!user) {
12+
let token = jwt.sign({username: user.username}, process.env.APP_SECRET, {
13+
expiresIn: process.env.JWT_EXPIRES_IN
2214
});
15+
return res.send({token: token});
16+
}
17+
18+
return res.status(httpStatus.UNAUTHORIZED).send({msg: 'Fail'});
19+
})
20+
.catch(error => {
21+
return res.status(httpStatus.INTERNAL_SERVER_ERROR).send(error)
22+
});
2323
});
2424

25-
module.exports = router;
25+
module.exports = router;

controllers/todo.js

+36-36
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,53 @@ const router = express.Router();
55
const todo = require('../helpers/todo');
66

77
router.post('/todo/search', (req, res) => {
8-
todo.getTodoBySearch(req.body)
9-
.then(todos => {
10-
return res.send(todos);
11-
})
12-
.catch(error => {
13-
return res.status(httpStatus.INTERNAL_SERVER_ERROR).send(error);
14-
});
8+
todo.getTodoBySearch(req.body)
9+
.then(todos => {
10+
return res.send(todos);
11+
})
12+
.catch(error => {
13+
return res.status(httpStatus.INTERNAL_SERVER_ERROR).send(error);
14+
});
1515
});
1616

1717
router.get('/todo', (req, res) => {
18-
todo.getAllTodos()
19-
.then(todos => {
20-
return res.send(todos);
21-
})
22-
.catch(error => {
23-
return res.status(httpStatus.INTERNAL_SERVER_ERROR).send(error);
24-
});
18+
todo.getAllTodos()
19+
.then(todos => {
20+
return res.send(todos);
21+
})
22+
.catch(error => {
23+
return res.status(httpStatus.INTERNAL_SERVER_ERROR).send(error);
24+
});
2525
});
2626

2727
router.post('/todo', (req, res) => {
28-
todo.addTodo(req.body)
29-
.then(todo => {
30-
return res.send(todo);
31-
})
32-
.catch(error => {
33-
return res.status(httpStatus.INTERNAL_SERVER_ERROR).send(error);
34-
});
28+
todo.addTodo(req.body)
29+
.then(todo => {
30+
return res.send(todo);
31+
})
32+
.catch(error => {
33+
return res.status(httpStatus.INTERNAL_SERVER_ERROR).send(error);
34+
});
3535
});
3636

3737
router.put('/todo/:id', (req, res) => {
38-
todo.updateTodo(req.body, req.params.id)
39-
.then(todo => {
40-
return res.send(todo);
41-
})
42-
.catch(error => {
43-
return res.status(httpStatus.INTERNAL_SERVER_ERROR).send(error);
44-
});
38+
todo.updateTodo(req.body, req.params.id)
39+
.then(todo => {
40+
return res.send(todo);
41+
})
42+
.catch(error => {
43+
return res.status(httpStatus.INTERNAL_SERVER_ERROR).send(error);
44+
});
4545
});
4646

4747
router.delete('/todo/:id', (req, res) => {
48-
todo.removeTodo(req.params.id)
49-
.then(todo => {
50-
return res.send(todo);
51-
})
52-
.catch(error => {
53-
return res.status(httpStatus.INTERNAL_SERVER_ERROR).send(error);
54-
});
48+
todo.removeTodo(req.params.id)
49+
.then(todo => {
50+
return res.send(todo);
51+
})
52+
.catch(error => {
53+
return res.status(httpStatus.INTERNAL_SERVER_ERROR).send(error);
54+
});
5555
});
5656

57-
module.exports = router;
57+
module.exports = router;

helpers/todo.js

+54-54
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const todo = require('../models/todo');
66
* @return {err} - return error
77
*/
88
let getTodoBySearch = (params) => {
9-
return todo
10-
.search(params)
11-
.then((todos) => Promise.resolve(todos))
12-
.catch((err) => Promise.reject(err));
9+
return todo
10+
.search(params)
11+
.then((todos) => Promise.resolve(todos))
12+
.catch((err) => Promise.reject(err));
1313
};
1414

1515
/**
@@ -18,12 +18,12 @@ let getTodoBySearch = (params) => {
1818
* @return {err} - return error
1919
*/
2020
let getAllTodos = () => {
21-
return todo
22-
.find({})
23-
.sort({name: 1})
24-
.exec()
25-
.then((todos) => Promise.resolve(todos))
26-
.catch((err) => Promise.reject(err));
21+
return todo
22+
.find({})
23+
.sort({name: 1})
24+
.exec()
25+
.then((todos) => Promise.resolve(todos))
26+
.catch((err) => Promise.reject(err));
2727
};
2828

2929
/**
@@ -33,11 +33,11 @@ let getAllTodos = () => {
3333
* @return {err} - return error
3434
*/
3535
let getTodoById = (id) => {
36-
return todo
37-
.findById(id)
38-
.exec()
39-
.then((todo) => Promise.resolve(todo))
40-
.catch((err) => Promise.reject(err));
36+
return todo
37+
.findById(id)
38+
.exec()
39+
.then((todo) => Promise.resolve(todo))
40+
.catch((err) => Promise.reject(err));
4141
};
4242

4343
/**
@@ -47,13 +47,13 @@ let getTodoById = (id) => {
4747
* @return {err} - return error
4848
*/
4949
let getTodoByName = (name) => {
50-
return todo
51-
.findOne({
52-
name: new RegExp('^' + name + '$', "i")
53-
})
54-
.exec()
55-
.then((todo) => Promise.resolve(todo))
56-
.catch((err) => Promise.reject(err));
50+
return todo
51+
.findOne({
52+
name: new RegExp('^' + name + '$', "i")
53+
})
54+
.exec()
55+
.then((todo) => Promise.resolve(todo))
56+
.catch((err) => Promise.reject(err));
5757
};
5858

5959
/**
@@ -63,13 +63,13 @@ let getTodoByName = (name) => {
6363
* @return {err} - return error
6464
*/
6565
let addTodo = (req) => {
66-
let oTodo = new todo();
67-
oTodo.name = req.name;
68-
oTodo.description = req.description;
66+
let oTodo = new todo();
67+
oTodo.name = req.name;
68+
oTodo.description = req.description;
6969

70-
return oTodo.save()
71-
.then(todo => Promise.resolve(todo))
72-
.catch(err => Promise.reject(err));
70+
return oTodo.save()
71+
.then(todo => Promise.resolve(todo))
72+
.catch(err => Promise.reject(err));
7373
};
7474

7575
/**
@@ -79,17 +79,17 @@ let addTodo = (req) => {
7979
* @return {err} - return error
8080
*/
8181
let updateTodo = (req, id) => {
82-
return todo
83-
.findById(id)
84-
.exec()
85-
.then((oTodo) => {
86-
oTodo.name = req.name || oTodo.name;
87-
oTodo.description = req.description || oTodo.description;
88-
return oTodo.save()
89-
.then(updatedTodo => Promise.resolve(updatedTodo))
90-
.catch(err => Promise.reject(err));
91-
})
82+
return todo
83+
.findById(id)
84+
.exec()
85+
.then((oTodo) => {
86+
oTodo.name = req.name || oTodo.name;
87+
oTodo.description = req.description || oTodo.description;
88+
return oTodo.save()
89+
.then(updatedTodo => Promise.resolve(updatedTodo))
9290
.catch(err => Promise.reject(err));
91+
})
92+
.catch(err => Promise.reject(err));
9393
};
9494

9595
/**
@@ -99,24 +99,24 @@ let updateTodo = (req, id) => {
9999
* @return {err} - return error
100100
*/
101101
let removeTodo = (id) => {
102-
return todo
103-
.findById(id)
104-
.exec()
105-
.then((oTodo) => {
106-
return oTodo
107-
.remove()
108-
.then((rTodo) => Promise.resolve(rTodo))
109-
.catch(err => Promise.reject(err));
110-
})
102+
return todo
103+
.findById(id)
104+
.exec()
105+
.then((oTodo) => {
106+
return oTodo
107+
.remove()
108+
.then((rTodo) => Promise.resolve(rTodo))
111109
.catch(err => Promise.reject(err));
110+
})
111+
.catch(err => Promise.reject(err));
112112
};
113113

114114
module.exports = {
115-
getAllTodos,
116-
getTodoById,
117-
getTodoByName,
118-
addTodo,
119-
updateTodo,
120-
removeTodo,
121-
getTodoBySearch
115+
getAllTodos,
116+
getTodoById,
117+
getTodoByName,
118+
addTodo,
119+
updateTodo,
120+
removeTodo,
121+
getTodoBySearch
122122
};

0 commit comments

Comments
 (0)