Skip to content

Commit

Permalink
Merge pull request #1 from nchaulet/ts-update-beats-cm
Browse files Browse the repository at this point in the history
Fix ts errors for beats management
  • Loading branch information
mshustov authored May 29, 2020
2 parents a7bcdcf + 626b710 commit baa6209
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ import { DatabaseAdapter } from '../database/adapter_types';
import { FrameworkUser } from '../framework/adapter_types';
import { BeatsTagAssignment, CMBeatsAdapter } from './adapter_types';

function formatWithTags(beat: CMBeat) {
const { tags, ...rest } = beat;

return {
tags: tags || [],
...rest,
};
}

export class ElasticsearchBeatsAdapter implements CMBeatsAdapter {
private database: DatabaseAdapter;

Expand Down Expand Up @@ -97,10 +106,9 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter {
if (beats.length === 0) {
return [];
}
return beats.map((beat: any) => ({
tags: [] as string[],
...(omit(beat._source.beat as CMBeat, ['access_token']) as CMBeat),
}));
return beats.map((beat: any) =>
formatWithTags(omit(beat._source.beat as CMBeat, ['access_token']) as CMBeat)
);
}

public async getBeatWithToken(
Expand All @@ -124,7 +132,7 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter {
if (beats.length === 0) {
return null;
}
return omit<CMBeat, {}>(_get<CMBeat>({ tags: [], ...beats[0] }, '_source.beat'), [
return omit<CMBeat, {}>(_get<CMBeat>(formatWithTags(beats[0]), '_source.beat'), [
'access_token',
]);
}
Expand Down Expand Up @@ -165,10 +173,9 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter {
}
const beats = _get<any>(response, 'hits.hits', []);

return beats.map((beat: any) => ({
tags: [] as string[],
...(omit(beat._source.beat as CMBeat, ['access_token']) as CMBeat),
}));
return beats.map((beat: any) =>
formatWithTags(omit(beat._source.beat as CMBeat, ['access_token']) as CMBeat)
);
}

public async removeTagsFromBeats(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,13 @@ export class ElasticsearchConfigurationBlockAdapter implements ConfigurationBloc
public async create(user: FrameworkUser, configs: ConfigurationBlock[]): Promise<string[]> {
const body = flatten(
configs.map((config) => {
const id = config.id || uuidv4();
const { id: configId, ...configWithoutId } = config;
const id = configId || uuidv4();
return [
{ index: { _id: `configuration_block:${id}` } },
{
type: 'configuration_block',
configuration_block: { id, ...config, config: JSON.stringify(config.config) },
configuration_block: { id, ...configWithoutId, config: JSON.stringify(config.config) },
},
];
})
Expand Down

0 comments on commit baa6209

Please sign in to comment.