From 500f7d4462f45a71b7738172f2de0338f1bf9d12 Mon Sep 17 00:00:00 2001 From: samuel Date: Fri, 8 Jun 2018 23:58:56 +0530 Subject: [PATCH 1/6] resource type bug fix - added api/v1 from config --- lib/serializer.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/serializer.js b/lib/serializer.js index 0d355c1..772932d 100644 --- a/lib/serializer.js +++ b/lib/serializer.js @@ -33,6 +33,10 @@ function defaultSerialize (options, cb) { } resultData.data = result + + // Overriding data.links as the links were wrong + resultData.data.links = makeLinks(options.topLevelLinks); + if (options.meta) resultData.meta = options.meta /** @@ -60,6 +64,11 @@ function defaultAfterSerialize (options, cb) { } module.exports = function serializer (type, data, relations, options, cb) { + + // #SAM + // as we always have model type based on api versioning lets say api/v1 concatenating this + type = options.type + type ; + options = _.clone(options) options.attributes = options.attributes || {} From 1e576d324cec38b9f3cae260423230fe2b8f1d03 Mon Sep 17 00:00:00 2001 From: samuel Date: Tue, 17 Jul 2018 14:43:35 +0530 Subject: [PATCH 2/6] Refactor to include apiRoot (api/v1) in the resources --- lib/serializer.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/serializer.js b/lib/serializer.js index 772932d..12db563 100644 --- a/lib/serializer.js +++ b/lib/serializer.js @@ -3,7 +3,8 @@ var _ = require('lodash') var RelUtils = require('./utilities/relationship-utils') var utils = require('./utils') - + +var apiRoot = 'api/v1/'; function defaultBeforeSerialize (options, cb) { cb(null, options) } @@ -67,7 +68,7 @@ module.exports = function serializer (type, data, relations, options, cb) { // #SAM // as we always have model type based on api versioning lets say api/v1 concatenating this - type = options.type + type ; + type = apiRoot + type ; options = _.clone(options) options.attributes = options.attributes || {} @@ -247,7 +248,8 @@ function parseRelations (data, relations, options) { } else { toType = utils.pluralForModel(relation.modelTo) } - + + toType = apiRoot + toType // Relationship `links` should always be defined unless this is a // relationship request if (!options.isRelationshipRequest) { @@ -420,7 +422,7 @@ function handleIncludes (resp, includes, relations, options) { resource.relationships[include].data = included.map(relData => { return { id: String(relData[propertyKey]), - type: plural + type: apiRoot + plural } }) } else { @@ -436,7 +438,7 @@ function handleIncludes (resp, includes, relations, options) { resource.relationships[include].data = { id: String(resource.attributes[include][propertyKey]), - type: plural + type: apiRoot + plural } embeds.push(compoundIncludes) } From 213b87326bce7f0e9ff6b1c89c02351fefb0944a Mon Sep 17 00:00:00 2001 From: samuel Date: Wed, 18 Jul 2018 11:34:42 +0530 Subject: [PATCH 3/6] Fix links to have apiRoot api/v1 --- lib/serializer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/serializer.js b/lib/serializer.js index 12db563..c0d7f19 100644 --- a/lib/serializer.js +++ b/lib/serializer.js @@ -256,8 +256,8 @@ function parseRelations (data, relations, options) { relationships[name] = { links: { related: options.host + - options.restApiRoot + - '/' + + '/' + + apiRoot + options.modelPath + '/' + pk + From c215d29abbc293a70fdf34ef1ec763dd6f1feb67 Mon Sep 17 00:00:00 2001 From: samuel Date: Mon, 20 Aug 2018 12:52:17 +0530 Subject: [PATCH 4/6] Fix for type attr in the included --- lib/serializer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/serializer.js b/lib/serializer.js index c0d7f19..6e8e4e3 100644 --- a/lib/serializer.js +++ b/lib/serializer.js @@ -257,7 +257,6 @@ function parseRelations (data, relations, options) { links: { related: options.host + '/' + - apiRoot + options.modelPath + '/' + pk + @@ -493,6 +492,7 @@ function createCompoundIncludes ( includedRelations, options ) { + type = apiRoot + type; var compoundInclude = makeRelation(type, String(relationship[key])) if (options && !_.isEmpty(includedRelations)) { From 76dc378c72a20b68112510796de0f1abc9117364 Mon Sep 17 00:00:00 2001 From: samuel Date: Tue, 21 Aug 2018 19:31:12 +0530 Subject: [PATCH 5/6] Fixing links in the related includes --- lib/serializer.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/serializer.js b/lib/serializer.js index 6e8e4e3..816b075 100644 --- a/lib/serializer.js +++ b/lib/serializer.js @@ -74,6 +74,7 @@ module.exports = function serializer (type, data, relations, options, cb) { options.attributes = options.attributes || {} options.isRelationshipRequest = false + options.modelPath = apiRoot + options.modelPath; if (options.topLevelLinks.self.match(/\/relationships\//)) { options.topLevelLinks.related = options.topLevelLinks.self.replace( @@ -253,6 +254,18 @@ function parseRelations (data, relations, options) { // Relationship `links` should always be defined unless this is a // relationship request if (!options.isRelationshipRequest) { + + console.dir( + 'options.host ' +options.host + + '/' + + 'options.modelPath ' + options.modelPath + + '/' + + 'pk ' + pk + + '/ name ' + + name + ); + + relationships[name] = { links: { related: options.host + From ac9198abeb03dd34f8b9f319ee04440691c25bf2 Mon Sep 17 00:00:00 2001 From: samuel Date: Tue, 21 Aug 2018 19:32:58 +0530 Subject: [PATCH 6/6] removing log --- lib/serializer.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/lib/serializer.js b/lib/serializer.js index 816b075..f7d99ec 100644 --- a/lib/serializer.js +++ b/lib/serializer.js @@ -255,17 +255,6 @@ function parseRelations (data, relations, options) { // relationship request if (!options.isRelationshipRequest) { - console.dir( - 'options.host ' +options.host + - '/' + - 'options.modelPath ' + options.modelPath + - '/' + - 'pk ' + pk + - '/ name ' + - name - ); - - relationships[name] = { links: { related: options.host +