forked from Dearkano/TrueResume
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contract.js
38 lines (36 loc) · 1.09 KB
/
contract.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"use strict";
var ResumeContract = function () {
LocalContractStorage.defineMapProperty(this, "resumedb", {
stringify: function (o) {
return o.toString();
}
});
};
ResumeContract.prototype = {
init: function () {
},
save: function (data) {
var from = Blockchain.transaction.from;
var fData = this.resumedb.get(data.nameHash);
if ((fData && fData.owner == from) || fData==null) {
var rData = {"owner":from,"data":data};
this.resumedb.put(data.nameHash, JSON.stringify(rData));
}else{
throw new Error("Cannot update this resume.");
}
},
query: function (nameHash) {
var from = Blockchain.transaction.from;
var data = this.resumedb.get(nameHash);
if(data==null){
throw new Error("No resume before.");
}
if(from==data.owner){
return data.data;
}else{
var tData = {nameHash:"",resume:"",resumeHash:data.data.resumeHash};
return tData;
}
}
};
module.exports = ResumeContract;