OpenFn/OpenFn-Site

View on GitHub
app/assets/javascripts/the_bridge_ng/services/mappings/mapping_service.js.coffee

Summary

Maintainability
Test Coverage
@serviceModule.factory 'MappingService', ['Mapping'
  (Mapping) ->

    mappingParams: (mapping) ->
      hash = {
        mapping: {
          name: mapping.name
          active: mapping.active
          enabled: mapping.enabled
          odk_form_attributes: mapping.odkForm
          can_be_enabled: mapping.can_be_enabled
        }
      }

    saveMapping: (mapping) ->
      if mapping.id
        Mapping.update {id: mapping.id}, @mappingParams(mapping)
      else
        # Create a mapping using the custom params for nested objects
        Mapping.save {}, @mappingParams(mapping)
]