Support incrementing push badge value by more than 1 (#4889)

* Support 'IncrementByN' badge value for higher push badge increments

* Fix test

* Rely on object for badge incrementation (i.e. {increment: 3}) rather than string (IncrementBy3)

* For badge incrementation, utilize format similar to other operation notation
This commit is contained in:
Ross Bayer
2018-07-12 11:34:08 -07:00
committed by Florent Vilmart
parent 800959f458
commit ced6b76ef5
3 changed files with 93 additions and 5 deletions

View File

@@ -44,10 +44,13 @@ export class PushController {
let restUpdate = {};
if (typeof badge == 'string' && badge.toLowerCase() === 'increment') {
restUpdate = { badge: { __op: 'Increment', amount: 1 } }
} else if (typeof badge == 'object' && typeof badge.__op == 'string' &&
badge.__op.toLowerCase() == 'increment' && Number(badge.amount)) {
restUpdate = { badge: { __op: 'Increment', amount: badge.amount } }
} else if (Number(badge)) {
restUpdate = { badge: badge }
} else {
throw "Invalid value for badge, expected number or 'Increment'";
throw "Invalid value for badge, expected number or 'Increment' or {increment: number}";
}
// Force filtering on only valid device tokens