|
4469 | 4469 | * @param {boolean} enable true to enable fetchWhenSave option. |
4470 | 4470 | */ |
4471 | 4471 | fetchWhenSave: function(enable){ |
4472 | | - if (typeof enable !== 'boolean'){ |
| 4472 | + if (!_.isBoolean(enable)) { |
4473 | 4473 | throw "Expect boolean value for fetchWhenSave"; |
4474 | 4474 | } |
4475 | 4475 | this._fetchWhenSave = enable; |
|
6908 | 6908 | if(!target){ |
6909 | 6909 | throw "Invalid target user."; |
6910 | 6910 | } |
6911 | | - var userObjectId = (typeof target === 'string') ? target: target.id; |
| 6911 | + var userObjectId = _.isString(target) ? target: target.id; |
6912 | 6912 | if(!userObjectId){ |
6913 | 6913 | throw "Invalid target user."; |
6914 | 6914 | } |
|
6932 | 6932 | if(!target){ |
6933 | 6933 | throw "Invalid target user."; |
6934 | 6934 | } |
6935 | | - var userObjectId = (typeof target === 'string') ? target: target.id; |
| 6935 | + var userObjectId = _.isString(target) ? target: target.id; |
6936 | 6936 | if(!userObjectId){ |
6937 | 6937 | throw "Invalid target user."; |
6938 | 6938 | } |
|
7188 | 7188 | * @since 0.3.0 |
7189 | 7189 | */ |
7190 | 7190 | followerQuery: function(userObjectId) { |
7191 | | - if(!userObjectId || typeof userObjectId !='string'){ |
| 7191 | + if(!userObjectId || !_.isString(userObjectId)) { |
7192 | 7192 | throw "Invalid user object id."; |
7193 | 7193 | } |
7194 | 7194 | var query = new AV.FriendShipQuery('_Follower'); |
|
7203 | 7203 | * @since 0.3.0 |
7204 | 7204 | */ |
7205 | 7205 | followeeQuery: function(userObjectId) { |
7206 | | - if(!userObjectId || typeof userObjectId !='string'){ |
| 7206 | + if(!userObjectId || !_.isString(userObjectId)) { |
7207 | 7207 | throw "Invalid user object id."; |
7208 | 7208 | } |
7209 | 7209 | var query = new AV.FriendShipQuery('_Followee'); |
|
7531 | 7531 | * completes. |
7532 | 7532 | * |
7533 | 7533 | * @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. |
7534 | 7536 | * @return {AV.Promise} A promise that is resolved with the results when |
7535 | | - * the query completes. |
| 7537 | + * the query completes,it's optional. |
7536 | 7538 | */ |
7537 | | - AV.Query.doCloudQuery = function(cql, options) { |
| 7539 | + AV.Query.doCloudQuery = function(cql, pvalues, options) { |
7538 | 7540 | var params = { cql: cql }; |
| 7541 | + if(_.isArray(pvalues)){ |
| 7542 | + params.pvalues = pvalues; |
| 7543 | + } else { |
| 7544 | + options = pvalues; |
| 7545 | + } |
| 7546 | + |
7539 | 7547 | var request = AV._request("cloudQuery", null, null, 'GET', params) |
7540 | 7548 | return request.then(function(response) { |
7541 | 7549 | //query to process results. |
|
8892 | 8900 |
|
8893 | 8901 | /** |
8894 | 8902 | * 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. |
8896 | 8905 | * @param {Object} options A Backbone-style options object |
8897 | 8906 | * @return {AV.Promise} A promise that will be resolved with the result |
8898 | 8907 | * of the function. |
8899 | 8908 | */ |
8900 | 8909 | requestSmsCode: function(data, options){ |
8901 | | - if(typeof data === 'string') |
| 8910 | + if(_.isString(data)) { |
8902 | 8911 | data = { mobilePhoneNumber: data }; |
8903 | | - if(!data.mobilePhoneNumber) |
| 8912 | + } |
| 8913 | + if(!data.mobilePhoneNumber) { |
8904 | 8914 | throw "Missing mobilePhoneNumber."; |
| 8915 | + } |
8905 | 8916 | var request = AV._request("requestSmsCode", null, null, 'POST', |
8906 | 8917 | data); |
8907 | 8918 | return request._thenRunCallbacks(options); |
|
8949 | 8960 | * <li>expiration_interval - The seconds from now to expire the push.</li> |
8950 | 8961 | * <li>where - A AV.Query over AV.Installation that is used to match |
8951 | 8962 | * 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> |
8952 | 8965 | * <li>data - The data to send as part of the push</li> |
8953 | 8966 | * <ol> |
8954 | 8967 | * @param {Object} options An object that has an optional success function, |
|
8961 | 8974 | data.where = data.where.toJSON().where; |
8962 | 8975 | } |
8963 | 8976 |
|
| 8977 | + if(data.where && data.cql){ |
| 8978 | + throw "Both where and cql can't be set"; |
| 8979 | + } |
| 8980 | + |
8964 | 8981 | if (data.push_time) { |
8965 | 8982 | data.push_time = data.push_time.toJSON(); |
8966 | 8983 | } |
|
8993 | 9010 | this.data = {}; |
8994 | 9011 | this.inboxType = 'default'; |
8995 | 9012 | this.query = null; |
8996 | | - if(imageUrl && typeof imageUrl == 'object') { |
| 9013 | + if(imageUrl && typeof imageUrl === 'object') { |
8997 | 9014 | this.data = imageUrl; |
8998 | 9015 | } else { |
8999 | 9016 | if(imageUrl){ |
|
9177 | 9194 | if(!target){ |
9178 | 9195 | throw "Invalid target user."; |
9179 | 9196 | } |
9180 | | - var userObjectId = (typeof target === 'string') ? target: target.id; |
| 9197 | + var userObjectId = _.isString(target) ? target: target.id; |
9181 | 9198 | if(!userObjectId){ |
9182 | 9199 | throw "Invalid target user."; |
9183 | 9200 | } |
|
9221 | 9238 | throw 'Please signin an user or pass the owner objectId.'; |
9222 | 9239 | } |
9223 | 9240 | 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]; |
9226 | 9243 | var params = {}; |
9227 | 9244 | params.inboxType = AV._encode(inboxType); |
9228 | 9245 | params.owner = AV._encode(owner); |
|
0 commit comments