@@ -17,7 +17,7 @@ const router = express.Router()
17
17
router . get ( '/' , async ( req , res ) => {
18
18
try {
19
19
const lists = await List . find ( { public : true } )
20
- if ( ! lists ) {
20
+ if ( ! lists || lists . length === 0 ) {
21
21
return res . status ( 404 ) . json ( { errors : [ { msg : 'No lists found.' } ] } )
22
22
}
23
23
return res . json ( lists )
@@ -34,7 +34,7 @@ router.get('/own', auth, async (req, res) => {
34
34
try {
35
35
const user = await User . findById ( req . user . id )
36
36
const lists = await List . find ( { creator : user . _id } )
37
- if ( ! lists ) {
37
+ if ( ! lists || lists . length === 0 ) {
38
38
return res . status ( 404 ) . json ( { errors : [ { msg : 'You do not own any lists.' } ] } )
39
39
}
40
40
return res . json ( lists )
@@ -45,7 +45,7 @@ router.get('/own', auth, async (req, res) => {
45
45
} )
46
46
47
47
48
- // @route GET api/lists/:id
48
+ // @route GET api/lists/public/id/ :id
49
49
// @desc Get a public list by ID
50
50
// @access Public
51
51
router . get ( '/public/id/:id' , async ( req , res ) => {
@@ -72,7 +72,7 @@ router.get('/public/id/:id', async (req, res) => {
72
72
router . get ( '/public/search/:term' , async ( req , res ) => {
73
73
try {
74
74
// If no term is passed, just return an empty array
75
- if ( ! req . params . term ) {
75
+ if ( ! req . params . term || req . params . term === '' ) {
76
76
return res . json ( [ ] )
77
77
}
78
78
const lists = await List . find ( { $and :
@@ -88,7 +88,7 @@ router.get('/public/search/:term', async (req, res) => {
88
88
}
89
89
} )
90
90
91
- // @route GET api/lists/:id
91
+ // @route GET api/lists/private/ :id
92
92
// @desc Get a public list, or private list user owns
93
93
// @access Private
94
94
router . get ( '/private/:id' , auth , async ( req , res ) => {
@@ -208,7 +208,7 @@ router.post('/', [auth, [
208
208
209
209
const numberOfLists = user . lists . length
210
210
if ( numberOfLists >= 100 ) {
211
- console . log ( 'User already has ' + numberOfLists + ' lists.' )
211
+ console . log ( 'User ' + user . name + ' already has ' + numberOfLists + ' lists.' )
212
212
// Prevent a user from owning more than 100 lists
213
213
return res . status ( 401 ) . json ( { errors : [ { msg : 'You cannot have more than 100 lists.' } ] } )
214
214
}
0 commit comments