forked from IanVS/nutshell-api-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
50 lines (45 loc) · 1.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
//------------------------------------------------------------------------------
// Requires
//------------------------------------------------------------------------------
const api = require('./lib/api-client');
//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------
exports.find = function (entity, args, cb) {
let options = {
method : 'POST',
path : '/api/v1/json',
username : args.username,
password : args.password
};
api.newNutshell(options, function (err, nutshell) {
if (err) {
console.error(err);
return;
}
let findArgs = { entity };
if (args.qty) {
findArgs.qty = args.qty;
}
if (args.orderBy) {
findArgs.orderBy = args.orderBy;
}
if (args.orderDirection) {
findArgs.orderDirection = args.orderDirection;
}
if (args.filter) {
findArgs.filter = args.filter;
}
if (args.query) {
findArgs.query = args.query;
}
nutshell.find(findArgs, function (err, results) {
if (err) {
console.error(err);
return cb(err);
}
cb(null, results);
});
});
};