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
This commit is contained in:
parent
59614201b5
commit
9714926e11
@ -58,6 +58,30 @@ class Contributor extends Record {
|
|||||||
return this.functions.addContributor(...contributor, callOptions);
|
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;
|
module.exports = Contributor;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user