[local-sync] make syncbackRequest objects N1-ready

This commit is contained in:
Evan Morikawa 2016-12-02 16:14:30 -05:00
parent b36f61812d
commit b06566d8bd
2 changed files with 7 additions and 2 deletions

View file

@ -3,6 +3,8 @@ const Serialization = require('./serialization');
module.exports = { module.exports = {
createSyncbackRequest: function createSyncbackRequest(request, reply, syncRequestArgs) { createSyncbackRequest: function createSyncbackRequest(request, reply, syncRequestArgs) {
request.getAccountDatabase().then((db) => { request.getAccountDatabase().then((db) => {
const accountId = request.auth.credentials.id;
syncRequestArgs.accountId = accountId
db.SyncbackRequest.create(syncRequestArgs).then((syncbackRequest) => { db.SyncbackRequest.create(syncRequestArgs).then((syncbackRequest) => {
reply(Serialization.jsonStringify(syncbackRequest)) reply(Serialization.jsonStringify(syncbackRequest))
}) })

View file

@ -10,15 +10,18 @@ module.exports = (sequelize, Sequelize) => {
}, },
error: JSONType('error'), error: JSONType('error'),
props: JSONType('props'), props: JSONType('props'),
accountId: { type: Sequelize.STRING, allowNull: false },
}, { }, {
instanceMethods: { instanceMethods: {
toJSON: function toJSON() { toJSON: function toJSON() {
return { return {
id: `${this.id}`, id: `${this.id}`,
type: this.type, type: this.type,
status: this.status, error: JSON.stringify(this.error || {}),
error: this.error,
props: this.props, props: this.props,
status: this.status,
object: 'providerSyncbackRequest',
account_id: this.accountId,
} }
}, },
}, },