diff --git a/x-pack/legacy/plugins/alerting/server/alerts_client.ts b/x-pack/legacy/plugins/alerting/server/alerts_client.ts index d394652462466..87b5cfb277f44 100644 --- a/x-pack/legacy/plugins/alerting/server/alerts_client.ts +++ b/x-pack/legacy/plugins/alerting/server/alerts_client.ts @@ -64,11 +64,11 @@ export interface FindOptions { }; } -export interface FindResult { +export interface FindResult { page: number; perPage: number; total: number; - data: T[]; + data: Alert[]; } interface CreateOptions { @@ -186,29 +186,24 @@ export class AlertsClient { return this.getAlertFromRaw(result.id, result.attributes, result.updated_at, result.references); } - public async find({ options = {} }: FindOptions = {}): Promise< - FindResult - > { - const results = await this.savedObjectsClient.find({ + public async find({ options = {} }: FindOptions = {}): Promise { + const { + page, + per_page: perPage, + total, + saved_objects: data, + } = await this.savedObjectsClient.find({ ...options, type: 'alert', }); - const data = results.saved_objects.map( - result => - this.getAlertFromRaw( - result.id, - result.attributes, - result.updated_at, - result.references - ) as T - ); - return { - page: results.page, - perPage: results.per_page, - total: results.total, - data, + page, + perPage, + total, + data: data.map(({ id, attributes, updated_at, references }) => + this.getAlertFromRaw(id, attributes, updated_at, references) + ), }; } diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/find_rules.ts b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/find_rules.ts index c63bee43b86b7..5f69082e3fc71 100644 --- a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/find_rules.ts +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/find_rules.ts @@ -24,7 +24,7 @@ export const findRules = async ({ sortField, sortOrder, }: FindRuleParams) => { - return alertsClient.find({ + return alertsClient.find({ options: { fields, page, @@ -33,5 +33,10 @@ export const findRules = async ({ sortOrder, sortField, }, - }); + }) as Promise<{ + page: number; + perPage: number; + total: number; + data: RuleAlertType[]; + }>; };