1
- import RestWrite from './RestWrite' ;
2
- import { md5Hash } from './cryptoUtils' ;
1
+ import { md5Hash , newObjectId } from './cryptoUtils' ;
3
2
4
3
export default function pushStatusHandler ( config ) {
5
4
6
5
let initialPromise ;
7
6
let pushStatus ;
7
+
8
+ let collection = function ( ) {
9
+ return config . database . adaptiveCollection ( '_PushStatus' ) ;
10
+ }
11
+
8
12
let setInitial = function ( body , where , options = { source : 'rest' } ) {
13
+ let now = new Date ( ) ;
9
14
let object = {
10
- pushTime : ( new Date ( ) ) . toISOString ( ) ,
15
+ objectId : newObjectId ( ) ,
16
+ pushTime : now . toISOString ( ) ,
17
+ _created_at : now ,
11
18
query : JSON . stringify ( where ) ,
12
19
payload : body . data ,
13
20
source : options . source ,
@@ -16,21 +23,27 @@ export default function pushStatusHandler(config) {
16
23
status : "pending" ,
17
24
numSent : 0 ,
18
25
pushHash : md5Hash ( JSON . stringify ( body . data ) ) ,
19
- ACL : new Parse . ACL ( ) // lockdown!
26
+ // lockdown!
27
+ _wperm : [ ] ,
28
+ _rperm : [ ]
20
29
}
21
- let restWrite = new RestWrite ( config , { isMaster : true } , '_PushStatus' , null , object ) ;
22
- initialPromise = restWrite . execute ( ) . then ( ( res ) => {
23
- pushStatus = res . response ;
30
+ initialPromise = collection ( ) . then ( ( collection ) => {
31
+ return collection . insertOne ( object ) ;
32
+ } ) . then ( ( res ) => {
33
+ pushStatus = {
34
+ objectId : object . objectId
35
+ } ;
24
36
return Promise . resolve ( pushStatus ) ;
25
- } ) ;
37
+ } )
26
38
return initialPromise ;
27
39
}
28
40
29
41
let setRunning = function ( ) {
30
42
return initialPromise . then ( ( ) => {
31
- let restWrite = new RestWrite ( config , { isMaster : true } , '_PushStatus' , { status :"pending" , objectId : pushStatus . objectId } , { status : "running" } ) ;
32
- return restWrite . execute ( ) ;
33
- } )
43
+ return collection ( ) ;
44
+ } ) . then ( ( collection ) => {
45
+ return collection . updateOne ( { status :"pending" , objectId : pushStatus . objectId } , { $set : { status : "running" } } ) ;
46
+ } ) ;
34
47
}
35
48
36
49
let complete = function ( results ) {
@@ -63,9 +76,10 @@ export default function pushStatusHandler(config) {
63
76
}
64
77
65
78
return initialPromise . then ( ( ) => {
66
- let restWrite = new RestWrite ( config , { isMaster : true } , '_PushStatus' , { status :"running" , objectId : pushStatus . objectId } , update ) ;
67
- return restWrite . execute ( ) ;
68
- } )
79
+ return collection ( ) ;
80
+ } ) . then ( ( collection ) => {
81
+ return collection . updateOne ( { status :"running" , objectId : pushStatus . objectId } , { $set : update } ) ;
82
+ } ) ;
69
83
}
70
84
71
85
return Object . freeze ( {
0 commit comments