From 788a37c2f701d45d664f56d6e5de5fb1c527d816 Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Fri, 19 Apr 2019 16:09:18 -0400 Subject: [PATCH] fix import related issue --- app/actions/pledges.js | 14 -------------- app/model/pledge.js | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/actions/pledges.js b/app/actions/pledges.js index 30cd54f..2f9ea76 100644 --- a/app/actions/pledges.js +++ b/app/actions/pledges.js @@ -4,20 +4,6 @@ import database from '../db' import { getPledges, getAllPledges } from '../utils/pledges' import { getProfilesById } from './profiles' -export const createPledgeFromFunding = (pledge, newId, amount, oldPledge, project = 0) => { - const { owner, token, commitTime, nDelegates, pledgeState, delegates, profile } = oldPledge - pledge.idPledge = Number(newId) - pledge.owner = Number(owner) - pledge.amount = amount - pledge.token = token - pledge.commitTime = Number(commitTime) - pledge.nDelegates = Number(nDelegates) - pledge.pledgeState = Number(pledgeState) - pledge.intendedProject = Number(project) - pledge.delegates = delegates - pledge.profile.set(profile) -} - const createPledge = (pledge, data, profiles) => { const { id, owner, amount, blockNumber, token, commitTime, nDelegates, pledgeState, intendedProject, delegates } = data const profile = profiles.find(p => p.idProfile == owner) diff --git a/app/model/pledge.js b/app/model/pledge.js index 1aa2952..a79e1b6 100644 --- a/app/model/pledge.js +++ b/app/model/pledge.js @@ -1,7 +1,20 @@ import { action, field, relation, json } from '@nozbe/watermelondb/decorators' import { Q } from '@nozbe/watermelondb' import { LiquidModel } from '../utils/models' -import { createPledgeFromFunding } from '../actions/pledges' + +const createPledgeFromFunding = (pledge, newId, amount, oldPledge, project = 0) => { + const { owner, token, commitTime, nDelegates, pledgeState, delegates, profile } = oldPledge + pledge.idPledge = Number(newId) + pledge.owner = Number(owner) + pledge.amount = amount + pledge.token = token + pledge.commitTime = Number(commitTime) + pledge.nDelegates = Number(nDelegates) + pledge.pledgeState = Number(pledgeState) + pledge.intendedProject = Number(project) + pledge.delegates = delegates + pledge.profile.set(profile) +} const sanitizeValues = json => json export default class Pledge extends LiquidModel { @@ -26,6 +39,7 @@ export default class Pledge extends LiquidModel { const toPledgeQuery = await this.collections.get('pledges').query( Q.where('pledge_id', to) ).fetch() + const pledgesCollection = await this.collections.get('pledges') const toPledge = toPledgeQuery[0] const args = [ this.prepareUpdate(pledge => { @@ -40,7 +54,7 @@ export default class Pledge extends LiquidModel { ) } else { args.push( - this.prepareCreate(pledge => { + pledgesCollection.prepareCreate(pledge => { createPledgeFromFunding(pledge, to, amount, this, projectId) }) )