Push status nits (#1462)
* Sets _id to objectId in _PushStatus (fixes #1457) * _PushStatus stores serialized payload (fixes #1458)
This commit is contained in:
@@ -295,9 +295,11 @@ describe('PushController', () => {
|
||||
expect(results.length).toBe(1);
|
||||
let result = results[0];
|
||||
expect(result.createdAt instanceof Date).toBe(true);
|
||||
expect(result.id.length).toBe(10);
|
||||
expect(result.get('source')).toEqual('rest');
|
||||
expect(result.get('query')).toEqual(JSON.stringify({}));
|
||||
expect(result.get('payload')).toEqual(payload.data);
|
||||
expect(typeof result.get('payload')).toEqual("string");
|
||||
expect(JSON.parse(result.get('payload'))).toEqual(payload.data);
|
||||
expect(result.get('status')).toEqual('succeeded');
|
||||
expect(result.get('numSent')).toEqual(10);
|
||||
expect(result.get('sentPerType')).toEqual({
|
||||
|
||||
@@ -24,18 +24,19 @@ export default function pushStatusHandler(config) {
|
||||
let setInitial = function(body = {}, where, options = {source: 'rest'}) {
|
||||
let now = new Date();
|
||||
let data = body.data || {};
|
||||
let payloadString = JSON.stringify(data);
|
||||
let object = {
|
||||
objectId,
|
||||
_id: objectId,
|
||||
pushTime: now.toISOString(),
|
||||
_created_at: now,
|
||||
query: JSON.stringify(where),
|
||||
payload: body.data,
|
||||
payload: payloadString,
|
||||
source: options.source,
|
||||
title: options.title,
|
||||
expiry: body.expiration_time,
|
||||
status: "pending",
|
||||
numSent: 0,
|
||||
pushHash: md5Hash(JSON.stringify(data)),
|
||||
pushHash: md5Hash(payloadString),
|
||||
// lockdown!
|
||||
_wperm: [],
|
||||
_rperm: []
|
||||
@@ -44,7 +45,7 @@ export default function pushStatusHandler(config) {
|
||||
return collection.insertOne(object);
|
||||
}).then((res) => {
|
||||
pushStatus = {
|
||||
objectId: object.objectId
|
||||
objectId
|
||||
};
|
||||
return Promise.resolve(pushStatus);
|
||||
})
|
||||
@@ -56,7 +57,7 @@ export default function pushStatusHandler(config) {
|
||||
return initialPromise.then(() => {
|
||||
return collection();
|
||||
}).then((collection) => {
|
||||
return collection.updateOne({status:"pending", objectId: pushStatus.objectId}, {$set: {status: "running"}});
|
||||
return collection.updateOne({status:"pending", _id: objectId}, {$set: {status: "running"}});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -93,7 +94,7 @@ export default function pushStatusHandler(config) {
|
||||
return initialPromise.then(() => {
|
||||
return collection();
|
||||
}).then((collection) => {
|
||||
return collection.updateOne({status:"running", objectId: pushStatus.objectId}, {$set: update});
|
||||
return collection.updateOne({status:"running", _id: objectId}, {$set: update});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -106,7 +107,7 @@ export default function pushStatusHandler(config) {
|
||||
return initialPromise.then(() => {
|
||||
return collection();
|
||||
}).then((collection) => {
|
||||
return collection.updateOne({objectId: pushStatus.objectId}, {$set: update});
|
||||
return collection.updateOne({_id: objectId}, {$set: update});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user