Skip to content

Commit

Permalink
Add enum 'CriteriaTokenType'
Browse files Browse the repository at this point in the history
  • Loading branch information
danetsao committed Feb 19, 2024
1 parent fdf72ac commit 20f39ce
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/api/dto/from/dtoToAggregateCriteria.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/api/dto/from/dtoToData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion src/api/dto/from/dtoToHeaderFooter.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions src/api/dto/to/aggregateCriteriaToFilterDto.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -9,15 +9,15 @@ 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),
};

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),
};
Expand Down
5 changes: 3 additions & 2 deletions src/api/dto/to/dataToDto.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -33,15 +34,15 @@ 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),
};

case DataTokenType.AGGREGATE_TOTAL:
return {
type: 'Aggregate',
value: 'TOTAL_AMOUNT',
value: CriteriaTokenType.TOTAL_AMOUNT,
decimal: token.decimal,
lengthControl: lengthControlToDto(token.lengthControl),
};
Expand Down
5 changes: 3 additions & 2 deletions src/api/dto/to/headerFooterToDto.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -32,15 +33,15 @@ 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),
};

case HeaderFooterTokenType.AGGREGATE_TOTAL:
return {
type: 'Aggregate',
value: 'TOTAL_AMOUNT',
value: CriteriaTokenType.TOTAL_AMOUNT,
decimal: token.decimal,
lengthControl: lengthControlToDto(token.lengthControl),
};
Expand Down
5 changes: 5 additions & 0 deletions src/types/CriteriaTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,8 @@ export enum CriteriaAggregateType {
NUM_ROWS = 'NumRows',
TOTAL_AMOUNT = 'TotalAmount',
}

export enum CriteriaTokenType {
NUM_ROWS = 'NUM_ROWS',
TOTAL_AMOUNT = 'TOTAL_AMOUNT',
}

0 comments on commit 20f39ce

Please sign in to comment.