Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can also do id = uuidv4() to use uuid if id is falsy. No issue, just an option.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nchaulet Do you want to accept this suggestion? Or can I merge the PR?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am currently in a phone I think you can merge it as it is.

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