fix: append ?plugin_name to dynamic host catalog create requests
This commit is contained in:
4 files changed
+54
-1
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import ApplicationAdapter from './application';
|
||||
import { serializeIntoHash } from '@ember-data/adapter/-private';
|
||||
|
||||
export default class HostCatalogAdapter extends ApplicationAdapter {
|
||||
/**
|
||||
Called by the store when a newly created record is
|
||||
saved via the `save` method on a model record instance.
|
||||
|
||||
The `createRecord` method serializes the record and makes an Ajax (HTTP POST) request
|
||||
to a URL computed by `buildURL`.
|
||||
|
||||
See `serialize` for information on how to customize the serialized form
|
||||
of a record.
|
||||
|
||||
@method createRecord
|
||||
@param {Store} store
|
||||
@param {Model} type
|
||||
@param {Snapshot} snapshot
|
||||
@return {Promise} promise
|
||||
*/
|
||||
createRecord(store, type, snapshot) {
|
||||
let url = this.buildURL(type.modelName, null, snapshot, 'createRecord');
|
||||
const pluginName = snapshot.attr('plugin')?.name;
|
||||
if (pluginName) url = `${url}?plugin_name=${pluginName}`;
|
||||
const data = serializeIntoHash(store, type, snapshot);
|
||||
return this.ajax(url, 'POST', { data });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from 'api/adapters/host-catalog';
|
||||
@@ -270,7 +270,19 @@ export default function () {
|
||||
return hostCatalogs.where({ scopeId });
|
||||
}
|
||||
);
|
||||
this.post('/host-catalogs');
|
||||
this.post(
|
||||
'/host-catalogs',
|
||||
function ({ hostCatalogs }, { queryParams: { plugin_name } }) {
|
||||
const attrs = this.normalizedRequestAttrs();
|
||||
if (plugin_name) {
|
||||
attrs.type = 'plugin';
|
||||
attrs.plugin = {
|
||||
name: plugin_name,
|
||||
};
|
||||
}
|
||||
return hostCatalogs.create(attrs);
|
||||
}
|
||||
);
|
||||
this.get('/host-catalogs/:id');
|
||||
this.patch('/host-catalogs/:id');
|
||||
this.del('/host-catalogs/:id');
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Adapter | host catalog', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function (assert) {
|
||||
let adapter = this.owner.lookup('adapter:host-catalog');
|
||||
assert.ok(adapter);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user