Skip to content

feat: allow empty array in createAll method #2410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 @@
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
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
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');

Check failure on line 516 in lib/dao.js

View workflow job for this annotation

GitHub Actions / Code Lint

Expected indentation of 4 spaces but found 2
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() {

Check failure on line 522 in lib/dao.js

View workflow job for this annotation

GitHub Actions / Code Lint

Expected indentation of 6 spaces but found 5
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
Loading