vault/ui/lib/kmip/addon/routes/configure.js
Chelsea Shaw da7fad68b8
UI: Replace getNewModel with hydrateModel when model exists (#27978)
* Replace getNewModel with hydrateModel when model exists

* Update getNewModel to only handle nonexistant model types

* Update test

* clarify test

* Fix auth-config models which need hydration not generation

* rename file to match service name

* cleanup + tests

* Add comment about helpUrl method
2024-08-07 16:07:25 +00:00

28 lines
727 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Route from '@ember/routing/route';
import { service } from '@ember/service';
export default Route.extend({
store: service(),
secretMountPath: service(),
pathHelp: service(),
beforeModel() {
return this.pathHelp.hydrateModel('kmip/config', this.secretMountPath.currentPath);
},
model() {
return this.store.findRecord('kmip/config', this.secretMountPath.currentPath).catch((err) => {
if (err.httpStatus === 404) {
const model = this.store.createRecord('kmip/config');
model.set('id', this.secretMountPath.currentPath);
return model;
} else {
throw err;
}
});
},
});