Skip to content

Commit 68c02d9

Browse files
authored
Merge pull request #8 from iolufemi/bugFix/createSearchTagsJob
bugFix(Queue):Fix data reference bug in the createsearchtags Job
2 parents 6e38b54 + 103d0f0 commit 68c02d9

File tree

1 file changed

+31
-34
lines changed

1 file changed

+31
-34
lines changed

services/queue/jobs.js

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -55,45 +55,42 @@ jobs.createSearchTags = function(data, done){
5555

5656
var ourDoc = data;
5757
var split = [];
58-
if(ourDoc && ourDoc._id){
59-
delete ourDoc._id;
60-
}
61-
62-
if(ourDoc && ourDoc.createdAt){
63-
delete ourDoc.createdAt;
64-
}
65-
66-
if(ourDoc && ourDoc.updatedAt){
67-
delete ourDoc.updatedAt;
68-
}
69-
70-
if(ourDoc && ourDoc.tags){
71-
delete ourDoc.tags;
72-
}
7358

7459
for(var n in ourDoc){
75-
if(typeof ourDoc[n] === 'string'){
76-
split.push(ourDoc[n].split(' '));
60+
if(ourDoc[n] === ourDoc._id){ /* jslint ignore:line */
61+
// Skip
62+
}else if(ourDoc[n] === ourDoc.createdAt){ /* jslint ignore:line */
63+
// Skip
64+
}else if(ourDoc[n] === ourDoc.updatedAt){ /* jslint ignore:line */
65+
// Skip
66+
}else if(ourDoc[n] === ourDoc.tags){ /* jslint ignore:line */
67+
// Skip
68+
}else{
69+
if(typeof ourDoc[n] === 'string'){
70+
split.push(ourDoc[n].split(' '));
71+
}else{ /* jslint ignore:line */
72+
// Move on nothing to see here
7773
}
7874
}
7975

80-
split = _.flattenDeep(split);
81-
82-
var task;
83-
if(update){
84-
task = models[model].update(data,{ $set: { updatedAt: new Date().toISOString() }, $addToSet: {tags: {$each: split}} });
85-
}else{
86-
task = models[model].update(data,{ $set: { tags: split} });
87-
}
88-
89-
task
90-
.then(function(res){
91-
return done(false, res);
92-
})
93-
.catch(function(err){
94-
log.error(err);
95-
return done(new Error(err.message));
96-
});
76+
}
77+
split = _.flattenDeep(split);
78+
79+
var task;
80+
if(update){
81+
task = models[model].update(data,{ $set: { updatedAt: new Date().toISOString() }, $addToSet: {tags: {$each: split}} });
82+
}else{
83+
task = models[model].update(data,{ $set: { tags: split} });
84+
}
85+
86+
task
87+
.then(function(res){
88+
return done(false, res);
89+
})
90+
.catch(function(err){
91+
log.error(err);
92+
return done(new Error(err.message));
93+
});
9794
};
9895

9996
// Backup Data to Trash

0 commit comments

Comments
 (0)