Skip to content

Commit

Permalink
fix: create relation with additional template param
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-scherzinger committed Feb 2, 2018
1 parent 560fb9d commit f888b2e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Core.ts
Expand Up @@ -368,7 +368,11 @@ export default class Core {
.then(link => validator.validate(resource, `${link.profile}${this[relationsSymbol][relation].createTemplateModifier}`))
.then(() => this.follow(this[relationsSymbol][relation].relation))
.then(request => {
request.withTemplateParameters({});
if (this[relationsSymbol][relation].additionalTemplateParam) {
request.withTemplateParameters(optionsToQuery({
[this[relationsSymbol][relation].additionalTemplateParam]: this[this[relationsSymbol][relation].additionalTemplateParam],
}));
}
return post(this[environmentSymbol], request, resource)
})
.then(([c, traversal]) =>
Expand Down
2 changes: 1 addition & 1 deletion src/helper.ts
Expand Up @@ -444,7 +444,7 @@ const modifier = {
* @param {string?} templateURL optional templateURL for validating inputs
* @returns {object} translated querystring object
*/
export function optionsToQuery(options: filterOptions, templateURL: string): any {
export function optionsToQuery(options: filterOptions, templateURL?: string): any {
const out: any = {};

if (options) {
Expand Down
6 changes: 5 additions & 1 deletion src/resources/Resource.ts
Expand Up @@ -139,7 +139,11 @@ class Resource {
.then(link => validator.validate(resource, `${link.profile}${this[relationsSymbol][relation].createTemplateModifier}`))
.then(() => this.newRequest().follow(this[relationsSymbol][relation].relation))
.then(request => {
request.withTemplateParameters({});
if (this[relationsSymbol][relation].additionalTemplateParam) {
request.withTemplateParameters(optionsToQuery({
[this[relationsSymbol][relation].additionalTemplateParam]: this[this[relationsSymbol][relation].additionalTemplateParam],
}));
}
return post(this[environmentSymbol], request, resource)
})
.then(([c, traversal]) =>
Expand Down

0 comments on commit f888b2e

Please sign in to comment.