2019-11-12 00:22:20 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-11-13 02:14:24 +00:00
|
|
|
function whereOr(query, table, builder) {
|
2019-11-30 04:55:32 +00:00
|
|
|
if (!query) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-11-12 00:22:20 +00:00
|
|
|
Object.entries(query).forEach(([key, value]) => {
|
2019-12-01 04:32:47 +00:00
|
|
|
if (value === undefined) {
|
|
|
|
return builder;
|
2019-11-12 00:22:20 +00:00
|
|
|
}
|
2019-12-01 04:32:47 +00:00
|
|
|
|
|
|
|
if (Array.isArray(value)) {
|
|
|
|
builder.orWhereIn(`${table}.${key}`, value);
|
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.orWhere(`${table}.${key}`, value);
|
|
|
|
return builder;
|
2019-11-12 00:22:20 +00:00
|
|
|
});
|
2019-11-30 04:55:32 +00:00
|
|
|
|
|
|
|
return builder;
|
2019-11-12 00:22:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = whereOr;
|