diff options
author | eug-vs <eug-vs@keemail.me> | 2021-03-20 00:12:40 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2021-03-20 00:12:40 +0300 |
commit | cd284d9e4c1f28bf7c31c52d71e76878a3ff5f4a (patch) | |
tree | ed6b97b4e9bc85c921869de004dfff8f5e2066dc /src/hooks/formatDate.ts | |
parent | ad530510a4aba72f3074f1a7dec82cc9018db7b4 (diff) | |
download | commercel-api-cd284d9e4c1f28bf7c31c52d71e76878a3ff5f4a.tar.gz |
feat: move formatDate to hooks
Diffstat (limited to 'src/hooks/formatDate.ts')
-rw-r--r-- | src/hooks/formatDate.ts | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/hooks/formatDate.ts b/src/hooks/formatDate.ts new file mode 100644 index 0000000..ada8502 --- /dev/null +++ b/src/hooks/formatDate.ts @@ -0,0 +1,11 @@ +import { HookContext } from '@feathersjs/feathers'; +import { populate, alterItems } from 'feathers-hooks-common'; +import moment from 'moment'; +import _ from 'lodash'; + +const formatDate = (fieldName = 'date') => alterItems(item => { + const date = _.get(item, fieldName); + return _.set(item, fieldName, moment(date).format('YYYY-MM-DD')); +}); + +export default formatDate; |