Skip to content

Commit a10c1fd

Browse files
committed
[assistant] Lint fixes
1 parent a6cc8eb commit a10c1fd

File tree

11 files changed

+335
-312
lines changed

11 files changed

+335
-312
lines changed

plugins/assistant/api/api.js

+49-55
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
const plugin = {},
2-
common = require('../../../api/utils/common.js'),
3-
plugins = require('../../pluginManager.js'),
4-
log = common.log('assistant:api'),
5-
fetch = require('../../../api/parts/data/fetch.js'),
6-
async = require("async"),
7-
assistant = require("./assistant.js"),
8-
_ = require('underscore');
9-
10-
(function(plugin) {
11-
plugins.register("/master", function(ob) {
1+
const exportedPlugin = {};
2+
const common = require('../../../api/utils/common.js');
3+
const plugins = require('../../pluginManager.js');
4+
const log = common.log('assistant:api');
5+
const assistant = require("./assistant.js");
6+
const _ = require('underscore');
7+
8+
(function() {
9+
plugins.register("/master", function() {
1210
// Allow configs to load & scanner to find all jobs classes
1311
setTimeout(() => {
1412
require('../../../api/parts/jobs').job('assistant:generate').replace().schedule("every " + assistant.JOB_SCHEDULE_INTERVAL + " minutes starting on the 0 min");
@@ -17,7 +15,6 @@ const plugin = {},
1715

1816
plugins.register("/o/assistant", function(ob) {
1917
const params = ob.params;
20-
const paths = ob.paths;
2118

2219
if (!params.qstring.api_key) {
2320
common.returnMessage(params, 400, 'Missing parameter "api_key"');
@@ -29,28 +26,25 @@ const plugin = {},
2926

3027
log.d('Assistant plugin request: Get All Notifications');
3128
const validate = ob.validateUserForMgmtReadAPI;
32-
validate(function(params) {
33-
const member = params.member;
29+
validate(function(paramsInValidate) {
30+
const member = paramsInValidate.member;
3431

3532
if (_.isUndefined(app_id) || app_id === null) {
3633
//app id not provided, not app targeted
3734

3835
//for a single user return all of his notifications for all of his apps
3936
assistant.getNotificationsForUser(common.db, member, api_key, function(err, results) {
40-
common.returnOutput(params, results);
37+
common.returnOutput(paramsInValidate, results);
4138
});
4239
}
4340
else {
4441
//app id provided, a single app targeted
4542

4643
//for a single user return all of his notifications for a specific app
4744
assistant.getNotificationsForUserForSingleApp(common.db, api_key, app_id, function(err, singleAppNotifications) {
48-
common.returnOutput(params, [singleAppNotifications]);
45+
common.returnOutput(paramsInValidate, [singleAppNotifications]);
4946
});
5047
}
51-
52-
53-
5448
}, params);
5549
return true;
5650
});
@@ -66,30 +60,31 @@ const plugin = {},
6660

6761
log.d('Assistant plugin request: /i/assistant');
6862
const validate = ob.validateUserForMgmtReadAPI;
69-
validate(function(params) {
63+
validate(function(paramsInValidate) {
64+
const api_key = paramsInValidate.qstring.api_key;
7065

71-
const member = params.member;
72-
const api_key = params.qstring.api_key;
66+
let save_action;
67+
let notif;
68+
let save_val;
7369

7470
const subAction = paths[3];
7571
log.d('Assistant plugin request: ' + subAction);
7672
switch (subAction) {
7773
case 'global':
7874
case 'private':
79-
if (typeof params.qstring.save === "undefined") {
80-
common.returnMessage(params, 400, 'Missing parameter "save"');
75+
if (typeof paramsInValidate.qstring.save === "undefined") {
76+
common.returnMessage(paramsInValidate, 400, 'Missing parameter "save"');
8177
return false;
8278
}
8379

84-
if (typeof params.qstring.notif === "undefined") {
85-
common.returnMessage(params, 400, 'Missing parameter "notif"');
80+
if (typeof paramsInValidate.qstring.notif === "undefined") {
81+
common.returnMessage(paramsInValidate, 400, 'Missing parameter "notif"');
8682
return false;
8783
}
8884

89-
const notif = params.qstring.notif;
90-
const save_val = params.qstring.save;
85+
notif = paramsInValidate.qstring.notif;
86+
save_val = paramsInValidate.qstring.save;
9187

92-
let save_action;
9388
if (save_val === "true") {
9489
save_action = true;
9590
}//save
@@ -102,14 +97,14 @@ const plugin = {},
10297
//this toggles the global save status
10398
log.d('Assistant plugin request: Change global notification status');
10499
assistant.changeNotificationSavedStatus(false, save_action, notif, api_key, common.db);
105-
common.returnOutput(params, "the global action was done " + save_action);
100+
common.returnOutput(paramsInValidate, "the global action was done " + save_action);
106101
}
107102
else if (subAction === 'private') {
108103
//this is called when changing the save status of a notification from the frontend
109104
//this toggles the private save status
110105
log.d('Assistant plugin request: Change personal notification status');
111106
assistant.changeNotificationSavedStatus(true, save_action, notif, api_key, common.db);
112-
common.returnOutput(params, "the private action was done " + save_action);
107+
common.returnOutput(paramsInValidate, "the private action was done " + save_action);
113108
}
114109
break;
115110
case 'create_external':
@@ -118,72 +113,71 @@ const plugin = {},
118113

119114
try {
120115
//read provided fields
121-
const notifData = JSON.parse(params.qstring.notif_data);
122-
const pluginName = params.qstring.owner_name;
123-
const notifType = params.qstring.notif_type;
124-
const notifSubType = params.qstring.notif_subtype;
125-
const i18nId = params.qstring.i18n_id;
126-
const notifAppId = params.qstring.notif_app_id;
127-
const notificationVersion = params.qstring.notif_version;
128-
const targetUserApiKey = params.qstring.target_user_api_key;
116+
const notifData = JSON.parse(paramsInValidate.qstring.notif_data);
117+
const pluginName = paramsInValidate.qstring.owner_name;
118+
const notifType = paramsInValidate.qstring.notif_type;
119+
const notifSubType = paramsInValidate.qstring.notif_subtype;
120+
const i18nId = paramsInValidate.qstring.i18n_id;
121+
const notifAppId = paramsInValidate.qstring.notif_app_id;
122+
const notificationVersion = paramsInValidate.qstring.notif_version;
123+
const targetUserApiKey = paramsInValidate.qstring.target_user_api_key;
129124

130125
//check if they are set
131126
if (_.isUndefined(notifData)) {
132-
common.returnMessage(params, 400, 'Missing parameter "notif_data"');
127+
common.returnMessage(paramsInValidate, 400, 'Missing parameter "notif_data"');
133128
return false;
134129
}
135130

136131
if (_.isUndefined(pluginName)) {
137-
common.returnMessage(params, 400, 'Missing parameter "owner_name"');
132+
common.returnMessage(paramsInValidate, 400, 'Missing parameter "owner_name"');
138133
return false;
139134
}
140135

141136
if (_.isUndefined(notifType)) {
142-
common.returnMessage(params, 400, 'Missing parameter "notif_type"');
137+
common.returnMessage(paramsInValidate, 400, 'Missing parameter "notif_type"');
143138
return false;
144139
}
145140

146141
if (_.isUndefined(notifSubType)) {
147-
common.returnMessage(params, 400, 'Missing parameter "notif_subtype"');
142+
common.returnMessage(paramsInValidate, 400, 'Missing parameter "notif_subtype"');
148143
return false;
149144
}
150145

151146
if (_.isUndefined(i18nId)) {
152-
common.returnMessage(params, 400, 'Missing parameter "i18n_id"');
147+
common.returnMessage(paramsInValidate, 400, 'Missing parameter "i18n_id"');
153148
return false;
154149
}
155150

156151
if (_.isUndefined(notifAppId)) {
157-
common.returnMessage(params, 400, 'Missing parameter "notif_app_id"');
152+
common.returnMessage(paramsInValidate, 400, 'Missing parameter "notif_app_id"');
158153
return false;
159154
}
160155

161156
if (_.isUndefined(notificationVersion)) {
162-
common.returnMessage(params, 400, 'Missing parameter "notif_version"');
157+
common.returnMessage(paramsInValidate, 400, 'Missing parameter "notif_version"');
163158
return false;
164159
}
165160

166161
assistant.createNotificationExternal(common.db, notifData, pluginName, notifType, notifSubType, i18nId, notifAppId, notificationVersion, targetUserApiKey, function(succeeded, err) {
167162
if (succeeded) {
168-
common.returnOutput(params, prepareMessage("Succeded in creating notification", null, null));
163+
common.returnOutput(paramsInValidate, prepareMessage("Succeded in creating notification", null, null));
169164
}
170165
else {
171166
if (_.isUndefined(err) || err === null) {
172167
err = "N/A";
173168
}
174-
common.returnMessage(params, 500, prepareMessage('Failed to create notification', err, null));
169+
common.returnMessage(paramsInValidate, 500, prepareMessage('Failed to create notification', err, null));
175170
}
176171
});
177172
}
178173
catch (ex) {
179-
common.returnMessage(params, 500, prepareMessage('Problem while trying to create notification', ex, null));
174+
common.returnMessage(paramsInValidate, 500, prepareMessage('Problem while trying to create notification', ex, null));
180175
return false;
181176
}
182177
break;
183178
default:
184-
common.returnMessage(params, 400, 'Invalid path');
179+
common.returnMessage(paramsInValidate, 400, 'Invalid path');
185180
return false;
186-
break;
187181
}
188182

189183
log.d('Assistant plugin request: 3');
@@ -195,11 +189,11 @@ const plugin = {},
195189
const prepareMessage = function(message, error, data) {
196190
let ret = {};
197191
ret.message = message;
198-
if (!_.isUndefined(error) && error != null) {
192+
if (!_.isUndefined(error) && error !== null) {
199193
ret.error = error;
200194
}
201195

202-
if (!_.isUndefined(data) && data != null) {
196+
if (!_.isUndefined(data) && data !== null) {
203197
ret.data = data;
204198
}
205199

@@ -304,6 +298,6 @@ const plugin = {},
304298
common.db.collection(db_name_config).remove({_id: common.db.ObjectID(appId)}, function() {});
305299
});
306300

307-
}(plugin));
301+
}(exportedPlugin));
308302

309-
module.exports = plugin;
303+
module.exports = exportedPlugin;

0 commit comments

Comments
 (0)