This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
suite-script-nsify-restlet.js
112 lines (99 loc) · 3.04 KB
/
suite-script-nsify-restlet.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var script = function r(n,t,o){function e(f){if(!t[f]){if(!n[f])throw"Cannot find module '"+f+"'";var u=t[f]={exports:{}};n[f][0].call(u.exports,function(r){var t=n[f][1][r];return e(t?t:r)},u,u.exports,r,n,t,o)}return t[f].exports}for(var f=0;f<o.length;f++)e(o[f]);return e}({1:[function(require,module,exports){
/**
* Save Record.
*
* @param data {{type: string, init: [object]}}
*/
exports.save = function(data) {
var recType = data.type,
record = nlapiCreateRecord(recType, data.init);
nlapiSubmitRecrod(reccord);
};
/**
* Update Record.
*
* @param data {{type: string, id: string, fields: [string], values: [string]}}
*/
exports.update = function(data) {
var recType = data.type,
recId = data.id;
nlapiSubmitField(recType, recId, data.fields, data.values);
};
/**
* Remove Record.
*
* @param data {{type: string, id: string}}
*/
exports.remove = function(data) {
var recType = data.type,
recId = data.id;
nlapiDeleteRecord(recType, recId);
};
/**
* Get info Record.
*
* @param data {{type: string, id: string}}
*/
exports.info = function(data) {
var recType = data.type,
recId = data.id;
var record = nlapiLoadRecord(recType, recId);
return JSON.stringify(record);
};
},{}],2:[function(require,module,exports){
/**
* @ns.id: 'restlet-with-require'
* @ns.desc: 'Restlet with require()'
* @ns.type: 'restlet'
*
* @ns.functions.get: 'info'
* @ns.functions.post: 'save'
* @ns.functions.put: 'update'
* @ns.functions.delete: 'remove'
*/
var store = require('./libs/store');
var $trace = 'restlet-with-require';
module.exports = {
info: function (data) {
if (data.type) {
nlapiLogExecution('ERROR', $trace + '.info', 'Missing Record Type: "data.type"')
} else
if (data.id) {
nlapiLogExecution('ERROR', $trace + '.info', 'Missing Internal ID: "data.id"')
} else {
return store.info(data);
}
},
save: function (data) {
if (data.type) {
nlapiLogExecution('ERROR', $trace + '.save', 'Missing Record Type: "data.type"')
} else
if (data.init) {
nlapiLogExecution('ERROR', $trace + '.save', 'Missing Initial Data: "data.init"')
} else {
return store.save(data);
}
},
update: function (data) {
if (data.type) {
nlapiLogExecution('ERROR', $trace + '.update', 'Missing Record Type: "data.type"')
} else
if (data.id) {
nlapiLogExecution('ERROR', $trace + '.update', 'Missing Internal ID: "data.id"')
} else {
return store.update(data);
}
},
remove: function (data) {
if (data.type) {
nlapiLogExecution('ERROR', $trace + '.remove', 'Missing Record Type: "data.type"')
} else
if (data.id) {
nlapiLogExecution('ERROR', $trace + '.remove', 'Missing Internal ID: "data.id"')
} else {
return store.remove(data);
}
}
};
},{"./libs/store":1}]},{},[2]);
var RestletWithRequire = script(2);