Completed
Push — master ( 20d56b...f5fa55 )
by Anil Kumar
01:25
created

app.post(ꞌ/inviteUserꞌ)   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 25
rs 8.8571

2 Functions

Rating   Name   Duplication   Size   Complexity  
A ��) 0 17 1
A ��) 0 3 1
1
require('dotenv').config();
2
var express = require('express');
3
var path = require('path');
4
var cons = require('consolidate');
5
6
var port = 8080;
7
var app = module.exports = express();
8
var swig = require('swig');
9
10
// handlebars initiation
11
var exphbs = require('express-handlebars');
12
var hbs = exphbs.create({});
13
14
// Configure View and Handlebars
15
app.use(express.static(path.join(__dirname)));
16
app.engine('handlebars', hbs.engine);
17
app.set('views', path.join(__dirname, 'views'));
18
app.set('view engine', 'handlebars');
19
20
21
22
// Create body parsers for application/json and application/x-www-form-urlencoded
23
var bodyParser = require('body-parser')
24
app.use(bodyParser.json())
25
var urlencodedParser = bodyParser.urlencoded({ extended: false })
26
27
if(!module.parent){ app.listen(process.env.PORT || port); }
28
29
console.log("Application started. Listening on port:" + port);
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...
30
31
32
var ringcentral = require('ringcentral');
33
34
var rcsdk = new ringcentral({
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like ringcentral should be capitalized.
Loading history...
35
    server: process.env.GLIP_APP_SERVER_URL,
36
    appKey: process.env.GLIP_APP_KEY,
37
    appSecret: process.env.GLIP_APP_SECRET
38
});
39
40
var groupMembers;
41
var userList = [];
42
43
    // Route for the home page
44
    app.get('/inviteDemo', function (req, res) {
45
        var badge = swig.renderFile(path.join(__dirname, '/views/badge.svg'));
46
        res.writeHead(200, {"Content-Type": "image/svg+xml"})
47
        res.write(badge);
48
        res.send();
49
    });
50
    // Route for the inviteDemo
51
    app.get('/', function (req, res) {
52
53
        console.log('Insdei');
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...
54
        rcsdk.platform()
55
            .login({
56
                username: process.env.GLIP_USERNAME,
57
                extension: process.env.GLIP_EXTENSION || null,
58
                password: process.env.GLIP_PASSWORD
59
            })
60
            .then(function(response) {
0 ignored issues
show
Unused Code introduced by
The parameter response is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
61
                console.log('Logged in to platform');
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...
62
                return rcsdk.platform()
63
                    .get('/glip/groups/' + process.env.GLIP_GROUP_ID)
64
                    .then(function(apiResponse) {
65
                        var response = apiResponse.json();
66
                        if(response.members){
67
                            groupMembers = response.members.length;
68
                            console.log(groupMembers);
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...
69
                        }
70
                        res.render('index', {RC_Logo: process.env.GLIP_LOGO, RC_Community: process.env.GLIP_GROUP_NAME, RC_Total_members: groupMembers, RC_groupId: process.env.GLIP_GROUP_ID});
0 ignored issues
show
Bug introduced by
The variable groupMembers does not seem to be initialized in case response.members on line 66 is false. Are you sure this can never be the case?
Loading history...
71
                    })
72
                    .catch(function(e) {
73
                        console.log('INVITE USER DID NOT WORK');
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...
74
                        console.log(e);
75
                    });
76
            })
77
            .catch(function(e) {
78
                console.log('ERR_CALLBACK ' + e.message  || 'Server cannot authorize user');
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...
79
                res.send('Error');
80
            });
81
    });
82
83
 // Route for the invite user
84
    app.post('/inviteUser', urlencodedParser, function (req, res, next) {
0 ignored issues
show
Unused Code introduced by
The parameter next is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
85
        var userInvite = [ req.body.userInvite || '' ];
86
        userList.push(userInvite);
87
        rcsdk.platform().loggedIn()
88
            .then(function(status) {
0 ignored issues
show
Unused Code introduced by
The parameter status is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
89
                return rcsdk.platform()
90
                	.post('/glip/groups/' + process.env.GLIP_GROUP_ID + '/bulk-assign',{
91
                			"addedPersonEmails": userInvite
92
                		})
93
                	.then(function(response) {
94
                		console.log('The response is :', response.json());
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...
95
                        console.log('The total number of users invited to the grpup is :'+ userList.length);
96
                        console.log('The total number of users registered in the grpup is :'+response.json().members.length);
97
                        console.log("The type of data is :" + typeof userList.length);
98
                        res.send(userList.length.toString());
99
                	})
100
                    .catch(function(e) {
101
                        console.log('INVITE USER DID NOT WORK');
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...
102
                        console.log(e);
103
                    });
104
            })
105
            .catch(function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
106
                res.send("E_NOT_LOGGED_IN");
107
            });
108
    });
109
110
111
module.exports = {
112
    app : app
113
};
114