MCPcopy Create free account
hub / github.com/CloudBoost/cloudboost / save

Method save

sdk/src/CloudObject.js:82–119  ·  view source on GitHub ↗

* Saved CloudObject in Database. * @param callback * @returns {*}

(callback)

Source from the content-addressed store, hash-verified

80 */
81
82 save(callback) { //save the document to the db
83 var def;
84 CB._validate();
85
86 if (!callback) {
87 def = new CB.Promise();
88 }
89 var thisObj = this;
90 CB._fileCheck(this).then(function(thisObj) {
91
92 var params = JSON.stringify({document: CB.toJSON(thisObj), key: CB.appKey});
93 var url = CB.apiUrl + "/data/" + CB.appId + '/' + thisObj.document._tableName;
94 CB._request('PUT', url, params).then(function(response) {
95 thisObj = CB.fromJSON(JSON.parse(response), thisObj);
96 if (callback) {
97 callback.success(thisObj);
98 } else {
99 def.resolve(thisObj);
100 }
101 }, function(err) {
102 if (callback) {
103 callback.error(err);
104 } else {
105 def.reject(err);
106 }
107 });
108
109 }, function(err) {
110 if (callback) {
111 callback.error(err);
112 } else {
113 def.reject(err);
114 }
115 });
116 if (!callback) {
117 return def.promise;
118 }
119 };
120
121 pin(callback) { //pins the document to the local store
122 CB.CloudObject.pin(this, callback);

Callers 1

CloudObject.jsFile · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected