better logic for author handling

This commit is contained in:
John McLear 2015-01-21 00:28:00 +00:00
parent 5f9bbd0666
commit cb65224997
1 changed files with 14 additions and 1 deletions

View File

@ -24,12 +24,25 @@ exports.setPadRaw = function(padId, records, callback){
async.eachSeries(Object.keys(records), function(key, cb){
var value = records[key]
// we know its an author
// Author data
if(value.padIDs){
// rewrite author pad ids
value.padIDs[padId] = 1;
var newKey = key;
// Does this author already exist?
db.get(key, function(err, author){
if(author){
// Yes, add the padID to the author..
author.padIDs.push(padId);
value = author;
}else{
// No, create a new array with the author info in
value.padIDs = [padId];
}
});
// Not author data, probably pad data
}else{
// we can split it to look to see if its pad data
var oldPadId = key.split(":");