2018-10-04 04:32:55 +00:00
|
|
|
import { get } from '@ember/object';
|
|
|
|
import ApplicationSerializer from './application';
|
|
|
|
|
|
|
|
export default ApplicationSerializer.extend({
|
|
|
|
secretDataPath: 'data.data',
|
2018-10-06 03:02:23 +00:00
|
|
|
normalizeItems(payload) {
|
2018-10-04 04:32:55 +00:00
|
|
|
let path = this.secretDataPath;
|
|
|
|
// move response that is the contents of the secret from the dataPath
|
|
|
|
// to `secret_data` so it will be `secretData` in the model
|
|
|
|
payload.secret_data = get(payload, path);
|
|
|
|
payload = Object.assign({}, payload, payload.data.metadata);
|
|
|
|
delete payload.data;
|
2018-10-06 03:02:23 +00:00
|
|
|
payload.path = payload.id;
|
2018-10-04 04:32:55 +00:00
|
|
|
// return the payload if it's expecting a single object or wrap
|
|
|
|
// it as an array if not
|
|
|
|
return payload;
|
|
|
|
},
|
|
|
|
serialize(snapshot) {
|
2018-10-15 14:40:18 +00:00
|
|
|
let secret = snapshot.belongsTo('secret');
|
2018-11-19 21:47:58 +00:00
|
|
|
let version = secret.attr('currentVersion') || 0;
|
2018-10-15 14:40:18 +00:00
|
|
|
return {
|
2018-10-04 04:32:55 +00:00
|
|
|
data: snapshot.attr('secretData'),
|
2018-10-15 14:40:18 +00:00
|
|
|
options: {
|
|
|
|
cas: version,
|
|
|
|
},
|
2018-10-04 04:32:55 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|