a90922cea4cda48bd2c6f1cb88a873ec47bb3d35
[motion2.git] / server / api / trigger / trigger.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xb10b=['hasOwnProperty','getAnyConditions','findOne','addAction','TriggerId','Action','getActions','html-pdf','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','ejs','lodash','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','sendStatus','status','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','get','Triggers','UserProfileResource','error','stack','name','index','map','rawAttributes','fieldName','type','key','query','filters','intersection','model','attributes','fields','length','nolimit','order','sort','where','pick','merge','VIRTUAL','filter','includeAll','Trigger','findAll','catch','show','keys','filtears','include','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','addAllCondition','TriggerAllId','Condition','addAnyCondition','getAllConditions'];(function(_0x909afd,_0x4c5a74){var _0x5753f=function(_0x294963){while(--_0x294963){_0x909afd['push'](_0x909afd['shift']());}};_0x5753f(++_0x4c5a74);}(_0xb10b,0x12a));var _0xbb10=function(_0x260f28,_0x4e9b30){_0x260f28=_0x260f28-0x0;var _0x3aefcc=_0xb10b[_0x260f28];return _0x3aefcc;};'use strict';var pdf=require(_0xbb10('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xbb10('0x1'));var zipdir=require(_0xbb10('0x2'));var jsonpatch=require(_0xbb10('0x3'));var rp=require('request-promise');var moment=require(_0xbb10('0x4'));var BPromise=require(_0xbb10('0x5'));var Mustache=require(_0xbb10('0x6'));var util=require(_0xbb10('0x7'));var path=require(_0xbb10('0x8'));var sox=require(_0xbb10('0x9'));var csv=require('to-csv');var ejs=require(_0xbb10('0xa'));var fs=require('fs');var _=require(_0xbb10('0xb'));var squel=require('squel');var crypto=require(_0xbb10('0xc'));var jsforce=require(_0xbb10('0xd'));var deskjs=require(_0xbb10('0xe'));var toCsv=require(_0xbb10('0xf'));var querystring=require(_0xbb10('0x10'));var Papa=require(_0xbb10('0x11'));var Redis=require(_0xbb10('0x12'));var authService=require(_0xbb10('0x13'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xbb10('0x14'));var logger=require(_0xbb10('0x15'))(_0xbb10('0x16'));var utils=require('../../config/utils');var config=require(_0xbb10('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0xbb10('0x18'))['db'];function respondWithStatusCode(_0x916a32,_0x285009){_0x285009=_0x285009||0xcc;return function(_0x193a27){if(_0x193a27){return _0x916a32[_0xbb10('0x19')](_0x285009);}return _0x916a32[_0xbb10('0x1a')](_0x285009)['end']();};}function respondWithResult(_0x26e021,_0x42d7e4){_0x42d7e4=_0x42d7e4||0xc8;return function(_0x45b9d6){if(_0x45b9d6){return _0x26e021[_0xbb10('0x1a')](_0x42d7e4)[_0xbb10('0x1b')](_0x45b9d6);}};}function respondWithFilteredResult(_0x2f2ebf,_0x24a57b){return function(_0x36b5e8){if(_0x36b5e8){var _0x3e26f4=_0x36b5e8[_0xbb10('0x1c')],_0x2b184e=_0x24a57b[_0xbb10('0x1d')],_0x4a2bfc=_0x24a57b[_0xbb10('0x1d')]+_0x24a57b[_0xbb10('0x1e')],_0x2eca0f;if(_0x4a2bfc>=_0x3e26f4){_0x4a2bfc=_0x3e26f4;_0x2eca0f=0xc8;}else{_0x2eca0f=0xce;}_0x2f2ebf[_0xbb10('0x1a')](_0x2eca0f);return _0x2f2ebf[_0xbb10('0x1f')](_0xbb10('0x20'),_0x2b184e+'-'+_0x4a2bfc+'/'+_0x3e26f4)[_0xbb10('0x1b')](_0x36b5e8);}return null;};}function patchUpdates(_0xe1c665){return function(_0x48b6e9){try{jsonpatch[_0xbb10('0x21')](_0x48b6e9,_0xe1c665,!![]);}catch(_0x19f48d){return BPromise[_0xbb10('0x22')](_0x19f48d);}return _0x48b6e9[_0xbb10('0x23')]();};}function saveUpdates(_0xdf237d,_0x44e563){return function(_0x4deb49){if(_0x4deb49){return _0x4deb49[_0xbb10('0x24')](_0xdf237d)[_0xbb10('0x25')](function(_0x50aea1){return _0x50aea1;});}return null;};}function removeEntity(_0x4c4b0d,_0x8e2b97){return function(_0x311abe){if(_0x311abe){return _0x311abe[_0xbb10('0x26')]()[_0xbb10('0x25')](function(){var _0x445761=_0x311abe[_0xbb10('0x27')]({'plain':!![]});var _0x407cb4=_0xbb10('0x28');return db[_0xbb10('0x29')][_0xbb10('0x26')]({'where':{'type':_0x407cb4,'resourceId':_0x445761['id']}})[_0xbb10('0x25')](function(){return _0x311abe;});})[_0xbb10('0x25')](function(){_0x4c4b0d['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x4fb5e0,_0xc93a04){return function(_0x3c5ae7){if(!_0x3c5ae7){_0x4fb5e0[_0xbb10('0x19')](0x194);}return _0x3c5ae7;};}function handleError(_0x4e25ff,_0x2fdde9){_0x2fdde9=_0x2fdde9||0x1f4;return function(_0x24d586){logger[_0xbb10('0x2a')](_0x24d586[_0xbb10('0x2b')]);if(_0x24d586[_0xbb10('0x2c')]){delete _0x24d586[_0xbb10('0x2c')];}_0x4e25ff[_0xbb10('0x1a')](_0x2fdde9)['send'](_0x24d586);};}exports[_0xbb10('0x2d')]=function(_0x21ac54,_0xfc3595){var _0x2e0249={},_0x1d30aa={},_0x2ff4c1={'count':0x0,'rows':[]};var _0x5d5c80=_[_0xbb10('0x2e')](db['Trigger'][_0xbb10('0x2f')],function(_0x56f2da){return{'name':_0x56f2da[_0xbb10('0x30')],'type':_0x56f2da[_0xbb10('0x31')][_0xbb10('0x32')]};});_0x1d30aa['model']=_['map'](_0x5d5c80,_0xbb10('0x2c'));_0x1d30aa[_0xbb10('0x33')]=_['keys'](_0x21ac54[_0xbb10('0x33')]);_0x1d30aa[_0xbb10('0x34')]=_[_0xbb10('0x35')](_0x1d30aa[_0xbb10('0x36')],_0x1d30aa[_0xbb10('0x33')]);_0x2e0249[_0xbb10('0x37')]=_[_0xbb10('0x35')](_0x1d30aa['model'],qs[_0xbb10('0x38')](_0x21ac54[_0xbb10('0x33')][_0xbb10('0x38')]));_0x2e0249[_0xbb10('0x37')]=_0x2e0249[_0xbb10('0x37')][_0xbb10('0x39')]?_0x2e0249[_0xbb10('0x37')]:_0x1d30aa[_0xbb10('0x36')];if(!_0x21ac54[_0xbb10('0x33')]['hasOwnProperty'](_0xbb10('0x3a'))){_0x2e0249[_0xbb10('0x1e')]=qs[_0xbb10('0x1e')](_0x21ac54[_0xbb10('0x33')]['limit']);_0x2e0249[_0xbb10('0x1d')]=qs['offset'](_0x21ac54['query'][_0xbb10('0x1d')]);}_0x2e0249[_0xbb10('0x3b')]=qs[_0xbb10('0x3c')](_0x21ac54[_0xbb10('0x33')][_0xbb10('0x3c')]);_0x2e0249[_0xbb10('0x3d')]=qs['filters'](_[_0xbb10('0x3e')](_0x21ac54[_0xbb10('0x33')],_0x1d30aa['filters']),_0x5d5c80);if(_0x21ac54['query']['filter']){_0x2e0249[_0xbb10('0x3d')]=_[_0xbb10('0x3f')](_0x2e0249[_0xbb10('0x3d')],{'$or':_['map'](_0x5d5c80,function(_0x3c0cd7){if(_0x3c0cd7[_0xbb10('0x31')]!==_0xbb10('0x40')){var _0x4d1a83={};_0x4d1a83[_0x3c0cd7[_0xbb10('0x2c')]]={'$like':'%'+_0x21ac54[_0xbb10('0x33')][_0xbb10('0x41')]+'%'};return _0x4d1a83;}})});}_0x2e0249=_[_0xbb10('0x3f')]({},_0x2e0249,_0x21ac54['options']);var _0xd238e9={'where':_0x2e0249[_0xbb10('0x3d')]};return db['Trigger'][_0xbb10('0x1c')](_0xd238e9)[_0xbb10('0x25')](function(_0x44d6ae){_0x2ff4c1[_0xbb10('0x1c')]=_0x44d6ae;if(_0x21ac54[_0xbb10('0x33')][_0xbb10('0x42')]){_0x2e0249['include']=[{'all':!![]}];}return db[_0xbb10('0x43')][_0xbb10('0x44')](_0x2e0249);})[_0xbb10('0x25')](function(_0x3d3c41){_0x2ff4c1['rows']=_0x3d3c41;return _0x2ff4c1;})[_0xbb10('0x25')](respondWithFilteredResult(_0xfc3595,_0x2e0249))[_0xbb10('0x45')](handleError(_0xfc3595,null));};exports[_0xbb10('0x46')]=function(_0x403beb,_0x5e2cfa){var _0x351484={'raw':![],'where':{'id':_0x403beb['params']['id']}},_0x202c60={};_0x202c60['model']=_[_0xbb10('0x47')](db['Trigger'][_0xbb10('0x2f')]);_0x202c60[_0xbb10('0x33')]=_['keys'](_0x403beb[_0xbb10('0x33')]);_0x202c60[_0xbb10('0x48')]=_[_0xbb10('0x35')](_0x202c60['model'],_0x202c60[_0xbb10('0x33')]);_0x351484[_0xbb10('0x37')]=_[_0xbb10('0x35')](_0x202c60[_0xbb10('0x36')],qs[_0xbb10('0x38')](_0x403beb[_0xbb10('0x33')][_0xbb10('0x38')]));_0x351484[_0xbb10('0x37')]=_0x351484[_0xbb10('0x37')][_0xbb10('0x39')]?_0x351484[_0xbb10('0x37')]:_0x202c60[_0xbb10('0x36')];if(_0x403beb['query'][_0xbb10('0x42')]){_0x351484[_0xbb10('0x49')]=[{'all':!![]}];}_0x351484=_['merge']({},_0x351484,_0x403beb[_0xbb10('0x4a')]);return db[_0xbb10('0x43')][_0xbb10('0x4b')](_0x351484)[_0xbb10('0x25')](handleEntityNotFound(_0x5e2cfa,null))[_0xbb10('0x25')](respondWithResult(_0x5e2cfa,null))[_0xbb10('0x45')](handleError(_0x5e2cfa,null));};exports[_0xbb10('0x4c')]=function(_0x5be85e,_0x4a9793){return db[_0xbb10('0x43')][_0xbb10('0x4c')](_0x5be85e[_0xbb10('0x4d')],{})['then'](function(_0x5f0c12){var _0x3cd6f3=_0x5be85e[_0xbb10('0x4e')][_0xbb10('0x27')]({'plain':!![]});if(!_0x3cd6f3)throw new Error(_0xbb10('0x4f'));if(_0x3cd6f3[_0xbb10('0x50')]===_0xbb10('0x4e')){var _0x2f2552=_0x5f0c12[_0xbb10('0x27')]({'plain':!![]});var _0x2626d8=_0xbb10('0x28');return db['UserProfileSection']['find']({'where':{'name':_0x2626d8,'userProfileId':_0x3cd6f3[_0xbb10('0x51')]},'raw':!![]})[_0xbb10('0x25')](function(_0x36ab7d){if(_0x36ab7d&&_0x36ab7d[_0xbb10('0x52')]===0x0){return db[_0xbb10('0x29')][_0xbb10('0x4c')]({'name':_0x2f2552[_0xbb10('0x2c')],'resourceId':_0x2f2552['id'],'type':_0x36ab7d[_0xbb10('0x2c')],'sectionId':_0x36ab7d['id']},{})[_0xbb10('0x25')](function(){return _0x5f0c12;});}else{return _0x5f0c12;}})[_0xbb10('0x45')](function(_0x19ca3e){logger[_0xbb10('0x2a')](_0xbb10('0x53'),_0x19ca3e);throw _0x19ca3e;});}return _0x5f0c12;})[_0xbb10('0x25')](respondWithResult(_0x4a9793,0xc9))[_0xbb10('0x45')](handleError(_0x4a9793,null));};exports['update']=function(_0x124052,_0x5bd44d){if(_0x124052[_0xbb10('0x4d')]['id']){delete _0x124052[_0xbb10('0x4d')]['id'];}return db[_0xbb10('0x43')][_0xbb10('0x4b')]({'where':{'id':_0x124052[_0xbb10('0x54')]['id']}})[_0xbb10('0x25')](handleEntityNotFound(_0x5bd44d,null))[_0xbb10('0x25')](saveUpdates(_0x124052[_0xbb10('0x4d')],null))[_0xbb10('0x25')](respondWithResult(_0x5bd44d,null))[_0xbb10('0x45')](handleError(_0x5bd44d,null));};exports[_0xbb10('0x26')]=function(_0x1c2dce,_0x1d49e1){return db[_0xbb10('0x43')][_0xbb10('0x4b')]({'where':{'id':_0x1c2dce['params']['id']}})[_0xbb10('0x25')](handleEntityNotFound(_0x1d49e1,null))[_0xbb10('0x25')](removeEntity(_0x1d49e1,null))[_0xbb10('0x45')](handleError(_0x1d49e1,null));};exports[_0xbb10('0x55')]=function(_0xbffa3c,_0x379d8c,_0x4bedd0){if(_0xbffa3c[_0xbb10('0x4d')]['id']){delete _0xbffa3c[_0xbb10('0x4d')]['id'];}return db[_0xbb10('0x43')][_0xbb10('0x4b')]({'where':{'id':_0xbffa3c[_0xbb10('0x54')]['id']}})[_0xbb10('0x25')](handleEntityNotFound(_0x379d8c,null))[_0xbb10('0x25')](function(_0x12ec18){if(_0x12ec18){_0xbffa3c[_0xbb10('0x4d')][_0xbb10('0x56')]=_0x12ec18['id'];return db[_0xbb10('0x57')][_0xbb10('0x4c')](_0xbffa3c[_0xbb10('0x4d')]);}})['then'](respondWithResult(_0x379d8c,null))['catch'](handleError(_0x379d8c,null));};exports[_0xbb10('0x58')]=function(_0x3e6338,_0x3d0cb7,_0x8b0a7d){if(_0x3e6338['body']['id']){delete _0x3e6338['body']['id'];}return db[_0xbb10('0x43')][_0xbb10('0x4b')]({'where':{'id':_0x3e6338[_0xbb10('0x54')]['id']}})[_0xbb10('0x25')](handleEntityNotFound(_0x3d0cb7,null))[_0xbb10('0x25')](function(_0x3e9753){if(_0x3e9753){_0x3e6338[_0xbb10('0x4d')]['TriggerAnyId']=_0x3e9753['id'];return db[_0xbb10('0x57')][_0xbb10('0x4c')](_0x3e6338['body']);}})['then'](respondWithResult(_0x3d0cb7,null))['catch'](handleError(_0x3d0cb7,null));};exports[_0xbb10('0x59')]=function(_0x31c727,_0x155dc5,_0x5bd1c0){var _0x4e6e7c={};var _0x5846d1={};var _0x3ebc5f;var _0x249b33;return db[_0xbb10('0x43')]['findOne']({'where':{'id':_0x31c727[_0xbb10('0x54')]['id']}})[_0xbb10('0x25')](handleEntityNotFound(_0x155dc5,null))['then'](function(_0x4a560c){if(_0x4a560c){_0x3ebc5f=_0x4a560c;_0x5846d1[_0xbb10('0x36')]=_[_0xbb10('0x47')](db[_0xbb10('0x57')][_0xbb10('0x2f')]);_0x5846d1['query']=_[_0xbb10('0x47')](_0x31c727[_0xbb10('0x33')]);_0x5846d1[_0xbb10('0x34')]=_['intersection'](_0x5846d1[_0xbb10('0x36')],_0x5846d1[_0xbb10('0x33')]);_0x4e6e7c[_0xbb10('0x37')]=_['intersection'](_0x5846d1[_0xbb10('0x36')],qs[_0xbb10('0x38')](_0x31c727[_0xbb10('0x33')][_0xbb10('0x38')]));_0x4e6e7c['attributes']=_0x4e6e7c[_0xbb10('0x37')][_0xbb10('0x39')]?_0x4e6e7c[_0xbb10('0x37')]:_0x5846d1[_0xbb10('0x36')];_0x4e6e7c['order']=qs[_0xbb10('0x3c')](_0x31c727[_0xbb10('0x33')][_0xbb10('0x3c')]);_0x4e6e7c[_0xbb10('0x3d')]=qs[_0xbb10('0x34')](_[_0xbb10('0x3e')](_0x31c727[_0xbb10('0x33')],_0x5846d1['filters']));if(_0x31c727['query']['filter']){_0x4e6e7c[_0xbb10('0x3d')]=_[_0xbb10('0x3f')](_0x4e6e7c[_0xbb10('0x3d')],{'$or':_['map'](_0x4e6e7c['attributes'],function(_0x46f462){var _0x1b11c0={};_0x1b11c0[_0x46f462]={'$like':'%'+_0x31c727[_0xbb10('0x33')][_0xbb10('0x41')]+'%'};return _0x1b11c0;})});}_0x4e6e7c=_[_0xbb10('0x3f')]({},_0x4e6e7c,_0x31c727[_0xbb10('0x4a')]);return _0x3ebc5f['getAllConditions'](_0x4e6e7c);}})[_0xbb10('0x25')](function(_0x15fae2){if(_0x15fae2){_0x249b33=_0x15fae2[_0xbb10('0x39')];if(!_0x31c727[_0xbb10('0x33')][_0xbb10('0x5a')]('nolimit')){_0x4e6e7c['limit']=qs['limit'](_0x31c727[_0xbb10('0x33')][_0xbb10('0x1e')]);_0x4e6e7c[_0xbb10('0x1d')]=qs[_0xbb10('0x1d')](_0x31c727[_0xbb10('0x33')][_0xbb10('0x1d')]);}return _0x3ebc5f['getAllConditions'](_0x4e6e7c);}})[_0xbb10('0x25')](function(_0x4bc316){if(_0x4bc316){return _0x4bc316?{'count':_0x249b33,'rows':_0x4bc316}:null;}})['then'](respondWithResult(_0x155dc5,null))['catch'](handleError(_0x155dc5,null));};exports[_0xbb10('0x5b')]=function(_0x13040d,_0x23b1d5,_0x108f99){var _0x5ce94f={};var _0x122d38={};var _0x5c583b;var _0x576179;return db[_0xbb10('0x43')][_0xbb10('0x5c')]({'where':{'id':_0x13040d[_0xbb10('0x54')]['id']}})[_0xbb10('0x25')](handleEntityNotFound(_0x23b1d5,null))[_0xbb10('0x25')](function(_0x4fccc5){if(_0x4fccc5){_0x5c583b=_0x4fccc5;_0x122d38[_0xbb10('0x36')]=_[_0xbb10('0x47')](db[_0xbb10('0x57')][_0xbb10('0x2f')]);_0x122d38[_0xbb10('0x33')]=_[_0xbb10('0x47')](_0x13040d[_0xbb10('0x33')]);_0x122d38['filters']=_[_0xbb10('0x35')](_0x122d38[_0xbb10('0x36')],_0x122d38[_0xbb10('0x33')]);_0x5ce94f[_0xbb10('0x37')]=_[_0xbb10('0x35')](_0x122d38[_0xbb10('0x36')],qs[_0xbb10('0x38')](_0x13040d[_0xbb10('0x33')]['fields']));_0x5ce94f[_0xbb10('0x37')]=_0x5ce94f[_0xbb10('0x37')][_0xbb10('0x39')]?_0x5ce94f['attributes']:_0x122d38['model'];_0x5ce94f['order']=qs[_0xbb10('0x3c')](_0x13040d['query']['sort']);_0x5ce94f[_0xbb10('0x3d')]=qs[_0xbb10('0x34')](_[_0xbb10('0x3e')](_0x13040d[_0xbb10('0x33')],_0x122d38[_0xbb10('0x34')]));if(_0x13040d[_0xbb10('0x33')][_0xbb10('0x41')]){_0x5ce94f[_0xbb10('0x3d')]=_[_0xbb10('0x3f')](_0x5ce94f['where'],{'$or':_[_0xbb10('0x2e')](_0x5ce94f[_0xbb10('0x37')],function(_0x46b6d2){var _0x35b811={};_0x35b811[_0x46b6d2]={'$like':'%'+_0x13040d['query']['filter']+'%'};return _0x35b811;})});}_0x5ce94f=_[_0xbb10('0x3f')]({},_0x5ce94f,_0x13040d[_0xbb10('0x4a')]);return _0x5c583b[_0xbb10('0x5b')](_0x5ce94f);}})[_0xbb10('0x25')](function(_0x5ee705){if(_0x5ee705){_0x576179=_0x5ee705[_0xbb10('0x39')];if(!_0x13040d[_0xbb10('0x33')][_0xbb10('0x5a')](_0xbb10('0x3a'))){_0x5ce94f[_0xbb10('0x1e')]=qs['limit'](_0x13040d['query'][_0xbb10('0x1e')]);_0x5ce94f[_0xbb10('0x1d')]=qs[_0xbb10('0x1d')](_0x13040d['query'][_0xbb10('0x1d')]);}return _0x5c583b[_0xbb10('0x5b')](_0x5ce94f);}})['then'](function(_0x5caa06){if(_0x5caa06){return _0x5caa06?{'count':_0x576179,'rows':_0x5caa06}:null;}})[_0xbb10('0x25')](respondWithResult(_0x23b1d5,null))[_0xbb10('0x45')](handleError(_0x23b1d5,null));};exports[_0xbb10('0x5d')]=function(_0x4d64ff,_0x32d5a5,_0x3a17fc){if(_0x4d64ff[_0xbb10('0x4d')]['id']){delete _0x4d64ff[_0xbb10('0x4d')]['id'];}return db[_0xbb10('0x43')][_0xbb10('0x4b')]({'where':{'id':_0x4d64ff[_0xbb10('0x54')]['id']}})[_0xbb10('0x25')](handleEntityNotFound(_0x32d5a5,null))[_0xbb10('0x25')](function(_0x479d51){if(_0x479d51){_0x4d64ff[_0xbb10('0x4d')][_0xbb10('0x5e')]=_0x479d51['id'];return db[_0xbb10('0x5f')][_0xbb10('0x4c')](_0x4d64ff[_0xbb10('0x4d')]);}})[_0xbb10('0x25')](respondWithResult(_0x32d5a5,null))[_0xbb10('0x45')](handleError(_0x32d5a5,null));};exports[_0xbb10('0x60')]=function(_0x17ed20,_0x1a5538,_0x15e043){var _0x2a4278={};var _0x59e985={};var _0x51f106;var _0xe1fc51;return db[_0xbb10('0x43')][_0xbb10('0x5c')]({'where':{'id':_0x17ed20[_0xbb10('0x54')]['id']}})[_0xbb10('0x25')](handleEntityNotFound(_0x1a5538,null))['then'](function(_0x2749a7){if(_0x2749a7){_0x51f106=_0x2749a7;_0x59e985[_0xbb10('0x36')]=_[_0xbb10('0x47')](db[_0xbb10('0x5f')][_0xbb10('0x2f')]);_0x59e985[_0xbb10('0x33')]=_['keys'](_0x17ed20[_0xbb10('0x33')]);_0x59e985[_0xbb10('0x34')]=_['intersection'](_0x59e985[_0xbb10('0x36')],_0x59e985['query']);_0x2a4278[_0xbb10('0x37')]=_[_0xbb10('0x35')](_0x59e985[_0xbb10('0x36')],qs[_0xbb10('0x38')](_0x17ed20[_0xbb10('0x33')]['fields']));_0x2a4278[_0xbb10('0x37')]=_0x2a4278['attributes'][_0xbb10('0x39')]?_0x2a4278[_0xbb10('0x37')]:_0x59e985['model'];_0x2a4278['order']=qs[_0xbb10('0x3c')](_0x17ed20[_0xbb10('0x33')][_0xbb10('0x3c')]);_0x2a4278[_0xbb10('0x3d')]=qs[_0xbb10('0x34')](_[_0xbb10('0x3e')](_0x17ed20[_0xbb10('0x33')],_0x59e985[_0xbb10('0x34')]));if(_0x17ed20[_0xbb10('0x33')][_0xbb10('0x41')]){_0x2a4278[_0xbb10('0x3d')]=_['merge'](_0x2a4278[_0xbb10('0x3d')],{'$or':_[_0xbb10('0x2e')](_0x2a4278[_0xbb10('0x37')],function(_0xcd5d35){var _0xfe02f5={};_0xfe02f5[_0xcd5d35]={'$like':'%'+_0x17ed20[_0xbb10('0x33')][_0xbb10('0x41')]+'%'};return _0xfe02f5;})});}_0x2a4278=_[_0xbb10('0x3f')]({},_0x2a4278,_0x17ed20[_0xbb10('0x4a')]);return _0x51f106[_0xbb10('0x60')](_0x2a4278);}})[_0xbb10('0x25')](function(_0x2d3e98){if(_0x2d3e98){_0xe1fc51=_0x2d3e98['length'];if(!_0x17ed20[_0xbb10('0x33')]['hasOwnProperty'](_0xbb10('0x3a'))){_0x2a4278[_0xbb10('0x1e')]=qs[_0xbb10('0x1e')](_0x17ed20[_0xbb10('0x33')][_0xbb10('0x1e')]);_0x2a4278['offset']=qs[_0xbb10('0x1d')](_0x17ed20[_0xbb10('0x33')][_0xbb10('0x1d')]);}return _0x51f106[_0xbb10('0x60')](_0x2a4278);}})[_0xbb10('0x25')](function(_0x41380b){if(_0x41380b){return _0x41380b?{'count':_0xe1fc51,'rows':_0x41380b}:null;}})['then'](respondWithResult(_0x1a5538,null))['catch'](handleError(_0x1a5538,null));};