Skip to content

Commit 644ab4e

Browse files
committed
fix(builder): use typeof instead of constructor for checks
Fix error "You must pass a payload/object as param." when using builder in server side.
1 parent 72de598 commit 644ab4e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Builder.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ export default class Builder {
8383
}
8484

8585
// single entity .select(['age', 'firstname'])
86-
if (fields[0].constructor === String || Array.isArray(fields[0])) {
86+
if (typeof fields[0] === 'string' || Array.isArray(fields[0])) {
8787
this.fields[this.model.resource()] = fields.join(',')
8888
}
8989

9090
// related entities .select({ posts: ['title', 'content'], user: ['age', 'firstname']} )
91-
if (fields[0].constructor === Object) {
91+
if (typeof fields[0] === 'object') {
9292
Object.entries(fields[0]).forEach(([key, value]) => {
9393
this.fields[key] = value.join(',')
9494
})
@@ -161,7 +161,7 @@ export default class Builder {
161161
}
162162

163163
params(payload) {
164-
if (payload === undefined || payload.constructor !== Object) {
164+
if (payload === undefined || typeof payload !== 'object') {
165165
throw new Error('You must pass a payload/object as param.')
166166
}
167167

0 commit comments

Comments
 (0)