travis-web/app/serializers/build.coffee
Piotr Sarnacki d59e402314 Include repositoryId as an attribute on build
For some reason (probably some problem with one of the serializers) we
sometimes lack an id attribute for a promise that we get for a repo
relationship on build. Because of that doing `build.get('repo.id')` may
sometimes return undefined. A temporary workaround is to make sure that
we always can access the `repository_id` property.
2015-12-08 10:18:03 +01:00

39 lines
1.2 KiB
CoffeeScript

`import Ember from 'ember'`
`import V2FallbackSerializer from 'travis/serializers/v2_fallback'`
Serializer = V2FallbackSerializer.extend
isNewSerializerAPI: true
attrs: {
_config: { key: 'config' }
_finishedAt: { key: 'finished_at' }
_startedAt: { key: 'started_at' }
_duration: { key: 'duration' }
}
keyForV2Relationship: (key, typeClass, method) ->
if key == 'repo'
'repository_id'
else
@_super.apply(this, arguments)
normalize: (modelClass, resourceHash) ->
result = @_super(modelClass, resourceHash)
data = result.data
# for some reasone repo's promise not always has its id set
# so we can't always do build.get('repo.id')
# this ensures that repositoryId is always reachable on build
# TODO: look into the real cause of the problem (maybe it will be gone
# after fully switching to V3 and/or updating ember-data)
if repoId = resourceHash.repository_id
data.attributes.repositoryId = repoId
else if resourceHash.repository
if href = resourceHash.repository['@href']
id = href.match(/\d+/)[0]
data.attributes.repositoryId = id
return result
`export default Serializer`