From b06566d8bdf0d0929edc11b08af5dd444f8ff891 Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Fri, 2 Dec 2016 16:14:30 -0500 Subject: [PATCH] [local-sync] make syncbackRequest objects N1-ready --- packages/local-sync/src/local-api/route-helpers.js | 2 ++ packages/local-sync/src/models/syncbackRequest.js | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/local-sync/src/local-api/route-helpers.js b/packages/local-sync/src/local-api/route-helpers.js index 8ed888dc2..6dc9cc620 100644 --- a/packages/local-sync/src/local-api/route-helpers.js +++ b/packages/local-sync/src/local-api/route-helpers.js @@ -3,6 +3,8 @@ const Serialization = require('./serialization'); module.exports = { createSyncbackRequest: function createSyncbackRequest(request, reply, syncRequestArgs) { request.getAccountDatabase().then((db) => { + const accountId = request.auth.credentials.id; + syncRequestArgs.accountId = accountId db.SyncbackRequest.create(syncRequestArgs).then((syncbackRequest) => { reply(Serialization.jsonStringify(syncbackRequest)) }) diff --git a/packages/local-sync/src/models/syncbackRequest.js b/packages/local-sync/src/models/syncbackRequest.js index bb163ba44..6ffe3e0d0 100644 --- a/packages/local-sync/src/models/syncbackRequest.js +++ b/packages/local-sync/src/models/syncbackRequest.js @@ -10,15 +10,18 @@ module.exports = (sequelize, Sequelize) => { }, error: JSONType('error'), props: JSONType('props'), + accountId: { type: Sequelize.STRING, allowNull: false }, }, { instanceMethods: { toJSON: function toJSON() { return { id: `${this.id}`, type: this.type, - status: this.status, - error: this.error, + error: JSON.stringify(this.error || {}), props: this.props, + status: this.status, + object: 'providerSyncbackRequest', + account_id: this.accountId, } }, },