-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathoperations.js
80 lines (76 loc) · 1.85 KB
/
operations.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"use strict";
var api = require('./api');
/**
* This method adds requested defaultOperations to the provided ops and returns the full api functions including default operations
* Basically it provides mixin functionality with default methods
*/
module.exports.attach = function attach(ops, defaultOperations) {
defaultOperations.forEach(function (property) {
ops[property] = genericOperations[property];
});
return ops;
};
/**
* Pre-defined general operations
*/
var genericOperations = {
/**
* For now, there are no differences between a get and list request.
* The difference is that in get, you need to provide id (or alias etc.)
*
* @param data
* @param config
* @param cb
*/
get: function (data, config, cb) {
api.get(this.baseURL, data, config, cb);
},
/**
* Returns an array
*
* @param data
* @param config
* @param cb
*/
list: function (data, config, cb) {
api.get(this.baseURL, data, config, cb);
},
/**
*
* @param data
* @param config
* @param cb
*/
create: function (data, config, cb) {
api.post(this.baseURL, data, config, cb);
},
/**
*
* @param data
* @param config
* @param cb
*/
delete: function (data, config, cb) {
api.delete(this.baseURL, data, config, cb);
},
/**
* id is a String parameter, not an object
*
* @param id
* @param config
* @param cb
*/
deleteById: function (id, config, cb) {
api.delete(this.baseURL, {id: id}, config, cb);
},
/**
* For now, it is the same with create, but needs id parameter in data
*
* @param data
* @param config
* @param cb
*/
update: function (data, config, cb) {
api.post(this.baseURL, data, config, cb);
}
};