From cfdce1fb1179cfe4f15fc26676f064ca10fb9ce4 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 17 Apr 2021 15:21:08 +0300 Subject: refactor: move transformDate to transforms --- src/services/account/index.ts | 3 ++- src/services/transfers/index.ts | 4 ++-- src/services/transforms.ts | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/services/account/index.ts b/src/services/account/index.ts index cbe56f5..ab8ab38 100644 --- a/src/services/account/index.ts +++ b/src/services/account/index.ts @@ -1,10 +1,11 @@ import { ServiceParams } from '../../lib/ServiceContext'; +import { transformDate } from '../transforms'; const service: ServiceParams = { route: 'account', name: 'Рассчётный счёт', tableFields: [ - { key: 'date', label: 'Дата', transform: date => new Date(date).toLocaleDateString() }, + { key: 'date', label: 'Дата', transform: transformDate }, { key: 'amount', label: 'Сумма' }, ], actions: [ diff --git a/src/services/transfers/index.ts b/src/services/transfers/index.ts index ece8dae..2a0cad1 100644 --- a/src/services/transfers/index.ts +++ b/src/services/transfers/index.ts @@ -1,6 +1,6 @@ import Form from './TransferForm'; import UploadPage from './TransfersUpload'; -import { transformOperation } from '../transforms'; +import { transformDate, transformOperation } from '../transforms'; import { ServiceParams } from '../../lib/ServiceContext'; import { Transfer } from '../types'; @@ -10,7 +10,7 @@ const service: ServiceParams = { name: 'Переводы', nameSingular: 'Перевод', tableFields: [ - { key: 'date', label: 'Дата', transform: date => new Date(date).toLocaleDateString() }, + { key: 'date', label: 'Дата', transform: transformDate }, { key: 'contractor.name', label: 'Контрагент' }, { key: 'operation', label: 'Операция', transform: transformOperation }, { key: 'amount', label: 'Сумма' }, diff --git a/src/services/transforms.ts b/src/services/transforms.ts index 2eea46f..c12568e 100644 --- a/src/services/transforms.ts +++ b/src/services/transforms.ts @@ -7,6 +7,9 @@ const transformer = (hash: Record): Transformer => return value => _.get(hash, value, value); }; +export const transformDate = (date: string): string => { + return new Date(date).toLocaleDateString(); +}; export const transformOperation = transformer({ in: 'Приход', -- cgit v1.2.3