diff options
Diffstat (limited to 'src/hooks')
-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; |