Update serializers to work with jobs endpoint response
This commit is contained in:
parent
d59e402314
commit
74a9a1603e
|
@ -10,9 +10,36 @@ Serializer = V2FallbackSerializer.extend
|
|||
_duration: { key: 'duration' }
|
||||
}
|
||||
|
||||
extractRelationships: (modelClass, resourceHash) ->
|
||||
result = @_super(modelClass, resourceHash)
|
||||
result
|
||||
|
||||
normalizeArrayResponse: (store, primaryModelClass, payload, id, requestType) ->
|
||||
if payload.commits
|
||||
payload.builds.forEach (build) ->
|
||||
commit_id = build.commit_id
|
||||
if commit = payload.commits.findBy('id', commit_id)
|
||||
build.commit = commit
|
||||
delete build.commit_id
|
||||
|
||||
result = @_super.apply(this, arguments)
|
||||
store = this.store
|
||||
# TODO: probably it should be done for all of the relationships, not
|
||||
# only commit
|
||||
result.data.forEach (item) ->
|
||||
if item.relationships && item.relationships.commit
|
||||
serializer = store.serializerFor 'commit'
|
||||
modelClass = store.modelFor 'commit'
|
||||
normalized = serializer.normalize(modelClass, item.relationships.commit.data)
|
||||
result.included.push normalized.data
|
||||
|
||||
result
|
||||
|
||||
keyForV2Relationship: (key, typeClass, method) ->
|
||||
if key == 'repo'
|
||||
'repository_id'
|
||||
else if key == 'commit'
|
||||
key
|
||||
else
|
||||
@_super.apply(this, arguments)
|
||||
|
||||
|
|
|
@ -10,16 +10,16 @@ Serializer = V2FallbackSerializer.extend
|
|||
_startedAt: { key: 'started_at' }
|
||||
}
|
||||
|
||||
extractSingle: (store, primaryType, rawPayload, recordId) ->
|
||||
if commit = rawPayload.commit
|
||||
rawPayload.commits = [commit]
|
||||
|
||||
@_super(store, primaryType, rawPayload, recordId)
|
||||
|
||||
keyForV2Relationship: (key, typeClass, method) ->
|
||||
if key == 'repo'
|
||||
'repository_id'
|
||||
else
|
||||
@_super.apply(this, arguments)
|
||||
|
||||
normalize: (modelClass, resourceHash) ->
|
||||
if resourceHash.commit
|
||||
resourceHash.commit['type'] = 'commit'
|
||||
|
||||
@_super(modelClass, resourceHash)
|
||||
|
||||
`export default Serializer`
|
||||
|
|
|
@ -35,6 +35,26 @@ export default V3Serializer.extend({
|
|||
}
|
||||
},
|
||||
|
||||
normalize(modelClass, resourceHash) {
|
||||
if(resourceHash['@type']) {
|
||||
return this._super(...arguments);
|
||||
} else {
|
||||
var modelKey = modelClass.modelName;
|
||||
var attributes = resourceHash[modelKey];
|
||||
if(attributes) {
|
||||
for(var key in attributes) {
|
||||
resourceHash[key] = attributes[key];
|
||||
};
|
||||
|
||||
resourceHash['@type'] = modelKey;
|
||||
resourceHash['type'] = modelKey;
|
||||
delete resourceHash[modelKey];
|
||||
}
|
||||
|
||||
return this._super(modelClass, resourceHash);
|
||||
}
|
||||
},
|
||||
|
||||
keyForV2Relationship(key, typeClass, method) {
|
||||
return key.underscore() + '_id';
|
||||
}
|
||||
|
|
|
@ -4,10 +4,12 @@ import DS from 'ember-data';
|
|||
export default DS.JSONSerializer.extend({
|
||||
isNewSerializerAPI: true,
|
||||
|
||||
extractRelationship() {
|
||||
extractRelationship(type, hash) {
|
||||
let relationshipHash = this._super(...arguments);
|
||||
if(relationshipHash && relationshipHash['@type']) {
|
||||
relationshipHash.type = relationshipHash['@type'];
|
||||
} else if(relationshipHash && !relationshipHash.type) {
|
||||
relationshipHash.type = type;
|
||||
}
|
||||
return relationshipHash;
|
||||
},
|
||||
|
@ -101,5 +103,13 @@ export default DS.JSONSerializer.extend({
|
|||
}
|
||||
|
||||
return { data, included };
|
||||
},
|
||||
|
||||
keyForAttribute(key, method) {
|
||||
if(method === 'deserialize') {
|
||||
return Ember.String.underscore(key);
|
||||
} else {
|
||||
return Ember.String.camelize(key);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user