47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
import Ember from 'ember';
|
|
import V2FallbackSerializer from 'travis/serializers/v2_fallback';
|
|
|
|
var Serializer = V2FallbackSerializer.extend({
|
|
isNewSerializerAPI: true,
|
|
attrs: {
|
|
_config: { key: 'config' },
|
|
_finished_at: { key: 'finished_at' },
|
|
_started_at: { key: 'started_at' }
|
|
},
|
|
|
|
keyForV2Relationship(key, typeClass, method) {
|
|
if (key === 'repo') {
|
|
return 'repository_id';
|
|
} else {
|
|
return this._super.apply(this, arguments);
|
|
}
|
|
},
|
|
|
|
normalize(modelClass, resourceHash) {
|
|
if (resourceHash.commit) {
|
|
resourceHash.commit['type'] = 'commit';
|
|
}
|
|
|
|
return this._super(modelClass, resourceHash);
|
|
},
|
|
|
|
normalizeArrayResponse: function(store, primaryModelClass, payload, id, requestType) {
|
|
var result;
|
|
if (payload.commits) {
|
|
payload.jobs.forEach(function(job) {
|
|
var commit, commit_id;
|
|
commit_id = job.commit_id;
|
|
if (commit = payload.commits.findBy('id', commit_id)) {
|
|
job.commit = commit;
|
|
return delete job.commit_id;
|
|
}
|
|
});
|
|
}
|
|
return this._super.apply(this, arguments);
|
|
},
|
|
|
|
|
|
});
|
|
|
|
export default Serializer;
|