2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2020-10-29 12:46:42 +00:00
|
|
|
import ApplicationAdapter from './application';
|
2022-03-08 17:28:36 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2020-10-29 12:46:42 +00:00
|
|
|
|
2022-03-08 17:28:36 +00:00
|
|
|
@classic
|
2020-10-29 12:46:42 +00:00
|
|
|
export default class RecommendationSummaryAdapter extends ApplicationAdapter {
|
|
|
|
pathForType = () => 'recommendations';
|
|
|
|
|
|
|
|
urlForFindAll() {
|
|
|
|
const url = super.urlForFindAll(...arguments);
|
|
|
|
return `${url}?namespace=*`;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateRecord(store, type, snapshot) {
|
2021-12-28 16:08:12 +00:00
|
|
|
const url = `${super.urlForCreateRecord(
|
|
|
|
'recommendations',
|
|
|
|
snapshot
|
|
|
|
)}/apply`;
|
2020-10-29 12:46:42 +00:00
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
const allRecommendationIds = snapshot
|
|
|
|
.hasMany('recommendations')
|
|
|
|
.mapBy('id');
|
|
|
|
const excludedRecommendationIds = (
|
|
|
|
snapshot.hasMany('excludedRecommendations') || []
|
|
|
|
).mapBy('id');
|
|
|
|
const includedRecommendationIds = allRecommendationIds.removeObjects(
|
|
|
|
excludedRecommendationIds
|
2020-10-29 12:46:42 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
Apply: includedRecommendationIds,
|
|
|
|
Dismiss: excludedRecommendationIds,
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.ajax(url, 'POST', { data });
|
|
|
|
}
|
|
|
|
}
|