1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\r
3 # Licensed under the Apache License, Version 2.0 (the "License"); #
\r
4 # you may not use this file except in compliance with the License. #
\r
5 # You may obtain a copy of the License at #
\r
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\r
9 # Unless required by applicable law or agreed to in writing, software #
\r
10 # distributed under the License is distributed on an "AS IS" BASIS, #
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
\r
12 # See the License for the specific language governing permissions and #
\r
13 # limitations under the License. #
\r
14 ##############################################################################*/
\r
17 module.exports = function (service) {
\r
18 return async context => {
\r
19 // If the method is find, get, or create, return
\r
20 if(context.method == 'find' || context.method == 'get' || context.method == 'create'){
\r
24 // If the id or service does not exist, return
\r
25 if(!context.id || !context.service){
\r
31 serviceString = context.app.get('base-path') + service;
\r
33 serviceString = context.path;
\r
36 if(!context.app.services[serviceString].Model){
\r
40 // If the entity data hasnt been set, get and set it
\r
41 if(!context.params.entityData){
\r
42 context.params.entityData = await context.app.services[serviceString].get(context.id, { provider: undefined});
\r
45 // Find the shard key from the model
\r
47 Object.keys(context.app.services[serviceString].Model.schema.options.shardKey).forEach(key => {
\r
48 shardKeys[key] = context.params.entityData[key];
\r
51 // Add the shard keys to the query
\r
52 Object.assign(context.params.query, shardKeys);
\r