app/experiments/mongoose-queries.js   A
last analyzed

Complexity

Total Complexity 8
Complexity/F 2

Size

Lines of Code 48
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
nc 4
dl 0
loc 48
rs 10
c 1
b 0
f 0
wmc 8
mnd 2
bc 8
fnc 4
bpm 2
cpm 2
noi 7

1 Function

Rating   Name   Duplication   Size   Complexity  
A mongoose-queries.js ➔ ??? 0 7 2
1
'use strict';
2
const {ObjectID} = require('mongodb');
3
const {mongoose} = require('./../app/db/mongoose');
4
const {Todo} = require('./../app/models/todo');
5
const {User} = require('./../app/models/user');
6
7
let todoID = '5880842ef93e9523e07eece8' + '21';
8
let userID = '587fc1bc462a2b16144f8a07';
9
 
10
if (!ObjectID.isValid(todoID)) {
11
    console.log('Invalid todo ID');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
12
}
13
else {
14
    // Todo.find({
15
    //     _id:id
16
    // }).then((data) => {
17
    //     console.log('Todos : ', data);
18
    // }, (err) => {
19
    //     console.log(err);
20
    // });
21
22
    // Todo.findOne({
23
    //     _id: id
24
    // }).then((data) => {
25
    //     console.log('Todo : ', data);
26
    // });
27
28
    Todo.findById(todoID).then((data) => {
29
        //returns todo as null in case of invalid id
30
        if (!data) {
31
            return console.log('id not found');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
32
        }
33
        console.log('Todo by findById : ', data);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
34
    }).catch((err) => console.log(err));
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
35
    
36
}
37
38
if (!ObjectID.isValid(userID)) {
39
    console.log('Invalid user ID'); 
40
}
41
else {
42
    User.findById(userID).then((data) => {
43
        if (!data) {
44
            return console.log('User ID not found');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
45
        }
46
        console.log(data);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
47
    }).catch((err) => console.log(err));
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
48
}