Skip to content

Commit af30f66

Browse files
committed
Push status nits (#1462)
* Sets _id to objectId in _PushStatus (fixes #1457) * _PushStatus stores serialized payload (fixes #1458)
1 parent c050a65 commit af30f66

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

spec/PushController.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,11 @@ describe('PushController', () => {
295295
expect(results.length).toBe(1);
296296
let result = results[0];
297297
expect(result.createdAt instanceof Date).toBe(true);
298+
expect(result.id.length).toBe(10);
298299
expect(result.get('source')).toEqual('rest');
299300
expect(result.get('query')).toEqual(JSON.stringify({}));
300-
expect(result.get('payload')).toEqual(payload.data);
301+
expect(typeof result.get('payload')).toEqual("string");
302+
expect(JSON.parse(result.get('payload'))).toEqual(payload.data);
301303
expect(result.get('status')).toEqual('succeeded');
302304
expect(result.get('numSent')).toEqual(10);
303305
expect(result.get('sentPerType')).toEqual({

src/pushStatusHandler.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ export default function pushStatusHandler(config) {
2424
let setInitial = function(body = {}, where, options = {source: 'rest'}) {
2525
let now = new Date();
2626
let data = body.data || {};
27+
let payloadString = JSON.stringify(data);
2728
let object = {
28-
objectId,
29+
_id: objectId,
2930
pushTime: now.toISOString(),
3031
_created_at: now,
3132
query: JSON.stringify(where),
32-
payload: body.data,
33+
payload: payloadString,
3334
source: options.source,
3435
title: options.title,
3536
expiry: body.expiration_time,
3637
status: "pending",
3738
numSent: 0,
38-
pushHash: md5Hash(JSON.stringify(data)),
39+
pushHash: md5Hash(payloadString),
3940
// lockdown!
4041
_wperm: [],
4142
_rperm: []
@@ -44,7 +45,7 @@ export default function pushStatusHandler(config) {
4445
return collection.insertOne(object);
4546
}).then((res) => {
4647
pushStatus = {
47-
objectId: object.objectId
48+
objectId
4849
};
4950
return Promise.resolve(pushStatus);
5051
})
@@ -56,7 +57,7 @@ export default function pushStatusHandler(config) {
5657
return initialPromise.then(() => {
5758
return collection();
5859
}).then((collection) => {
59-
return collection.updateOne({status:"pending", objectId: pushStatus.objectId}, {$set: {status: "running"}});
60+
return collection.updateOne({status:"pending", _id: objectId}, {$set: {status: "running"}});
6061
});
6162
}
6263

@@ -93,7 +94,7 @@ export default function pushStatusHandler(config) {
9394
return initialPromise.then(() => {
9495
return collection();
9596
}).then((collection) => {
96-
return collection.updateOne({status:"running", objectId: pushStatus.objectId}, {$set: update});
97+
return collection.updateOne({status:"running", _id: objectId}, {$set: update});
9798
});
9899
}
99100

@@ -106,7 +107,7 @@ export default function pushStatusHandler(config) {
106107
return initialPromise.then(() => {
107108
return collection();
108109
}).then((collection) => {
109-
return collection.updateOne({objectId: pushStatus.objectId}, {$set: update});
110+
return collection.updateOne({_id: objectId}, {$set: update});
110111
});
111112
}
112113

0 commit comments

Comments
 (0)