2017-08-29 11:47:01 -04:00
|
|
|
import Parse from 'parse/node';
|
|
|
|
|
import deepcopy from 'deepcopy';
|
2017-01-13 19:34:04 -05:00
|
|
|
|
|
|
|
|
export function isPushIncrementing(body) {
|
|
|
|
|
return body.data &&
|
|
|
|
|
body.data.badge &&
|
|
|
|
|
typeof body.data.badge == 'string' &&
|
|
|
|
|
body.data.badge.toLowerCase() == "increment"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check whether the deviceType parameter in qury condition is valid or not.
|
|
|
|
|
* @param {Object} where A query condition
|
|
|
|
|
* @param {Array} validPushTypes An array of valid push types(string)
|
|
|
|
|
*/
|
|
|
|
|
export function validatePushType(where = {}, validPushTypes = []) {
|
|
|
|
|
var deviceTypeField = where.deviceType || {};
|
|
|
|
|
var deviceTypes = [];
|
|
|
|
|
if (typeof deviceTypeField === 'string') {
|
|
|
|
|
deviceTypes.push(deviceTypeField);
|
|
|
|
|
} else if (Array.isArray(deviceTypeField['$in'])) {
|
|
|
|
|
deviceTypes.concat(deviceTypeField['$in']);
|
|
|
|
|
}
|
|
|
|
|
for (var i = 0; i < deviceTypes.length; i++) {
|
|
|
|
|
var deviceType = deviceTypes[i];
|
|
|
|
|
if (validPushTypes.indexOf(deviceType) < 0) {
|
|
|
|
|
throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED,
|
2017-06-20 09:15:26 -07:00
|
|
|
deviceType + ' is not supported push type.');
|
2017-01-13 19:34:04 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-29 11:47:01 -04:00
|
|
|
|
|
|
|
|
export function applyDeviceTokenExists(where) {
|
|
|
|
|
where = deepcopy(where);
|
|
|
|
|
if (!where.hasOwnProperty('deviceToken')) {
|
|
|
|
|
where['deviceToken'] = {'$exists': true};
|
|
|
|
|
}
|
|
|
|
|
return where;
|
|
|
|
|
}
|