--- /dev/null
+/* Copyright (c) 2019 AT&T Intellectual Property. #\r
+# #\r
+# Licensed under the Apache License, Version 2.0 (the "License"); #\r
+# you may not use this file except in compliance with the License. #\r
+# You may obtain a copy of the License at #\r
+# #\r
+# http://www.apache.org/licenses/LICENSE-2.0 #\r
+# #\r
+# Unless required by applicable law or agreed to in writing, software #\r
+# distributed under the License is distributed on an "AS IS" BASIS, #\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #\r
+# See the License for the specific language governing permissions and #\r
+# limitations under the License. #\r
+##############################################################################*/\r
+\r
+\r
+// Application hooks that run for every service\r
+const log = require('./hooks/log');\r
+const paginateOption = require('./hooks/paginate-option');\r
+const createdBy = require('./hooks/createdBy');\r
+const updatedBy = require('./hooks/updatedBy');\r
+const {iff, disallow, isProvider, skipRemainingHooks} = require('feathers-hooks-common');\r
+const { ObjectID } = require('mongodb');\r
+\r
+module.exports = {\r
+ before: {\r
+ all: [paginateOption(), skipRemainingHooks(context => !context.params.provider)],\r
+ find: [\r
+ function(context){\r
+ const {query} = context.params;\r
+\r
+ iterate(query, '');\r
+\r
+ return context;\r
+ }\r
+ ],\r
+ get: [],\r
+ create: [createdBy()],\r
+ update: [updatedBy()],\r
+ patch: [updatedBy()],\r
+ remove: []\r
+ },\r
+\r
+ after: {\r
+ all: [],\r
+ find: [],\r
+ get: [],\r
+ create: [],\r
+ update: [],\r
+ patch: [],\r
+ remove: []\r
+ },\r
+\r
+ error: {\r
+ all: [log()],\r
+ find: [],\r
+ get: [],\r
+ create: [],\r
+ update: [],\r
+ patch: [],\r
+ remove: []\r
+ }\r
+};\r
+\r
+function iterate(obj, stack) {\r
+ for (var property in obj) {\r
+ if (obj.hasOwnProperty(property)) {\r
+ if (typeof obj[property] == "object") {\r
+\r
+ //check for $in\r
+ if(/\._id$/.test(property) && obj[property]['$in'] && obj[property]['$in'].length && obj[property]['$in'].length > 0){\r
+ obj[property]['$in'].forEach((elem, val) => {\r
+ obj[property]['$in'][val] = new ObjectID(elem);\r
+ })\r
+ }else{\r
+ iterate(obj[property], stack + '.' + property);\r
+ }\r
+ } else if(/\._id$/.test(property)){\r
+ obj[property] = new ObjectID(obj[property]);\r
+ }\r
+ }\r
+ }\r
+}\r