summaryrefslogtreecommitdiff
path: root/src/hooks
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-03-20 00:12:40 +0300
committereug-vs <eug-vs@keemail.me>2021-03-20 00:12:40 +0300
commitcd284d9e4c1f28bf7c31c52d71e76878a3ff5f4a (patch)
treeed6b97b4e9bc85c921869de004dfff8f5e2066dc /src/hooks
parentad530510a4aba72f3074f1a7dec82cc9018db7b4 (diff)
downloadcommercel-api-cd284d9e4c1f28bf7c31c52d71e76878a3ff5f4a.tar.gz
feat: move formatDate to hooks
Diffstat (limited to 'src/hooks')
-rw-r--r--src/hooks/formatDate.ts11
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;