dbs-and-docs-test-bulkAddDriver
module.exports = bulkAddDriverTest;
function findProblemRecords(record) {
return record.ok === false;
}
//b: { ok: true, index: 2, id: "3", db: db }
function bulkAddDriverTest(a, b) {
return function(err, res) {
// what a and b are without having to have a global
var ProblemRecords = res.find(findProblemRecords);
if (err === a &&
ProblemRecords !== undefined) {
console.log('Problem! At least one of your documents didn\'t save.: ');
console.log(JSON.stringify(res));
} else if (err === a && ProblemRecords === undefined) {
b.db.allDocs({
include_docs: true,
attachments: false,
keys: res.id
}, function(err, result_alldocs) {
if (err) {
return console.log(err);
}
// handle result
if (result_alldocs) {
var missingitems = [];
if (result_alldocs.rows[2].doc.hasOwnProperty('firstName') !== true) {
missingitems.push('firstName');
}
if (result_alldocs.rows[2].doc.hasOwnProperty('suspended') !== true) {
missingitems.push('suspended');
}
if (result_alldocs.rows[2].doc.hasOwnProperty('violations') !== true) {
missingitems.push('violations');
}
if (result_alldocs.rows[2].doc.hasOwnProperty('plates') !== true) {
missingitems.push('plates');
}
console.log('Problem! The third document is missing the following information: ' + JSON.stringify(missingitems));
}
});
} else if (err === a &&
ProblemRecords === undefined &&
res[b.index].id === b.id) {
console.log('Success! Done.');
console.log('response: ' + JSON.stringify(res));
} else {
console.log('There was an error: ' + JSON.stringify(err));
}
};
}
no comments