Skip to content

Commit

Permalink
restrict sortField in converSortField util
Browse files Browse the repository at this point in the history
  • Loading branch information
js-jankisalvi committed Jul 20, 2023
1 parent deb69bd commit 764e40b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/cases/common/api/cases/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ export type Cases = rt.TypeOf<typeof CasesRt>;
export type CasesDeleteRequest = rt.TypeOf<typeof CasesDeleteRequestRt>;
export type CasesByAlertIDRequest = rt.TypeOf<typeof CasesByAlertIDRequestRt>;
export type CasesFindRequest = rt.TypeOf<typeof CasesFindRequestRt>;
export type CasesFindRequestSortFields = rt.TypeOf<typeof CasesFindRequestSortFieldsRt>;
export type CasesFindResponse = rt.TypeOf<typeof CasesFindResponseRt>;
export type CasePatchRequest = rt.TypeOf<typeof CasePatchRequestRt>;
export type CasesPatchRequest = rt.TypeOf<typeof CasesPatchRequestRt>;
Expand Down
14 changes: 1 addition & 13 deletions x-pack/plugins/cases/server/client/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,6 @@ describe('utils', () => {
expect(convertSortField('createdAt')).toBe('created_at');
});

it('transforms created_at correctly', () => {
expect(convertSortField('created_at')).toBe('created_at');
});

it('transforms updated_at correctly', () => {
expect(convertSortField('updated_at')).toBe('updated_at');
});

it('transforms updatedAt correctly', () => {
expect(convertSortField('updatedAt')).toBe('updated_at');
});
Expand All @@ -149,16 +141,12 @@ describe('utils', () => {
expect(convertSortField('closedAt')).toBe('closed_at');
});

it('transforms closed_at correctly', () => {
expect(convertSortField('closed_at')).toBe('closed_at');
});

it('transforms title correctly', () => {
expect(convertSortField('title')).toBe('title.keyword');
});

it('transforms default correctly', () => {
expect(convertSortField('not-exist')).toBe('created_at');
expect(convertSortField(undefined)).toBe('created_at');
});
});

Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/cases/server/client/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {
CaseSeverity,
CommentRequestExternalReferenceType,
CasesFindRequest,
CasesFindRequestSortFields,
} from '../../common/api';
import type { SavedObjectFindOptionsKueryNode } from '../common/types';
import type { CasesFindQueryParams } from './types';
Expand Down Expand Up @@ -475,22 +476,21 @@ enum SortFieldCase {
category = 'category',
}

export const convertSortField = (sortField: string | undefined): SortFieldCase => {
export const convertSortField = (
sortField: CasesFindRequestSortFields | undefined
): SortFieldCase => {
switch (sortField) {
case 'status':
return SortFieldCase.status;
case 'createdAt':
case 'created_at':
return SortFieldCase.createdAt;
case 'closedAt':
case 'closed_at':
return SortFieldCase.closedAt;
case 'title':
return SortFieldCase.title;
case 'severity':
return SortFieldCase.severity;
case 'updatedAt':
case 'updated_at':
return SortFieldCase.updatedAt;
case 'category':
return SortFieldCase.category;
Expand Down

0 comments on commit 764e40b

Please sign in to comment.