@@ -12,8 +12,17 @@ export class PushController {
12
12
throw new Parse . Error ( Parse . Error . PUSH_MISCONFIGURED ,
13
13
'Missing push configuration' ) ;
14
14
}
15
+
15
16
// Replace the expiration_time and push_time with a valid Unix epoch milliseconds time
16
17
body . expiration_time = PushController . getExpirationTime ( body ) ;
18
+ body . expiration_interval = PushController . getExpirationInterval ( body ) ;
19
+
20
+ if ( body . expiration_time && body . expiration_interval ) {
21
+ throw new Parse . Error (
22
+ Parse . Error . PUSH_MISCONFIGURED ,
23
+ 'Both expiration_time and expiration_interval cannot be set' ) ;
24
+ }
25
+
17
26
const pushTime = PushController . getPushTime ( body ) ;
18
27
if ( pushTime && pushTime . date !== 'undefined' ) {
19
28
body [ 'push_time' ] = PushController . formatPushTime ( pushTime ) ;
@@ -108,6 +117,19 @@ export class PushController {
108
117
return expirationTime . valueOf ( ) ;
109
118
}
110
119
120
+ static getExpirationInterval ( body = { } ) {
121
+ const hasExpirationInterval = body . hasOwnProperty ( 'expiration_interval' ) ;
122
+ if ( ! hasExpirationInterval ) {
123
+ return ;
124
+ }
125
+
126
+ var expirationIntervalParam = body [ 'expiration_interval' ] ;
127
+ if ( typeof expirationIntervalParam !== 'number' || expirationIntervalParam <= 0 ) {
128
+ throw new Parse . Error ( Parse . Error . PUSH_MISCONFIGURED ,
129
+ `expiration_interval must be a number greater than 0` ) ;
130
+ }
131
+ }
132
+
111
133
/**
112
134
* Get push time from the request body.
113
135
* @param {Object } request A request object
0 commit comments