X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=otf-frontend%2Fserver%2Fsrc%2Ffeathers%2Fapp.hooks.js;fp=otf-frontend%2Fserver%2Fsrc%2Ffeathers%2Fapp.hooks.js;h=4cd08ac2b4ee974d0f29f705ca23e9cfbf6ceeab;hb=14f6f95c84a4a1fa8774190db4a03fd0214ec55f;hp=0000000000000000000000000000000000000000;hpb=f49bd1efeaaddd4891c1f329b18d8cfb28b3e75b;p=it%2Fotf.git diff --git a/otf-frontend/server/src/feathers/app.hooks.js b/otf-frontend/server/src/feathers/app.hooks.js new file mode 100644 index 0000000..4cd08ac --- /dev/null +++ b/otf-frontend/server/src/feathers/app.hooks.js @@ -0,0 +1,83 @@ +/* Copyright (c) 2019 AT&T Intellectual Property. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +##############################################################################*/ + + +// Application hooks that run for every service +const log = require('./hooks/log'); +const paginateOption = require('./hooks/paginate-option'); +const createdBy = require('./hooks/createdBy'); +const updatedBy = require('./hooks/updatedBy'); +const {iff, disallow, isProvider, skipRemainingHooks} = require('feathers-hooks-common'); +const { ObjectID } = require('mongodb'); + +module.exports = { + before: { + all: [paginateOption(), skipRemainingHooks(context => !context.params.provider)], + find: [ + function(context){ + const {query} = context.params; + + iterate(query, ''); + + return context; + } + ], + get: [], + create: [createdBy()], + update: [updatedBy()], + patch: [updatedBy()], + remove: [] + }, + + after: { + all: [], + find: [], + get: [], + create: [], + update: [], + patch: [], + remove: [] + }, + + error: { + all: [log()], + find: [], + get: [], + create: [], + update: [], + patch: [], + remove: [] + } +}; + +function iterate(obj, stack) { + for (var property in obj) { + if (obj.hasOwnProperty(property)) { + if (typeof obj[property] == "object") { + + //check for $in + if(/\._id$/.test(property) && obj[property]['$in'] && obj[property]['$in'].length && obj[property]['$in'].length > 0){ + obj[property]['$in'].forEach((elem, val) => { + obj[property]['$in'][val] = new ObjectID(elem); + }) + }else{ + iterate(obj[property], stack + '.' + property); + } + } else if(/\._id$/.test(property)){ + obj[property] = new ObjectID(obj[property]); + } + } + } +}