XingFramework/Relayer

View on GitHub
dist/relayer/transformers/CreateResourceTransformer.js

Summary

Maintainability
C
7 hrs
Test Coverage
import PrimaryResourceTransformer from "./PrimaryResourceTransformer.js"

export default class CreateResourceTransformer extends PrimaryResourceTransformer {

  constructor(relationshipDescription, uriTemplate) {
    super(relationshipDescription);
    this.uriTemplate = uriTemplate;
  }

  transformResponse(endpoint, response) {
    return response.then(
      (resolvedResponse) => {
        var resourceMapper = this.primaryResourceMapperFactory(endpoint.transport, resolvedResponse.data, this.relationshipDescription);
        resourceMapper.uriTemplate = this.uriTemplate;
        var resource = resourceMapper.map();
        resource.templatedUrl.etag = resolvedResponse.etag;
        return resource;
      }
    ).catch(
      (resolvedError) => {
        throw this.primaryResourceMapperFactory(endpoint.transport, resolvedError.data, this.relationshipDescription, null, true).map();
      }
    );
  }
}