kibana/x-pack/legacy/plugins/actions/server/routes/create.ts
Patrick Mueller 6acb716b2c
Changes action create/update http apis to return bodies (#42493)
Prior to this PR, the create and update http apis for actions returned
an object with the shape `{ id: <id of relevant action> }`.

This PR changes the responses to be the complete body of the action that
was created / updated, not just the `id`.

I believe this is the final piece of the "fix http apis for actions / alerts"
issue https://github.com/elastic/kibana/issues/41828
2019-08-05 14:42:58 -04:00

52 lines
1.3 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import Joi from 'joi';
import Hapi from 'hapi';
import { ActionResult, WithoutQueryAndParams } from '../types';
interface CreateRequest extends WithoutQueryAndParams<Hapi.Request> {
query: {
overwrite: boolean;
};
params: {
id?: string;
};
payload: {
description: string;
actionTypeId: string;
config: Record<string, any>;
secrets: Record<string, any>;
};
}
export function createRoute(server: Hapi.Server) {
server.route({
method: 'POST',
path: `/api/action`,
options: {
validate: {
options: {
abortEarly: false,
},
payload: Joi.object()
.keys({
description: Joi.string().required(),
actionTypeId: Joi.string().required(),
config: Joi.object().default({}),
secrets: Joi.object().default({}),
})
.required(),
},
},
async handler(request: CreateRequest): Promise<ActionResult> {
const actionsClient = request.getActionsClient!();
const action = request.payload;
return await actionsClient.create({ action });
},
});
}