Skip to content

Commit

Permalink
fix(builder): use typeof instead of constructor for checks
Browse files Browse the repository at this point in the history
Fix error "You must pass a payload/object as param." when using builder in server side.
  • Loading branch information
JoaoPedroAS51 committed Dec 4, 2020
1 parent 72de598 commit 644ab4e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ export default class Builder {
}

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

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

params(payload) {
if (payload === undefined || payload.constructor !== Object) {
if (payload === undefined || typeof payload !== 'object') {
throw new Error('You must pass a payload/object as param.')
}

Expand Down

0 comments on commit 644ab4e

Please sign in to comment.