Skip to content

Commit

Permalink
removed generics in AlertsClient
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Dec 30, 2019
1 parent f6b0dfb commit 36ea491
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
35 changes: 15 additions & 20 deletions x-pack/legacy/plugins/alerting/server/alerts_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ export interface FindOptions {
};
}

export interface FindResult<T extends Alert = Alert> {
export interface FindResult {
page: number;
perPage: number;
total: number;
data: T[];
data: Alert[];
}

interface CreateOptions {
Expand Down Expand Up @@ -186,29 +186,24 @@ export class AlertsClient {
return this.getAlertFromRaw(result.id, result.attributes, result.updated_at, result.references);
}

public async find<T extends Alert = Alert>({ options = {} }: FindOptions = {}): Promise<
FindResult<T>
> {
const results = await this.savedObjectsClient.find<RawAlert>({
public async find({ options = {} }: FindOptions = {}): Promise<FindResult> {
const {
page,
per_page: perPage,
total,
saved_objects: data,
} = await this.savedObjectsClient.find<RawAlert>({
...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)
),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const findRules = async ({
sortField,
sortOrder,
}: FindRuleParams) => {
return alertsClient.find<RuleAlertType>({
return alertsClient.find({
options: {
fields,
page,
Expand All @@ -33,5 +33,10 @@ export const findRules = async ({
sortOrder,
sortField,
},
});
}) as Promise<{
page: number;
perPage: number;
total: number;
data: RuleAlertType[];
}>;
};

0 comments on commit 36ea491

Please sign in to comment.