From cd284d9e4c1f28bf7c31c52d71e76878a3ff5f4a Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 20 Mar 2021 00:12:40 +0300 Subject: feat: move formatDate to hooks --- src/hooks/formatDate.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/hooks/formatDate.ts (limited to 'src/hooks') 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; -- cgit v1.2.3