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

Method findById

sdk/src/CloudQuery.js:918–979  ·  view source on GitHub ↗
(objectId, callback)

Source from the content-addressed store, hash-verified

916 };
917
918 findById(objectId, callback) { //find the document(s) matching the given query
919
920 var thisObj = this;
921
922 if (!CB.appId) {
923 throw "CB.appId is null.";
924 }
925 if (!this.tableName) {
926 throw "TableName is null.";
927 }
928 var def;
929 if (!callback) {
930 def = new CB.Promise();
931 }
932
933 if (thisObj.skip && !thisObj.skip !== 0) {
934 throw "You cannot use skip and find object by Id in the same query";
935 }
936
937 if (thisObj.limit && thisObj.limit === 0) {
938 throw "You cannot use limit and find object by Id in the same query";
939 }
940
941 if (thisObj.sort && Object.getOwnPropertyNames(thisObj.sort).length > 0) {
942 throw "You cannot use sort and find object by Id in the same query";
943 }
944
945 thisObj.equalTo('id', objectId);
946
947 var params = JSON.stringify({
948 query: thisObj.query,
949 select: thisObj.select,
950 key: CB.appKey,
951 limit: 1,
952 skip: 0,
953 sort: {}
954 });
955
956 var url = CB.apiUrl + "/data/" + CB.appId + "/" + thisObj.tableName + '/find';
957
958 CB._request('POST', url, params).then(function(response) {
959 response = JSON.parse(response);
960 if (Object.prototype.toString.call(response) === '[object Array]') {
961 response = response[0];
962 }
963 if (callback) {
964 callback.success(CB.fromJSON(response));
965 } else {
966 def.resolve(CB.fromJSON(response));
967 }
968 }, function(err) {
969 if (callback) {
970 callback.error(err);
971 } else {
972 def.reject(err);
973 }
974 });
975

Callers 14

getMethod · 0.95
cloudboost.jsFile · 0.80
test.jsFile · 0.80
CloudFile.jsFile · 0.80
versionTest.jsFile · 0.80
encryption.jsFile · 0.80
expire.jsFile · 0.80
atomicity.jsFile · 0.80
userTest.jsFile · 0.80
encryption.jsFile · 0.80
includeList.jsFile · 0.80
aclTest1.jsFile · 0.80

Calls 1

equalToMethod · 0.80

Tested by

no test coverage detected