From 20f39cece0c823157b827d5f9f0e9418cfc6eae1 Mon Sep 17 00:00:00 2001 From: danetsaoo Date: Mon, 19 Feb 2024 14:55:53 -0600 Subject: [PATCH] Add enum 'CriteriaTokenType' --- src/api/dto/from/dtoToAggregateCriteria.ts | 6 +++--- src/api/dto/from/dtoToData.ts | 3 ++- src/api/dto/from/dtoToHeaderFooter.ts | 3 ++- src/api/dto/to/aggregateCriteriaToFilterDto.ts | 6 +++--- src/api/dto/to/dataToDto.ts | 5 +++-- src/api/dto/to/headerFooterToDto.ts | 5 +++-- src/types/CriteriaTypes.ts | 5 +++++ 7 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/api/dto/from/dtoToAggregateCriteria.ts b/src/api/dto/from/dtoToAggregateCriteria.ts index 9bddf3f..c06c44d 100644 --- a/src/api/dto/from/dtoToAggregateCriteria.ts +++ b/src/api/dto/from/dtoToAggregateCriteria.ts @@ -1,6 +1,6 @@ import { IntlShape } from 'react-intl'; import { StripesType } from '@folio/stripes/core'; -import { ComparisonOperator, CriteriaAggregate, CriteriaAggregateType } from '../../../types/CriteriaTypes'; +import { ComparisonOperator, CriteriaAggregate, CriteriaAggregateType, CriteriaTokenType } from '../../../types/CriteriaTypes'; import { BursarExportFilterAggregate } from '../types'; // inverse of ../to/aggregateCriteriaToFilterDto @@ -10,13 +10,13 @@ export default function dtoToAggregateCriteria( intl: IntlShape, ): CriteriaAggregate | undefined { switch (filter?.property) { - case 'NUM_ROWS': + case CriteriaTokenType.NUM_ROWS: return { type: CriteriaAggregateType.NUM_ROWS, operator: filter.condition as ComparisonOperator, amount: intl.formatNumber(filter.amount, { style: 'currency', currency: stripes.currency }), }; - case 'TOTAL_AMOUNT': + case CriteriaTokenType.TOTAL_AMOUNT: return { type: CriteriaAggregateType.TOTAL_AMOUNT, operator: filter.condition as ComparisonOperator, diff --git a/src/api/dto/from/dtoToData.ts b/src/api/dto/from/dtoToData.ts index fb04c4a..0c6869b 100644 --- a/src/api/dto/from/dtoToData.ts +++ b/src/api/dto/from/dtoToData.ts @@ -7,6 +7,7 @@ import { LocationDTO } from '../../queries/useLocations'; import { BursarExportDataTokenDTO, BursarExportTokenAggregate, BursarExportTokenConstant } from '../types'; import dtoToCriteria from './dtoToCriteria'; import dtoToLengthControl from './dtoToLengthControl'; +import { CriteriaTokenType } from '../../../types/CriteriaTypes'; // inverse of ../to/dataToDto export default function dtoToData( @@ -125,7 +126,7 @@ export function constantToToken(token: BursarExportTokenConstant): DataToken { } export function aggregateToToken(token: BursarExportTokenAggregate): DataToken { - if (token.value === 'NUM_ROWS') { + if (token.value === CriteriaTokenType.NUM_ROWS) { return { type: DataTokenType.AGGREGATE_COUNT, lengthControl: dtoToLengthControl(token.lengthControl), diff --git a/src/api/dto/from/dtoToHeaderFooter.ts b/src/api/dto/from/dtoToHeaderFooter.ts index 8f8dcba..aa35817 100644 --- a/src/api/dto/from/dtoToHeaderFooter.ts +++ b/src/api/dto/from/dtoToHeaderFooter.ts @@ -1,4 +1,5 @@ import ConvenientConstants from '../../../types/ConvenientConstants'; +import { CriteriaTokenType } from '../../../types/CriteriaTypes'; import { DateFormatType, HeaderFooterToken, HeaderFooterTokenType } from '../../../types/TokenTypes'; import { BursarExportHeaderFooterTokenDTO, BursarExportTokenAggregate, BursarExportTokenConstant } from '../types'; import dtoToLengthControl from './dtoToLengthControl'; @@ -50,7 +51,7 @@ export function constantToToken(token: BursarExportTokenConstant): HeaderFooterT } export function aggregateToToken(token: BursarExportTokenAggregate): HeaderFooterToken { - if (token.value === 'NUM_ROWS') { + if (token.value === CriteriaTokenType.NUM_ROWS) { return { type: HeaderFooterTokenType.AGGREGATE_COUNT, lengthControl: dtoToLengthControl(token.lengthControl), diff --git a/src/api/dto/to/aggregateCriteriaToFilterDto.ts b/src/api/dto/to/aggregateCriteriaToFilterDto.ts index 760583e..e5c1ad1 100644 --- a/src/api/dto/to/aggregateCriteriaToFilterDto.ts +++ b/src/api/dto/to/aggregateCriteriaToFilterDto.ts @@ -1,4 +1,4 @@ -import { CriteriaAggregate, CriteriaAggregateType } from '../../../types/CriteriaTypes'; +import { CriteriaAggregate, CriteriaAggregateType, CriteriaTokenType } from '../../../types/CriteriaTypes'; import guardNumber from '../../../utils/guardNumber'; import { BursarExportFilterAggregate } from '../types'; @@ -9,7 +9,7 @@ export default function aggregateCriteriaToFilterDto( case CriteriaAggregateType.NUM_ROWS: return { type: 'Aggregate', - property: 'NUM_ROWS', + property: CriteriaTokenType.NUM_ROWS, condition: criteria.operator ?? 'GREATER_THAN_EQUAL', amount: guardNumber(criteria.amount, 0), }; @@ -17,7 +17,7 @@ export default function aggregateCriteriaToFilterDto( case CriteriaAggregateType.TOTAL_AMOUNT: return { type: 'Aggregate', - property: 'TOTAL_AMOUNT', + property: CriteriaTokenType.TOTAL_AMOUNT, condition: criteria.operator ?? 'GREATER_THAN_EQUAL', amount: guardNumber(criteria.amountCurrency, 0, (value) => value * 100), }; diff --git a/src/api/dto/to/dataToDto.ts b/src/api/dto/to/dataToDto.ts index 45fa7a1..a73973c 100644 --- a/src/api/dto/to/dataToDto.ts +++ b/src/api/dto/to/dataToDto.ts @@ -1,4 +1,5 @@ import ConvenientConstants from '../../../types/ConvenientConstants'; +import { CriteriaTokenType } from '../../../types/CriteriaTypes'; import { DataToken, DataTokenType } from '../../../types/TokenTypes'; import { guardNumberPositive } from '../../../utils/guardNumber'; import { BursarExportDataTokenDTO } from '../types'; @@ -33,7 +34,7 @@ export function dataTokenToDto(token: DataToken): BursarExportDataTokenDTO { case DataTokenType.AGGREGATE_COUNT: return { type: 'Aggregate', - value: 'NUM_ROWS', + value: CriteriaTokenType.NUM_ROWS, decimal: false, lengthControl: lengthControlToDto(token.lengthControl), }; @@ -41,7 +42,7 @@ export function dataTokenToDto(token: DataToken): BursarExportDataTokenDTO { case DataTokenType.AGGREGATE_TOTAL: return { type: 'Aggregate', - value: 'TOTAL_AMOUNT', + value: CriteriaTokenType.TOTAL_AMOUNT, decimal: token.decimal, lengthControl: lengthControlToDto(token.lengthControl), }; diff --git a/src/api/dto/to/headerFooterToDto.ts b/src/api/dto/to/headerFooterToDto.ts index df9007e..153e263 100644 --- a/src/api/dto/to/headerFooterToDto.ts +++ b/src/api/dto/to/headerFooterToDto.ts @@ -1,4 +1,5 @@ import ConvenientConstants from '../../../types/ConvenientConstants'; +import { CriteriaTokenType } from '../../../types/CriteriaTypes'; import { HeaderFooterToken, HeaderFooterTokenType } from '../../../types/TokenTypes'; import { guardNumberPositive } from '../../../utils/guardNumber'; import { BursarExportHeaderFooterTokenDTO } from '../types'; @@ -32,7 +33,7 @@ export function headerFooterTokenToDto(token: HeaderFooterToken): BursarExportHe case HeaderFooterTokenType.AGGREGATE_COUNT: return { type: 'Aggregate', - value: 'NUM_ROWS', + value: CriteriaTokenType.NUM_ROWS, decimal: false, lengthControl: lengthControlToDto(token.lengthControl), }; @@ -40,7 +41,7 @@ export function headerFooterTokenToDto(token: HeaderFooterToken): BursarExportHe case HeaderFooterTokenType.AGGREGATE_TOTAL: return { type: 'Aggregate', - value: 'TOTAL_AMOUNT', + value: CriteriaTokenType.TOTAL_AMOUNT, decimal: token.decimal, lengthControl: lengthControlToDto(token.lengthControl), }; diff --git a/src/types/CriteriaTypes.ts b/src/types/CriteriaTypes.ts index 21f6134..044d2a1 100644 --- a/src/types/CriteriaTypes.ts +++ b/src/types/CriteriaTypes.ts @@ -90,3 +90,8 @@ export enum CriteriaAggregateType { NUM_ROWS = 'NumRows', TOTAL_AMOUNT = 'TotalAmount', } + +export enum CriteriaTokenType { + NUM_ROWS = 'NUM_ROWS', + TOTAL_AMOUNT = 'TOTAL_AMOUNT', +}