Add Reimbursement app

This commit is contained in:
2020-05-29 10:46:55 +02:00
parent 2b99593699
commit a0b0183beb
35 changed files with 9288 additions and 34 deletions

View File

@@ -0,0 +1,45 @@
const Record = require('./record');
const ExpenseSerializer = require('../serializers/expense');
class Reimbursement extends Record {
get count () {
return this.functions.reimbursementsCount();
}
getById (id) {
return this.functions.getReimbursement(id)
.then(data => {
return this.ipfs.catAndMerge(data, ExpenseSerializer.deserialize);
});
}
getData (id) {
return this.functions.getReimbursement(id);
}
async add (attrs, callOptions = {}) {
const reimbursement = new ExpenseSerializer(attrs);
try { await reimbursement.validate(); }
catch (error) { return Promise.reject(error); }
const jsonStr = reimbursement.serialize();
return this.ipfs
.add(jsonStr)
.then(ipfsHashAttr => {
let reimbursement = [
attrs.amount,
attrs.token,
ipfsHashAttr.hashDigest,
ipfsHashAttr.hashFunction,
ipfsHashAttr.hashSize,
];
console.log(reimbursement)
return this.functions.add(...reimbursement, callOptions);
});
}
}
module.exports = Reimbursement;