forked from acumenbrands/rest_suite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupsert.js.html
222 lines (188 loc) · 6.37 KB
/
upsert.js.html
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: upsert.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: upsert.js</h1>
<section>
<article>
<pre class="prettyprint source"><code>/**
* Upserter Class
* @class Upserter
* @param {object} request The body of the HTTP Post request from the client
* @return {Upserter} A new instance of Upserter
*/
this.Upserter = (function() {
/** @constructor */
function Upserter(request) {
this.params = request;
this.record_data = request['record_data'];
this.reply_list = [];
this.exception = null;
}
/**
* Iterates over `record_data` calling `executeUpsertRequest` on each item
*
* @method
* @memberof Upserter
* @return {null}
*/
Upserter.prototype.upsertRecords = function() {
for(index in this.record_data) {
request_data = this.record_data[index];
this.executeUpsertRequest(request_data);
}
}
/**
* Initializes and executes an `UpsertRequest` calling `accumulateResult()`
*
* @method
* @memberof Upserter
* @param {object} An individual item's records
* @return {null}
*/
Upserter.prototype.executeUpsertRequest = function(request_data) {
upsert_request = new UpsertRequest(request_data);
upsert_request.execute();
this.accumulateResult(upsert_request.generateReply());
}
/**
* Pushes the result onto the `reply_list` array
*
* @method
* @memberof Upserter
* @return {null}
*/
Upserter.prototype.accumulateResult = function(result) {
this.reply_list.push(result);
}
/**
* Generate a body for the reply to the client's request.
*
* @method
* @memberof Upserter
* @return {object} The object containing a formatted summary of the results of the request
*/
Upserter.prototype.generateReply = function() {
return NetsuiteToolkit.formatReply(this.params, this.replyList);
}
return Upserter;
})();
/**
* UpsertRequest Class
* @class UpsertRequest
* @param {object} record_data The data from a client request
* @return {Loader} A new instance of UpsertRequest
*/
this.UpsertRequest = (function() {
/** @constructor */
function UpsertRequest(record_data) {
this.params = record_data;
this.record = null;
this.written_id = null;
this.internalid = record_data['internalid'] || null;
this.record_type = record_data['record_type'];
this.literal_field_data = record_data['literal_fields'];
this.sublist_data = record_data['sublists'];
}
/**
* Performs the UpsertRequest
*
* @method
* @memberof UpsertRequest
* @return {null}
*/
UpsertRequest.prototype.execute = function() {
this.record = this.loadOrInitializeRecord();
NetsuiteToolkit.RecordProcessor.updateLiterals(this.record, this.literal_field_data);
this.processSublists();
this.written_id = NetsuiteToolkit.submitRecord(this.record);
}
/**
* Finds or creates a new record based on the presence of `internalid`
*
* @method
* @memberof UpsertRequest
* @return {null}
*/
UpsertRequest.prototype.loadOrInitializeRecord = function() {
if(this.internalid) {
this.record = NetsuiteToolkit.loadRecord(this.record_type, this.internalid);
} else {
this.record = NetsuiteToolkit.initializeRecord(this.record_type);
}
}
/**
* Iterates through given sublists calling `executeSublistProcessor()`
*
* @method
* @memberof UpsertRequest
* @return {null}
*/
UpsertRequest.prototype.processSublists = function() {
for(index in this.sublist_data) {
sublist = this.sublist_data[index];
this.executeSublistProcessor(sublist);
}
}
/**
* Initializes and calls `execute()` on the `NetsuiteToolkit.SublistProcessor()`
*
* @method
* @memberof UpsertRequest
* @return {null}
*/
UpsertRequest.prototype.executeSublistProcessor = function(sublist_data) {
sublist_processor = new NetsuiteToolkit.SublistProcessor(this.record, sublist_data);
sublist_processor.execute();
}
/**
* Calls `NetsuiteToolkit.formatReply()` passing it `params` and `written_id`
*
* @method
* @memberof UpsertRequest
* @return {object} Formatted reply
*/
UpsertRequest.prototype.generateReply = function() {
return NetsuiteToolkit.formatReply(this.params, this.written_id);
}
return UpsertRequest;
})();
/** @namespace global */
/**
* The script function that Netsuite will call to execute the Upserter process
*
* @method
* @param {object} request The object representing the body of the HTTP request
* @memberof global
* @return {object} The formatted results of the request
*/
var upsertPostHandler = function(request) {
upserter = new Upserter(request);
upserter.upsertRecords();
return upserter.generateReply();
}
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Index</a></h2><h3>Classes</h3><ul><li><a href="Deleter.html">Deleter</a></li><li><a href="DeleteRequest.html">DeleteRequest</a></li><li><a href="Initializer.html">Initializer</a></li><li><a href="Loader.html">Loader</a></li><li><a href="LoadRequest.html">LoadRequest</a></li><li><a href="NetsuiteToolkit.SublistProcessor.html">SublistProcessor</a></li><li><a href="SavedSearch.html">SavedSearch</a></li><li><a href="Searcher.html">Searcher</a></li><li><a href="Transformer.html">Transformer</a></li><li><a href="TransformRequest.html">TransformRequest</a></li><li><a href="Upserter.html">Upserter</a></li><li><a href="UpsertRequest.html">UpsertRequest</a></li></ul><h3>Namespaces</h3><ul><li><a href="global.html">global</a></li><li><a href="NetsuiteToolkit.html">NetsuiteToolkit</a></li><li><a href="NetsuiteToolkit.RecordProcessor.html">RecordProcessor</a></li></ul>
</nav>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.1.1</a> on Thu May 16 2013 11:16:09 GMT-0500 (CDT)
</footer>
<script> prettyPrint(); </script>
</body>
</html>