From 9714926e1129fe8ad84e7dbb4e03414fdf2147a1 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Sat, 20 Apr 2019 02:17:38 +0200 Subject: [PATCH] Add function to update contributor profile to wrapper The function updates the contributor profile, adds the new profile to IPFS and does the contract call to update the profile hash --- lib/contracts/contributor.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/contracts/contributor.js b/lib/contracts/contributor.js index 3d8ce87..82b0c4f 100644 --- a/lib/contracts/contributor.js +++ b/lib/contracts/contributor.js @@ -58,6 +58,30 @@ class Contributor extends Record { return this.functions.addContributor(...contributor, callOptions); }); } + + updateProfile(contributorId, updateAttr, callOptions = {}) { + return this.getById(contributorId).then(async (contributor) => { + let updatedContributorAttr = Object.assign(contributor, updateAttr) + let updatedContributor = new ContributorSerializer(updatedContributorAttr); + + try { await updatedContributor.validate(); } + catch (error) { return Promise.reject(error); } + + const jsonStr = updatedContributor.serialize(); + + return this.ipfs + .add(jsonStr) + .then(ipfsHashAttr => { + return this.functions.updateContributorProfileHash( + contributorId, + ipfsHashAttr.hashDigest, + ipfsHashAttr.hashFunction, + ipfsHashAttr.hashSize, + callOptions + ); + }); + }); + } } module.exports = Contributor;