Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lib/dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,25 @@ DataAccessObject.createAll = function(dataArray, options, cb) {
options = options || {};
cb = cb || utils.createPromiseCallback();

assert(typeof dataArray === 'object' && dataArray.length,
'The data argument must be an array with length > 0');
assert(typeof dataArray === 'object' && Array.isArray(dataArray),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make it configurable in order to ensure backward compatibility ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added sir

'The data argument must be an array');
assert(typeof options === 'object', 'The options argument must be an object');
assert(typeof cb === 'function', 'The cb argument must be a function');
// If the dataArray is empty, we return an empty array or an error
if (dataArray.length === 0) {
if (options.allowEmptyArray === true) {
process.nextTick(function() {
cb(null, []);
});
} else {
process.nextTick(function() {
const err = new Error('The data argument must be an array with length > 0');
err.statusCode = 400;
cb(err);
});
}
return cb.promise;
}

const validationPromises = [];
for (let index = 0; index < dataArray.length; index++) {
Expand Down