_PushStatus uses proper Parse format (#1580)

* removes mongo style props from _PushStatus

* removes log

* Update MongoTransform.js

Removes _id case
This commit is contained in:
Florent Vilmart
2016-04-21 21:36:15 -04:00
parent 6e9529f81c
commit d49d539a81
4 changed files with 10 additions and 13 deletions

View File

@@ -1340,7 +1340,6 @@ describe('miscellaneous', function() {
expect(res.key).toBe(1); expect(res.key).toBe(1);
return runIncrement(-1); return runIncrement(-1);
}).then((res) => { }).then((res) => {
console.log(res);
expect(res.key).toBe(0); expect(res.key).toBe(0);
done(); done();
}) })

View File

@@ -293,6 +293,7 @@ describe('PushController', () => {
expect(results.length).toBe(1); expect(results.length).toBe(1);
let result = results[0]; let result = results[0];
expect(result.createdAt instanceof Date).toBe(true); expect(result.createdAt instanceof Date).toBe(true);
expect(result.updatedAt instanceof Date).toBe(true);
expect(result.id.length).toBe(10); expect(result.id.length).toBe(10);
expect(result.get('source')).toEqual('rest'); expect(result.get('source')).toEqual('rest');
expect(result.get('query')).toEqual(JSON.stringify({})); expect(result.get('query')).toEqual(JSON.stringify({}));

View File

@@ -214,8 +214,6 @@ const parseObjectKeyValueToMongoObjectKeyValue = (
let coercedToDate; let coercedToDate;
switch(restKey) { switch(restKey) {
case 'objectId': return {key: '_id', value: restValue}; case 'objectId': return {key: '_id', value: restValue};
case '_created_at'://TODO: for some reason, _PushStatus is already transformed when it gets here. For now,
// just pass the _created_at through. Later, we should make sure the push status doesn't get transformed inside Parse Server.
case 'createdAt': case 'createdAt':
transformedValue = transformAtom(restValue, false); transformedValue = transformAtom(restValue, false);
coercedToDate = typeof transformedValue === 'string' ? new Date(transformedValue) : transformedValue coercedToDate = typeof transformedValue === 'string' ? new Date(transformedValue) : transformedValue
@@ -228,8 +226,6 @@ const parseObjectKeyValueToMongoObjectKeyValue = (
transformedValue = transformAtom(restValue, false); transformedValue = transformAtom(restValue, false);
coercedToDate = typeof transformedValue === 'string' ? new Date(transformedValue) : transformedValue coercedToDate = typeof transformedValue === 'string' ? new Date(transformedValue) : transformedValue
return {key: 'expiresAt', value: coercedToDate}; return {key: 'expiresAt', value: coercedToDate};
case '_id': //TODO: for some reason, _PushStatus is already transformed when it gets here. For now,
// just pass the ID through. Later, we should make sure the push status doesn't get transformed inside Parse Server.
case '_rperm': case '_rperm':
case '_wperm': case '_wperm':
case '_email_verify_token': case '_email_verify_token':

View File

@@ -26,9 +26,9 @@ export default function pushStatusHandler(config) {
let data = body.data || {}; let data = body.data || {};
let payloadString = JSON.stringify(data); let payloadString = JSON.stringify(data);
let object = { let object = {
_id: objectId, objectId,
createdAt: now,
pushTime: now.toISOString(), pushTime: now.toISOString(),
_created_at: now,
query: JSON.stringify(where), query: JSON.stringify(where),
payload: payloadString, payload: payloadString,
source: options.source, source: options.source,
@@ -38,8 +38,7 @@ export default function pushStatusHandler(config) {
numSent: 0, numSent: 0,
pushHash: md5Hash(payloadString), pushHash: md5Hash(payloadString),
// lockdown! // lockdown!
_wperm: [], ACL: {}
_rperm: []
} }
return database.create(PUSH_STATUS_COLLECTION, object).then(() => { return database.create(PUSH_STATUS_COLLECTION, object).then(() => {
@@ -54,12 +53,13 @@ export default function pushStatusHandler(config) {
logger.verbose('sending push to %d installations', installations.length); logger.verbose('sending push to %d installations', installations.length);
return database.update(PUSH_STATUS_COLLECTION, return database.update(PUSH_STATUS_COLLECTION,
{status:"pending", objectId: objectId}, {status:"pending", objectId: objectId},
{status: "running"}); {status: "running", updatedAt: new Date() });
} }
let complete = function(results) { let complete = function(results) {
let update = { let update = {
status: 'succeeded', status: 'succeeded',
updatedAt: new Date(),
numSent: 0, numSent: 0,
numFailed: 0, numFailed: 0,
}; };
@@ -87,16 +87,17 @@ export default function pushStatusHandler(config) {
}, update); }, update);
} }
logger.verbose('sent push! %d success, %d failures', update.numSent, update.numFailed); logger.verbose('sent push! %d success, %d failures', update.numSent, update.numFailed);
return database.update('_PushStatus', {status:"running", objectId }, update); return database.update(PUSH_STATUS_COLLECTION, {status:"running", objectId }, update);
} }
let fail = function(err) { let fail = function(err) {
let update = { let update = {
errorMessage: JSON.stringify(err), errorMessage: JSON.stringify(err),
status: 'failed' status: 'failed',
updatedAt: new Date()
} }
logger.error('error while sending push', err); logger.error('error while sending push', err);
return database.update('_PushStatus', { objectId }, update); return database.update(PUSH_STATUS_COLLECTION, { objectId }, update);
} }
return Object.freeze({ return Object.freeze({