Skip to content

Commit 3e3a6a0

Browse files
committed
Merge pull request #29 from leancloud/feature/v0.4.5
Feature/v0.4.5
2 parents e992a6b + 34b8718 commit 3e3a6a0

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

lib/av.js

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4469,7 +4469,7 @@
44694469
* @param {boolean} enable true to enable fetchWhenSave option.
44704470
*/
44714471
fetchWhenSave: function(enable){
4472-
if (typeof enable !== 'boolean'){
4472+
if (!_.isBoolean(enable)) {
44734473
throw "Expect boolean value for fetchWhenSave";
44744474
}
44754475
this._fetchWhenSave = enable;
@@ -6908,7 +6908,7 @@
69086908
if(!target){
69096909
throw "Invalid target user.";
69106910
}
6911-
var userObjectId = (typeof target === 'string') ? target: target.id;
6911+
var userObjectId = _.isString(target) ? target: target.id;
69126912
if(!userObjectId){
69136913
throw "Invalid target user.";
69146914
}
@@ -6932,7 +6932,7 @@
69326932
if(!target){
69336933
throw "Invalid target user.";
69346934
}
6935-
var userObjectId = (typeof target === 'string') ? target: target.id;
6935+
var userObjectId = _.isString(target) ? target: target.id;
69366936
if(!userObjectId){
69376937
throw "Invalid target user.";
69386938
}
@@ -7188,7 +7188,7 @@
71887188
* @since 0.3.0
71897189
*/
71907190
followerQuery: function(userObjectId) {
7191-
if(!userObjectId || typeof userObjectId !='string'){
7191+
if(!userObjectId || !_.isString(userObjectId)) {
71927192
throw "Invalid user object id.";
71937193
}
71947194
var query = new AV.FriendShipQuery('_Follower');
@@ -7203,7 +7203,7 @@
72037203
* @since 0.3.0
72047204
*/
72057205
followeeQuery: function(userObjectId) {
7206-
if(!userObjectId || typeof userObjectId !='string'){
7206+
if(!userObjectId || !_.isString(userObjectId)) {
72077207
throw "Invalid user object id.";
72087208
}
72097209
var query = new AV.FriendShipQuery('_Followee');
@@ -7531,11 +7531,19 @@
75317531
* completes.
75327532
*
75337533
* @param {String} cql, A CQL string, see <a href='https://cn.avoscloud.com/docs/cql_guide.html'>CQL Guide.</a>
7534+
* @param {Array} pvalues, An array contains placeholder values.
7535+
* @param {Object} options A Backbone-style options object,it's optional.
75347536
* @return {AV.Promise} A promise that is resolved with the results when
7535-
* the query completes.
7537+
* the query completes,it's optional.
75367538
*/
7537-
AV.Query.doCloudQuery = function(cql, options) {
7539+
AV.Query.doCloudQuery = function(cql, pvalues, options) {
75387540
var params = { cql: cql };
7541+
if(_.isArray(pvalues)){
7542+
params.pvalues = pvalues;
7543+
} else {
7544+
options = pvalues;
7545+
}
7546+
75397547
var request = AV._request("cloudQuery", null, null, 'GET', params)
75407548
return request.then(function(response) {
75417549
//query to process results.
@@ -8892,16 +8900,19 @@
88928900

88938901
/**
88948902
* Makes a call to request a sms code for operation verification.
8895-
* @param {Object} data The mobile phone number string or a JSON object contains mobilePhoneNumber,op,ttl,name etc.
8903+
* @param {Object} data The mobile phone number string or a JSON
8904+
* object that contains mobilePhoneNumber,template,op,ttl,name etc.
88968905
* @param {Object} options A Backbone-style options object
88978906
* @return {AV.Promise} A promise that will be resolved with the result
88988907
* of the function.
88998908
*/
89008909
requestSmsCode: function(data, options){
8901-
if(typeof data === 'string')
8910+
if(_.isString(data)) {
89028911
data = { mobilePhoneNumber: data };
8903-
if(!data.mobilePhoneNumber)
8912+
}
8913+
if(!data.mobilePhoneNumber) {
89048914
throw "Missing mobilePhoneNumber.";
8915+
}
89058916
var request = AV._request("requestSmsCode", null, null, 'POST',
89068917
data);
89078918
return request._thenRunCallbacks(options);
@@ -8949,6 +8960,8 @@
89498960
* <li>expiration_interval - The seconds from now to expire the push.</li>
89508961
* <li>where - A AV.Query over AV.Installation that is used to match
89518962
* a set of installations to push to.</li>
8963+
* <li>cql - A CQL statement over AV.Installation that is used to match
8964+
* a set of installations to push to.</li>
89528965
* <li>data - The data to send as part of the push</li>
89538966
* <ol>
89548967
* @param {Object} options An object that has an optional success function,
@@ -8961,6 +8974,10 @@
89618974
data.where = data.where.toJSON().where;
89628975
}
89638976

8977+
if(data.where && data.cql){
8978+
throw "Both where and cql can't be set";
8979+
}
8980+
89648981
if (data.push_time) {
89658982
data.push_time = data.push_time.toJSON();
89668983
}
@@ -8993,7 +9010,7 @@
89939010
this.data = {};
89949011
this.inboxType = 'default';
89959012
this.query = null;
8996-
if(imageUrl && typeof imageUrl == 'object') {
9013+
if(imageUrl && typeof imageUrl === 'object') {
89979014
this.data = imageUrl;
89989015
} else {
89999016
if(imageUrl){
@@ -9177,7 +9194,7 @@
91779194
if(!target){
91789195
throw "Invalid target user.";
91799196
}
9180-
var userObjectId = (typeof target === 'string') ? target: target.id;
9197+
var userObjectId = _.isString(target) ? target: target.id;
91819198
if(!userObjectId){
91829199
throw "Invalid target user.";
91839200
}
@@ -9221,8 +9238,8 @@
92219238
throw 'Please signin an user or pass the owner objectId.';
92229239
}
92239240
owner = owner || AV.User.current();
9224-
var options = (typeof arguments[1] !== 'string') ? arguments[1] : arguments[2];
9225-
var inboxType = (typeof arguments[1] !== 'string') ? 'default' : arguments[1];
9241+
var options = !_.isString(arguments[1]) ? arguments[1] : arguments[2];
9242+
var inboxType = !_.isString(arguments[1]) ? 'default' : arguments[1];
92269243
var params = {};
92279244
params.inboxType = AV._encode(inboxType);
92289245
params.owner = AV._encode(owner);

tests/query.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ describe("Queries",function(){
5959
done();
6060
});
6161
});
62+
it("should return count value too.", function(done){
63+
AV.Query.doCloudQuery('select *,count(objectId) from GameScore limit ?', [5]).then(function(result){
64+
console.dir(result);
65+
var results = result.results;
66+
expect(results.length).to.be(5);
67+
expect(results[0].className).to.be("GameScore");
68+
expect(result.count).to.be.an('number');
69+
expect(result.className).to.be('GameScore');
70+
done();
71+
});
72+
});
6273
it("should return syntax error.", function(done){
6374
AV.Query.doCloudQuery('select * GameScore limit 10').then(function(){
6475
throw "Shoud not be successfully.";

0 commit comments

Comments
 (0)