From 644ab4e8a1a6ab9b1e450c8a1e770a324b93cd8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Antunes=20Silva?= Date: Fri, 4 Dec 2020 01:06:16 -0300 Subject: [PATCH] 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. --- src/Builder.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Builder.js b/src/Builder.js index af930564..8da09e88 100644 --- a/src/Builder.js +++ b/src/Builder.js @@ -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(',') }) @@ -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.') }