Skip to content

Commit aa0e033

Browse files
committed
fixed help menu
1 parent 66bf4d0 commit aa0e033

File tree

3 files changed

+61
-59
lines changed

3 files changed

+61
-59
lines changed

darrt/actions.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@
88
* actions for the company service
99
*/
1010

11-
var component = require('./lib/component');
12-
var data = require('./data');
13-
var object = "api";
11+
var component = require('./lib/component')
12+
var data = require('./data')
13+
var object = "api"
1414

15-
module.exports.home = home;
16-
module.exports.create = create;
17-
module.exports.list = list;
18-
module.exports.filter = filter;
19-
module.exports.read = read;
20-
module.exports.update = update;
21-
module.exports.status = status;
22-
module.exports.remove = remove;
15+
module.exports.home = home
16+
module.exports.create = create
17+
module.exports.list = list
18+
module.exports.filter = filter
19+
module.exports.read = read
20+
module.exports.update = update
21+
module.exports.status = status
22+
module.exports.remove = remove
2323

2424
/**
2525
* @function home
2626
* @memberof actions
2727
* @param {object} req - Express Request object.
2828
*/
29-
function home (req) {
30-
return new Promise(function (resolve, reject) {
29+
const home = (req) => {
30+
return new Promise((resolve, reject) => {
3131
var body = [];
3232

3333
// hack to handle empty root for non-link types
@@ -188,7 +188,7 @@ function status (req) {
188188
* @memberof actions
189189
* @param {object} req - Express Request object.
190190
*/
191-
function remove (req) {
191+
const remove = (req) => {
192192
return new Promise(function (resolve, reject) {
193193
if (req.params.id && req.params.id !== null) {
194194
var id = req.params.id;

darrt/lib/component.js

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
var storage = require('./storage');
2424
var utils = require('./utils');
25+
const IS = (check, type) =>
26+
check === null || (check.type && check.type === (type || 'error'));
2527

2628
module.exports = main;
2729

@@ -34,17 +36,17 @@ function main (args) {
3436
var rtn, props, reqd, enums;
3537
var action, id, filter, item, fields, defs, elm, profile;
3638

37-
elm = args.name || "";
39+
elm = args.name || '';
3840
props = args.props || [];
3941
reqd = args.reqd || [];
40-
action = args.action || "list";
41-
id = args.id || "";
42-
filter = args.filter || "";
42+
action = args.action || 'list';
43+
id = args.id || '';
44+
filter = args.filter || '';
4345
item = args.item || {};
4446
reqd = args.reqd || [];
4547
enums = args.enums || [];
4648
defs = args.defs || [];
47-
fields = args.fields || "";
49+
fields = args.fields || '';
4850

4951
// confirm existence of object storage
5052
storage({ action: 'create', object: elm });
@@ -98,7 +100,7 @@ function main (args) {
98100
if (rtn) {
99101
resolve(rtn);
100102
} else {
101-
reject({ error: "unable to process component request" });
103+
reject({ error: 'unable to process component request' });
102104
}
103105
});
104106
}
@@ -115,42 +117,42 @@ function main (args) {
115117
*/
116118
function addEntry (elm, entry, props, reqd, enums, defs) {
117119
var rtn, item, error, id, i, x;
118-
120+
119121
item = {};
120122

121123
// ensure correct properties
122124
for (i = 0, x = props.length; i < x; i++) {
123-
if (props[i] !== " id") {
124-
item[props[i]] = (entry[props[i]] || "");
125+
if (props[i] !== ' id') {
126+
item[props[i]] = (entry[props[i]] || '');
125127
} else {
126128
id = entry[props[i]];
127129
}
128130
}
129-
131+
130132
// fix up any missing defaults
131133
for (i = 0, x = defs.length; i < x; i++) {
132-
if (item[defs[i].name] === "") {
134+
if (item[defs[i].name] === '') {
133135
item[defs[i].name] = defs[i].value;
134136
}
135137
}
136-
137-
error = "";
138-
138+
139+
error = '';
140+
139141
// check for missing properties
140142
for (i = 0, x = reqd.length; i < x; i++) {
141-
if (item[reqd[i]] === "") {
142-
error += "Missing "+ reqd[i] + " ";
143+
if (item[reqd[i]] === '') {
144+
error += 'Missing ' + reqd[i] + ' ';
143145
}
144146
}
145147

146148
// validate enumerated properties
147149
for (i = 0, x = enums.length; i < x; i++) {
148150
for (var key in enums[i]) {
149-
if (item[key] !== "") {
150-
if (enums[i][key].indexOf(item[key]) === -1) {
151-
error += "Invalid enumerator [" + item[key] + "] for " + key + " ";
152-
}
153-
}
151+
if (item[key] !== '') {
152+
if (enums[i][key].indexOf(item[key]) === -1) {
153+
error += 'Invalid enumerator [' + item[key] + '] for ' + key + ' ';
154+
}
155+
}
154156
}
155157
}
156158

@@ -159,13 +161,13 @@ function addEntry (elm, entry, props, reqd, enums, defs) {
159161
rtn = utils.exception(error);
160162
} else {
161163
rtn = storage({
162-
object: elm,
163-
action: 'add',
164-
item: utils.setProps(item, props),
165-
id: id
166-
});
164+
object: elm,
165+
action: 'add',
166+
item: utils.setProps(item, props),
167+
id: id
168+
});
167169
}
168-
170+
169171
return rtn;
170172
}
171173

@@ -183,39 +185,42 @@ function updateEntry (elm, id, entry, props, reqd, enums) {
183185
var rtn, check, item, error, i, x;
184186

185187
check = storage({
186-
object: elm,
187-
action: 'item',
188-
id: id
189-
});
188+
object: elm,
189+
action: 'item',
190+
id: id
191+
});
192+
const ERROR = 'error'
193+
const HAS_ERROR = IS(check, ERROR)
190194

191-
if (check === null || (check.type && check.type === "error")) {
192-
rtn = utils.exception("File Not Found", "No record on file", 404);
195+
if (HAS_ERROR) {
196+
// rtn = erm(404)
197+
rtn = utils.exception('File Not Found', 'No record on file', 404);
193198
} else {
194199
item = check;
195200
for (i = 0, x = props.length; i < x; i++) {
196-
if (props[i]!=="id") {
201+
if (props[i]!=='id') {
197202
item[props[i]] = (entry[props[i]] === undefined ? check[props[i]] : entry[props[i]]);
198203
}
199204
}
200205

201-
error = "";
206+
error = '';
202207
for (i = 0, x = reqd.length; i < x; i++) {
203-
if (item[reqd[i]] === "") {
204-
error += "Missing "+ reqd[i] + " ";
208+
if (item[reqd[i]] === '') {
209+
error += 'Missing '+ reqd[i] + ' ';
205210
}
206211
}
207212

208213
for (i = 0, x = enums.length; i < x; i++) {
209214
for (var key in enums[i]) {
210-
if (item[key] !== "") {
215+
if (item[key] !== '') {
211216
if (enums[i][key].indexOf(item[key]) === -1) {
212-
error += "Invalid enumerator [" + item[key] + "] for " + key + " ";
217+
error += 'Invalid enumerator [' + item[key] + '] for ' + key + ' ';
213218
}
214219
}
215220
}
216221
}
217222

218-
if (error !== "") {
223+
if (error !== '') {
219224
rtn = utils.exception(error);
220225
} else {
221226
rtn = storage({
@@ -246,7 +251,7 @@ function removeEntry (elm, id) {
246251
});
247252

248253
if (check === null) {
249-
rtn = utils.exception("File Not Found", "No record on file", 404);
254+
rtn = utils.exception('File Not Found', 'No record on file', 404);
250255
} else {
251256
storage({
252257
object: elm,

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
"start": "node index",
1313
"dev": "nodemon index",
1414
"publish": "surge .",
15-
"help": "npm run help/nohup",
16-
"help/open": "npm run $(npm run | percol)",
17-
"install/help/nohup": "nohup $(npm run)",
18-
"help/nohup": "npm run $(cat nohup.out | percol)"
15+
"help": "npm run $(echo \"$(npm run)\" | percol)"
1916
},
2017
"repository": {
2118
"type": "git",

0 commit comments

Comments
 (0)