Skip to content

Commit

Permalink
better structure of json to store questions
Browse files Browse the repository at this point in the history
  • Loading branch information
chensivan committed Dec 9, 2015
1 parent 1811d3c commit 0011e89
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lib/voice-assist.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ socket.on('addNotification', function(data) {
fs.stat(file, function(err, stat){
if (err == null){
obj = JSON.parse(fs.readFileSync(file, 'utf8'));
obj[uid].response = data.msg;
console.log(obj);
if(!obj.hasOwnProperty(uid)){
obj[uid] = {
response: [data.msg]
};
}else{
obj[uid].response.push(data.msg);

}

console.log(" hi fewafew");
jsonfile.writeFile(file, obj, function (err) {
console.error(err)
Expand Down Expand Up @@ -165,12 +174,18 @@ recorder.on('start', function() {
console.log(err);
if (err == null){
obj = JSON.parse(fs.readFileSync(file, 'utf8'));
obj[uid] = true;
obj[uid] = {
id: uid,
response: []
}
jsonfile.writeFile(file, obj, function (err) {
console.error(err)
})
}else if(err.code === 'ENOENT') {
obj[uid] = true;
obj[uid] = {
id: uid,
response: []
}
console.log("ok");
jsonfile.writeFile(file, obj, function (err) {
console.error(err)
Expand Down

0 comments on commit 0011e89

Please sign in to comment.