(callback)
| 978 | } |
| 979 | }; |
| 980 | findOne(callback) { //find a single document matching the given query |
| 981 | if (!CB.appId) { |
| 982 | throw "CB.appId is null."; |
| 983 | } |
| 984 | if (!this.tableName) { |
| 985 | throw "TableName is null."; |
| 986 | } |
| 987 | var def; |
| 988 | if (!callback) { |
| 989 | def = new CB.Promise(); |
| 990 | } |
| 991 | var params = JSON.stringify({query: this.query, select: this.select, sort: this.sort, skip: this.skip, key: CB.appKey}); |
| 992 | var url = CB.apiUrl + "/data/" + CB.appId + "/" + this.tableName + '/findOne'; |
| 993 | |
| 994 | CB._request('POST', url, params).then(function(response) { |
| 995 | var object = CB.fromJSON(JSON.parse(response)); |
| 996 | if (callback) { |
| 997 | callback.success(object); |
| 998 | } else { |
| 999 | def.resolve(object); |
| 1000 | } |
| 1001 | }, function(err) { |
| 1002 | if (callback) { |
| 1003 | callback.error(err); |
| 1004 | } else { |
| 1005 | def.reject(err); |
| 1006 | } |
| 1007 | }); |
| 1008 | |
| 1009 | if (!callback) { |
| 1010 | return def.promise; |
| 1011 | } |
| 1012 | }; |
| 1013 | } |
| 1014 | |
| 1015 | // Logical operations |
no outgoing calls
no test coverage detected