(callback)
| 180 | } |
| 181 | |
| 182 | fetch(callback) { //fetch the document from the db |
| 183 | if (!CB.appId) { |
| 184 | throw "CB.appId is null."; |
| 185 | } |
| 186 | if (!this.document._id) { |
| 187 | throw "Can't fetch an object which is not saved." |
| 188 | } |
| 189 | var thisObj = this; |
| 190 | var def; |
| 191 | if (!callback) { |
| 192 | def = new CB.Promise(); |
| 193 | } |
| 194 | var query = null; |
| 195 | if (thisObj.document._type === 'file') { |
| 196 | query = new CB.CloudQuery('_File'); |
| 197 | } else { |
| 198 | query = new CB.CloudQuery(thisObj.document._tableName); |
| 199 | } |
| 200 | query.findById(thisObj.get('id')).then(function(res) { |
| 201 | if (!callback) { |
| 202 | def.resolve(res); |
| 203 | } else { |
| 204 | callback.success(res); |
| 205 | } |
| 206 | }, function(err) { |
| 207 | if (!callback) { |
| 208 | def.reject(err); |
| 209 | } else { |
| 210 | callback.error(err); |
| 211 | } |
| 212 | }); |
| 213 | |
| 214 | if (!callback) { |
| 215 | return def.promise; |
| 216 | } |
| 217 | |
| 218 | }; |
| 219 | |
| 220 | delete(callback) { //delete an object matching the objectId |
| 221 | if (!CB.appId) { |
no test coverage detected