Skip to content

Commit 63302bb

Browse files
committed
i50: clean lib/*.js
1 parent 9090b0c commit 63302bb

16 files changed

+218
-172
lines changed

Gruntfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ module.exports = function (grunt) {
66
jshintrc: ".jshintrc",
77
ignores : [ "node_modules/**/*.js" ]
88
},
9-
src: ["Gruntfile.js", "app.js"],
9+
src: ["Gruntfile.js", "app.js", "lib/**.js"],
1010
},
1111
jscs: {
12-
src: ["Gruntfile.js", "app.js"],
12+
src: ["Gruntfile.js", "app.js", "lib/**.js"],
1313
options: {
1414
config: ".jscsrc",
1515
requireCurlyBraces: [ "if" ]

lib/autocomplete.js

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var populate = function(service) {
2121
var actions = {};
2222
schema.fields.filter(f => f.facet).forEach(f => {
2323

24-
var name = `sss_${f.name}`
24+
var name = `sss_${f.name}`;
2525

2626
actions[name] = function(callback) {
2727

@@ -31,32 +31,43 @@ var populate = function(service) {
3131
name: name,
3232
url: `${appEnv.url}/autocompletes/${f.name}`
3333
}
34-
}
34+
};
3535

3636
if (service.username && service.password) {
3737
var auth = "Basic " + new Buffer(service.username + ":" + service.password).toString("base64");
3838
opts.headers = {
3939
"Authorization" : auth
40-
}
40+
};
4141
}
4242

4343
request.post(opts, function(err, res, body) {
44-
return callback()
45-
})
4644

47-
}
45+
res = null;
46+
body = null;
47+
err = null;
48+
49+
return callback();
50+
});
4851

49-
})
52+
};
53+
54+
});
5055

5156
async.series(actions, function(err, results) {
5257

58+
if (err) {
59+
return console.log(err);
60+
}
61+
62+
results = null;
63+
5364
console.log("autocompletes done");
5465

55-
})
66+
});
5667

57-
})
68+
});
5869

59-
}
70+
};
6071

6172
var append = function(data, service) {
6273

@@ -75,7 +86,9 @@ var append = function(data, service) {
7586
var actions = {};
7687
schema.fields.filter(f => f.facet).forEach(f => {
7788

78-
if (!data[f.name]) return false;
89+
if (!data[f.name]) {
90+
return false;
91+
}
7992

8093
actions[f.name] = function(callback) {
8194

@@ -84,37 +97,39 @@ var append = function(data, service) {
8497
json: {
8598
term: data[f.name]
8699
}
87-
}
100+
};
88101

89102
if (service.username && service.password) {
90103
var auth = "Basic " + new Buffer(service.username + ":" + service.password).toString("base64");
91104
opts.headers = {
92105
"Authorization" : auth
93-
}
106+
};
94107
}
95108

96109
request.put(opts, function(err, res, body) {
97-
return callback(err, body)
98-
})
110+
return callback(err, body);
111+
});
99112

100-
}
113+
};
101114

102115
});
103116

104117
async.series(actions, function(err, results) {
105118

106-
if (err) return console.log(err);
119+
if (err) {
120+
return console.log(err);
121+
}
107122

108123
console.log("autocomplete appended");
109124
console.log(results);
110125

111-
})
126+
});
112127

113-
})
128+
});
114129

115-
}
130+
};
116131

117132
module.exports = {
118133
populate: populate,
119134
append: append
120-
}
135+
};

lib/cache.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,31 @@ module.exports = function(opts) {
2121
var params = {
2222
method: method,
2323
url: `${opts.host}/key/${key}`
24-
}
24+
};
2525

26-
if (method.toLowerCase() == "post" && value) {
27-
params.form = { value : JSON.stringify(value) }
26+
if (method.toLowerCase() === "post" && value) {
27+
params.form = { value : JSON.stringify(value) };
2828
}
2929

3030
if (opts.username && opts.password) {
3131
var auth = "Basic " + new Buffer(opts.username + ":" + opts.password).toString("base64");
3232
params.headers = {
3333
"Authorization" : auth
34-
}
34+
};
3535
}
3636

3737
request(params, function(e, r, b) {
3838

39-
if (e) return callback(e);
39+
if (e) {
40+
return callback(e);
41+
}
42+
43+
var body = null;
4044

4145
try {
42-
var body = JSON.parse(b);
46+
body = JSON.parse(b);
4347
} catch (e) {
44-
var body = b;
48+
body = b;
4549
}
4650

4751
if (body.success === false || !body.data) {
@@ -50,36 +54,36 @@ module.exports = function(opts) {
5054

5155
return callback(null, body.data);
5256

53-
})
57+
});
5458

55-
}
59+
};
5660

5761
return {
5862

5963
put: function(key, value, callback) {
6064

61-
makeRequest("post", opts.host, key, value, callback)
65+
makeRequest("post", opts.host, key, value, callback);
6266

6367
},
6468

6569
get: function(key, callback) {
6670

67-
makeRequest("get", opts.host, key, null, callback)
71+
makeRequest("get", opts.host, key, null, callback);
6872

6973
},
7074

7175
clearAll: function() {
7276

73-
request({ url: `${opts.host}/clearall`, method: "POST"})
77+
request({ url: `${opts.host}/clearall`, method: "POST"});
7478

7579
},
7680

7781
enabled: opts.enabled,
7882

7983
host: opts.host
8084

81-
}
85+
};
8286

8387
}
8488

85-
}
89+
};

lib/couchmigrate.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ var writedoc = function(db, obj, docid, cb) {
1414
preexistingdoc = data;
1515
}
1616
callback(null, data);
17-
})
17+
});
1818
},
1919
function(callback) {
2020
obj._id = docid;
2121
if (preexistingdoc) {
22-
obj._rev = preexistingdoc._rev
22+
obj._rev = preexistingdoc._rev;
2323
}
2424
console.log("## writedoc - Writing doc", obj);
2525
db.insert(obj, function(err, data) {
2626
debug(err, data);
2727
callback(null, data);
2828
});
2929
}
30-
], cb)
30+
], cb);
3131
};
3232

3333

@@ -41,12 +41,12 @@ var migrate = function(dbname, dd, callback) {
4141
// this is the whole design document
4242
var db = null;
4343
var dd_name = dd._id;
44-
var original_dd = null;
45-
var old_dd = null;
46-
var new_dd = null;
44+
//var original_dd = null;
45+
//var old_dd = null;
46+
//var new_dd = null;
4747
delete dd._rev;
48-
var dd_old_name = dd_name + "_OLD";
49-
var dd_new_name = dd_name + "_NEW";
48+
//var dd_old_name = dd_name + "_OLD";
49+
//var dd_new_name = dd_name + "_NEW";
5050
db = cloudant.db.use(dbname);
5151

5252
async.series( [
@@ -57,26 +57,26 @@ var migrate = function(dbname, dd, callback) {
5757
if(err) {
5858
console.log("!!!");
5959
return callback(null, null);
60-
};
60+
}
6161
var a = clone(data);
6262
var b = clone(dd);
6363
delete a._rev;
6464
delete a._id;
6565
delete b._rev;
6666
delete b._id;
67-
if(JSON.stringify(a) == JSON.stringify(b)) {
67+
if(JSON.stringify(a) === JSON.stringify(b)) {
6868
console.log("** The design document is the same, no need to migrate! **");
6969
callback(true,null);
7070
} else {
7171
callback(null,null);
7272
}
73-
})
73+
});
7474
},
7575

7676
// write new design document to _NEW
7777
function(callback) {
7878
console.log("## write new design document to ");
79-
writedoc(db, dd, dd_name, callback)
79+
writedoc(db, dd, dd_name, callback);
8080
}
8181

8282
], function(err, data) {
@@ -89,4 +89,4 @@ var migrate = function(dbname, dd, callback) {
8989

9090
module.exports = {
9191
migrate: migrate
92-
}
92+
};

lib/credentials.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// VCAP_SERVICES
66
// This is Bluemix configuration
77
if (typeof process.env.VCAP_SERVICES === 'string') {
8-
console.log("Using Bluemix config for Cloudant")
8+
console.log("Using Bluemix config for Cloudant");
99
var services = process.env.VCAP_SERVICES;
10-
if (typeof services != 'undefined') {
10+
if (typeof services !== 'undefined') {
1111
services = JSON.parse(services);
1212
}
1313
}
@@ -16,7 +16,7 @@ if (typeof process.env.VCAP_SERVICES === 'string') {
1616
// Local deploy cloudant configuration
1717
// URL format: https://<username>:<password>@<hostname>
1818
else if (typeof process.env.SSS_CLOUDANT_URL === 'string') {
19-
console.log("Using local config for Cloudant")
19+
console.log("Using local config for Cloudant");
2020
var services = {
2121
"cloudantNoSQLDB": [{
2222
"name": "simple-search-service-cloudant-service",
@@ -26,15 +26,15 @@ else if (typeof process.env.SSS_CLOUDANT_URL === 'string') {
2626
"url": process.env.SSS_CLOUDANT_URL
2727
}
2828
}]
29-
}
29+
};
3030
}
3131

3232
/*******
3333
REDIS
3434
*******/
3535

3636
if (typeof process.env.SSS_REDIS_HOST === 'string') {
37-
console.log("Using local config for Redis")
37+
console.log("Using local config for Redis");
3838
services["user-provided"] = [
3939
{
4040
name: "Redis by Compose",
@@ -44,7 +44,7 @@ if (typeof process.env.SSS_REDIS_HOST === 'string') {
4444
}
4545

4646
}
47-
]
47+
];
4848

4949
}
5050

0 commit comments

Comments
 (0)