Built motion from commit 9d0783e6.|2.6.13
[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 _0xff01=['rimraf','fast-json-patch','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','offset','undefined','count','limit','set','Content-Range','json','apply','reject','save','destroy','then','get','Triggers','sendStatus','error','stack','name','send','map','Trigger','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','rawAttributes','find','create','body','user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','addAllCondition','TriggerAllId','Condition','addAnyCondition','getAllConditions','filter','pick','getAnyConditions','TriggerId','Action','getActions','findOne'];(function(_0x3a3964,_0x438f17){var _0x2bd0e9=function(_0x376afa){while(--_0x376afa){_0x3a3964['push'](_0x3a3964['shift']());}};_0x2bd0e9(++_0x438f17);}(_0xff01,0x1e5));var _0x1ff0=function(_0x256d38,_0x4a9eb2){_0x256d38=_0x256d38-0x0;var _0x1603eb=_0xff01[_0x256d38];return _0x1603eb;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x1ff0('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x1ff0('0x1'));var rp=require('request-promise');var moment=require(_0x1ff0('0x2'));var BPromise=require(_0x1ff0('0x3'));var Mustache=require('mustache');var util=require(_0x1ff0('0x4'));var path=require(_0x1ff0('0x5'));var sox=require(_0x1ff0('0x6'));var csv=require(_0x1ff0('0x7'));var ejs=require(_0x1ff0('0x8'));var fs=require('fs');var fs_extra=require(_0x1ff0('0x9'));var _=require(_0x1ff0('0xa'));var squel=require(_0x1ff0('0xb'));var crypto=require(_0x1ff0('0xc'));var jsforce=require(_0x1ff0('0xd'));var deskjs=require(_0x1ff0('0xe'));var toCsv=require(_0x1ff0('0x7'));var querystring=require(_0x1ff0('0xf'));var Papa=require(_0x1ff0('0x10'));var Redis=require(_0x1ff0('0x11'));var authService=require('../../components/auth/service');var qs=require(_0x1ff0('0x12'));var as=require(_0x1ff0('0x13'));var hardwareService=require(_0x1ff0('0x14'));var logger=require('../../config/logger')(_0x1ff0('0x15'));var utils=require(_0x1ff0('0x16'));var config=require(_0x1ff0('0x17'));var licenseUtil=require(_0x1ff0('0x18'));var db=require(_0x1ff0('0x19'))['db'];function respondWithStatusCode(_0x2f60a8,_0x3f5ccf){_0x3f5ccf=_0x3f5ccf||0xcc;return function(_0x2653f8){if(_0x2653f8){return _0x2f60a8['sendStatus'](_0x3f5ccf);}return _0x2f60a8[_0x1ff0('0x1a')](_0x3f5ccf)[_0x1ff0('0x1b')]();};}function respondWithResult(_0x252e0b,_0x34f067){_0x34f067=_0x34f067||0xc8;return function(_0x5ad3a8){if(_0x5ad3a8){return _0x252e0b[_0x1ff0('0x1a')](_0x34f067)['json'](_0x5ad3a8);}};}function respondWithFilteredResult(_0x5479d6,_0x46eea2){return function(_0xb4388c){if(_0xb4388c){var _0x16ed78=typeof _0x46eea2[_0x1ff0('0x1c')]===_0x1ff0('0x1d')&&typeof _0x46eea2['limit']==='undefined';var _0x17bd42=_0xb4388c[_0x1ff0('0x1e')];var _0x4facb1=_0x16ed78?0x0:_0x46eea2['offset'];var _0x38cbd8=_0x16ed78?_0xb4388c[_0x1ff0('0x1e')]:_0x46eea2['offset']+_0x46eea2[_0x1ff0('0x1f')];var _0x53ef9b;if(_0x38cbd8>=_0x17bd42){_0x38cbd8=_0x17bd42;_0x53ef9b=0xc8;}else{_0x53ef9b=0xce;}_0x5479d6[_0x1ff0('0x1a')](_0x53ef9b);return _0x5479d6[_0x1ff0('0x20')](_0x1ff0('0x21'),_0x4facb1+'-'+_0x38cbd8+'/'+_0x17bd42)[_0x1ff0('0x22')](_0xb4388c);}return null;};}function patchUpdates(_0x55ced9){return function(_0x14c1d4){try{jsonpatch[_0x1ff0('0x23')](_0x14c1d4,_0x55ced9,!![]);}catch(_0x563ddc){return BPromise[_0x1ff0('0x24')](_0x563ddc);}return _0x14c1d4[_0x1ff0('0x25')]();};}function saveUpdates(_0x56748d,_0x412c1a){return function(_0x152e3f){if(_0x152e3f){return _0x152e3f['update'](_0x56748d)['then'](function(_0x3ce77d){return _0x3ce77d;});}return null;};}function removeEntity(_0xc34542,_0x514502){return function(_0x558705){if(_0x558705){return _0x558705[_0x1ff0('0x26')]()[_0x1ff0('0x27')](function(){var _0x40600c=_0x558705[_0x1ff0('0x28')]({'plain':!![]});var _0x3c4b78=_0x1ff0('0x29');return db['UserProfileResource'][_0x1ff0('0x26')]({'where':{'type':_0x3c4b78,'resourceId':_0x40600c['id']}})['then'](function(){return _0x558705;});})[_0x1ff0('0x27')](function(){_0xc34542[_0x1ff0('0x1a')](0xcc)[_0x1ff0('0x1b')]();});}};}function handleEntityNotFound(_0x46f1b8,_0x1978e8){return function(_0x3dcdf3){if(!_0x3dcdf3){_0x46f1b8[_0x1ff0('0x2a')](0x194);}return _0x3dcdf3;};}function handleError(_0x34406d,_0x58878a){_0x58878a=_0x58878a||0x1f4;return function(_0x36156a){logger[_0x1ff0('0x2b')](_0x36156a[_0x1ff0('0x2c')]);if(_0x36156a['name']){delete _0x36156a[_0x1ff0('0x2d')];}_0x34406d['status'](_0x58878a)[_0x1ff0('0x2e')](_0x36156a);};}exports['index']=function(_0x155f2f,_0x24c63b){var _0x36d618={},_0x534604={},_0x268240={'count':0x0,'rows':[]};var _0x1bd560=_[_0x1ff0('0x2f')](db[_0x1ff0('0x30')]['rawAttributes'],function(_0x25880d){return{'name':_0x25880d[_0x1ff0('0x31')],'type':_0x25880d[_0x1ff0('0x32')][_0x1ff0('0x33')]};});_0x534604[_0x1ff0('0x34')]=_['map'](_0x1bd560,_0x1ff0('0x2d'));_0x534604[_0x1ff0('0x35')]=_[_0x1ff0('0x36')](_0x155f2f['query']);_0x534604[_0x1ff0('0x37')]=_['intersection'](_0x534604[_0x1ff0('0x34')],_0x534604['query']);_0x36d618['attributes']=_[_0x1ff0('0x38')](_0x534604['model'],qs[_0x1ff0('0x39')](_0x155f2f[_0x1ff0('0x35')][_0x1ff0('0x39')]));_0x36d618[_0x1ff0('0x3a')]=_0x36d618['attributes'][_0x1ff0('0x3b')]?_0x36d618[_0x1ff0('0x3a')]:_0x534604['model'];if(!_0x155f2f[_0x1ff0('0x35')][_0x1ff0('0x3c')](_0x1ff0('0x3d'))){_0x36d618['limit']=qs[_0x1ff0('0x1f')](_0x155f2f[_0x1ff0('0x35')][_0x1ff0('0x1f')]);_0x36d618[_0x1ff0('0x1c')]=qs[_0x1ff0('0x1c')](_0x155f2f[_0x1ff0('0x35')]['offset']);}_0x36d618[_0x1ff0('0x3e')]=qs[_0x1ff0('0x3f')](_0x155f2f[_0x1ff0('0x35')][_0x1ff0('0x3f')]);_0x36d618[_0x1ff0('0x40')]=qs[_0x1ff0('0x37')](_['pick'](_0x155f2f[_0x1ff0('0x35')],_0x534604[_0x1ff0('0x37')]),_0x1bd560);if(_0x155f2f[_0x1ff0('0x35')]['filter']){_0x36d618[_0x1ff0('0x40')]=_[_0x1ff0('0x41')](_0x36d618['where'],{'$or':_['map'](_0x1bd560,function(_0x2ddb8d){if(_0x2ddb8d['type']!==_0x1ff0('0x42')){var _0x29d834={};_0x29d834[_0x2ddb8d[_0x1ff0('0x2d')]]={'$like':'%'+_0x155f2f[_0x1ff0('0x35')]['filter']+'%'};return _0x29d834;}})});}_0x36d618=_[_0x1ff0('0x41')]({},_0x36d618,_0x155f2f[_0x1ff0('0x43')]);var _0x44cae4={'where':_0x36d618[_0x1ff0('0x40')]};return db['Trigger']['count'](_0x44cae4)['then'](function(_0x5912ae){_0x268240['count']=_0x5912ae;if(_0x155f2f[_0x1ff0('0x35')][_0x1ff0('0x44')]){_0x36d618[_0x1ff0('0x45')]=[{'all':!![]}];}return db['Trigger'][_0x1ff0('0x46')](_0x36d618);})[_0x1ff0('0x27')](function(_0x1200f0){_0x268240[_0x1ff0('0x47')]=_0x1200f0;return _0x268240;})[_0x1ff0('0x27')](respondWithFilteredResult(_0x24c63b,_0x36d618))[_0x1ff0('0x48')](handleError(_0x24c63b,null));};exports[_0x1ff0('0x49')]=function(_0x4f3ac2,_0x5e5df0){var _0x400e91={'raw':![],'where':{'id':_0x4f3ac2[_0x1ff0('0x4a')]['id']}},_0xc7c4b8={};_0xc7c4b8[_0x1ff0('0x34')]=_['keys'](db['Trigger'][_0x1ff0('0x4b')]);_0xc7c4b8[_0x1ff0('0x35')]=_[_0x1ff0('0x36')](_0x4f3ac2['query']);_0xc7c4b8[_0x1ff0('0x37')]=_[_0x1ff0('0x38')](_0xc7c4b8[_0x1ff0('0x34')],_0xc7c4b8[_0x1ff0('0x35')]);_0x400e91[_0x1ff0('0x3a')]=_[_0x1ff0('0x38')](_0xc7c4b8[_0x1ff0('0x34')],qs['fields'](_0x4f3ac2[_0x1ff0('0x35')]['fields']));_0x400e91[_0x1ff0('0x3a')]=_0x400e91['attributes'][_0x1ff0('0x3b')]?_0x400e91['attributes']:_0xc7c4b8[_0x1ff0('0x34')];if(_0x4f3ac2[_0x1ff0('0x35')][_0x1ff0('0x44')]){_0x400e91[_0x1ff0('0x45')]=[{'all':!![]}];}_0x400e91=_[_0x1ff0('0x41')]({},_0x400e91,_0x4f3ac2[_0x1ff0('0x43')]);return db[_0x1ff0('0x30')][_0x1ff0('0x4c')](_0x400e91)[_0x1ff0('0x27')](handleEntityNotFound(_0x5e5df0,null))[_0x1ff0('0x27')](respondWithResult(_0x5e5df0,null))[_0x1ff0('0x48')](handleError(_0x5e5df0,null));};exports[_0x1ff0('0x4d')]=function(_0x4d88e5,_0x5cc718){return db[_0x1ff0('0x30')][_0x1ff0('0x4d')](_0x4d88e5[_0x1ff0('0x4e')],{})[_0x1ff0('0x27')](function(_0x332f3b){var _0x161fa2=_0x4d88e5[_0x1ff0('0x4f')][_0x1ff0('0x28')]({'plain':!![]});if(!_0x161fa2)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x161fa2['role']===_0x1ff0('0x4f')){var _0x11bf7b=_0x332f3b['get']({'plain':!![]});var _0x12d40b=_0x1ff0('0x29');return db[_0x1ff0('0x50')]['find']({'where':{'name':_0x12d40b,'userProfileId':_0x161fa2[_0x1ff0('0x51')]},'raw':!![]})['then'](function(_0x9206a8){if(_0x9206a8&&_0x9206a8[_0x1ff0('0x52')]===0x0){return db['UserProfileResource']['create']({'name':_0x11bf7b[_0x1ff0('0x2d')],'resourceId':_0x11bf7b['id'],'type':_0x9206a8[_0x1ff0('0x2d')],'sectionId':_0x9206a8['id']},{})[_0x1ff0('0x27')](function(){return _0x332f3b;});}else{return _0x332f3b;}})[_0x1ff0('0x48')](function(_0x4a3386){logger[_0x1ff0('0x2b')](_0x1ff0('0x53'),_0x4a3386);throw _0x4a3386;});}return _0x332f3b;})[_0x1ff0('0x27')](respondWithResult(_0x5cc718,0xc9))[_0x1ff0('0x48')](handleError(_0x5cc718,null));};exports[_0x1ff0('0x54')]=function(_0x5546c4,_0x251794){if(_0x5546c4[_0x1ff0('0x4e')]['id']){delete _0x5546c4[_0x1ff0('0x4e')]['id'];}return db[_0x1ff0('0x30')][_0x1ff0('0x4c')]({'where':{'id':_0x5546c4[_0x1ff0('0x4a')]['id']}})[_0x1ff0('0x27')](handleEntityNotFound(_0x251794,null))[_0x1ff0('0x27')](saveUpdates(_0x5546c4[_0x1ff0('0x4e')],null))['then'](respondWithResult(_0x251794,null))[_0x1ff0('0x48')](handleError(_0x251794,null));};exports[_0x1ff0('0x26')]=function(_0x27a319,_0x333fd6){return db[_0x1ff0('0x30')][_0x1ff0('0x4c')]({'where':{'id':_0x27a319[_0x1ff0('0x4a')]['id']}})[_0x1ff0('0x27')](handleEntityNotFound(_0x333fd6,null))[_0x1ff0('0x27')](removeEntity(_0x333fd6,null))['catch'](handleError(_0x333fd6,null));};exports[_0x1ff0('0x55')]=function(_0x6e97ff,_0x2a9eba,_0x363fb9){if(_0x6e97ff[_0x1ff0('0x4e')]['id']){delete _0x6e97ff[_0x1ff0('0x4e')]['id'];}return db[_0x1ff0('0x30')][_0x1ff0('0x4c')]({'where':{'id':_0x6e97ff[_0x1ff0('0x4a')]['id']}})[_0x1ff0('0x27')](handleEntityNotFound(_0x2a9eba,null))[_0x1ff0('0x27')](function(_0xc3d2da){if(_0xc3d2da){_0x6e97ff['body'][_0x1ff0('0x56')]=_0xc3d2da['id'];return db[_0x1ff0('0x57')][_0x1ff0('0x4d')](_0x6e97ff[_0x1ff0('0x4e')]);}})[_0x1ff0('0x27')](respondWithResult(_0x2a9eba,null))['catch'](handleError(_0x2a9eba,null));};exports[_0x1ff0('0x58')]=function(_0x44da07,_0x2e84b1,_0x596933){if(_0x44da07[_0x1ff0('0x4e')]['id']){delete _0x44da07['body']['id'];}return db[_0x1ff0('0x30')][_0x1ff0('0x4c')]({'where':{'id':_0x44da07[_0x1ff0('0x4a')]['id']}})['then'](handleEntityNotFound(_0x2e84b1,null))['then'](function(_0x472319){if(_0x472319){_0x44da07['body']['TriggerAnyId']=_0x472319['id'];return db[_0x1ff0('0x57')][_0x1ff0('0x4d')](_0x44da07[_0x1ff0('0x4e')]);}})['then'](respondWithResult(_0x2e84b1,null))[_0x1ff0('0x48')](handleError(_0x2e84b1,null));};exports[_0x1ff0('0x59')]=function(_0x198a9e,_0x3860d2,_0x275971){var _0x1109f6={};var _0x26a577={};var _0x2eee0b;var _0x4997cf;return db[_0x1ff0('0x30')]['findOne']({'where':{'id':_0x198a9e[_0x1ff0('0x4a')]['id']}})[_0x1ff0('0x27')](handleEntityNotFound(_0x3860d2,null))[_0x1ff0('0x27')](function(_0x381fa4){if(_0x381fa4){_0x2eee0b=_0x381fa4;_0x26a577[_0x1ff0('0x34')]=_[_0x1ff0('0x36')](db[_0x1ff0('0x57')][_0x1ff0('0x4b')]);_0x26a577[_0x1ff0('0x35')]=_['keys'](_0x198a9e[_0x1ff0('0x35')]);_0x26a577[_0x1ff0('0x37')]=_[_0x1ff0('0x38')](_0x26a577[_0x1ff0('0x34')],_0x26a577['query']);_0x1109f6[_0x1ff0('0x3a')]=_[_0x1ff0('0x38')](_0x26a577[_0x1ff0('0x34')],qs[_0x1ff0('0x39')](_0x198a9e[_0x1ff0('0x35')][_0x1ff0('0x39')]));_0x1109f6[_0x1ff0('0x3a')]=_0x1109f6[_0x1ff0('0x3a')][_0x1ff0('0x3b')]?_0x1109f6[_0x1ff0('0x3a')]:_0x26a577[_0x1ff0('0x34')];_0x1109f6[_0x1ff0('0x3e')]=qs[_0x1ff0('0x3f')](_0x198a9e[_0x1ff0('0x35')][_0x1ff0('0x3f')]);_0x1109f6[_0x1ff0('0x40')]=qs['filters'](_['pick'](_0x198a9e['query'],_0x26a577['filters']));if(_0x198a9e[_0x1ff0('0x35')][_0x1ff0('0x5a')]){_0x1109f6[_0x1ff0('0x40')]=_['merge'](_0x1109f6[_0x1ff0('0x40')],{'$or':_['map'](_0x1109f6['attributes'],function(_0x3bd819){var _0x7f7997={};_0x7f7997[_0x3bd819]={'$like':'%'+_0x198a9e[_0x1ff0('0x35')][_0x1ff0('0x5a')]+'%'};return _0x7f7997;})});}_0x1109f6=_[_0x1ff0('0x41')]({},_0x1109f6,_0x198a9e['options']);return _0x2eee0b[_0x1ff0('0x59')](_0x1109f6);}})[_0x1ff0('0x27')](function(_0x2edceb){if(_0x2edceb){_0x4997cf=_0x2edceb[_0x1ff0('0x3b')];if(!_0x198a9e['query'][_0x1ff0('0x3c')]('nolimit')){_0x1109f6[_0x1ff0('0x1f')]=qs['limit'](_0x198a9e[_0x1ff0('0x35')][_0x1ff0('0x1f')]);_0x1109f6[_0x1ff0('0x1c')]=qs[_0x1ff0('0x1c')](_0x198a9e[_0x1ff0('0x35')][_0x1ff0('0x1c')]);}return _0x2eee0b[_0x1ff0('0x59')](_0x1109f6);}})[_0x1ff0('0x27')](function(_0x196d8d){if(_0x196d8d){return _0x196d8d?{'count':_0x4997cf,'rows':_0x196d8d}:null;}})[_0x1ff0('0x27')](respondWithResult(_0x3860d2,null))['catch'](handleError(_0x3860d2,null));};exports['getAnyConditions']=function(_0x5dae47,_0x3f9915,_0x723b0){var _0x7ba586={};var _0xcb18ee={};var _0x2db221;var _0x522195;return db[_0x1ff0('0x30')]['findOne']({'where':{'id':_0x5dae47[_0x1ff0('0x4a')]['id']}})[_0x1ff0('0x27')](handleEntityNotFound(_0x3f9915,null))[_0x1ff0('0x27')](function(_0x5200bf){if(_0x5200bf){_0x2db221=_0x5200bf;_0xcb18ee[_0x1ff0('0x34')]=_[_0x1ff0('0x36')](db['Condition'][_0x1ff0('0x4b')]);_0xcb18ee['query']=_[_0x1ff0('0x36')](_0x5dae47[_0x1ff0('0x35')]);_0xcb18ee[_0x1ff0('0x37')]=_[_0x1ff0('0x38')](_0xcb18ee['model'],_0xcb18ee[_0x1ff0('0x35')]);_0x7ba586[_0x1ff0('0x3a')]=_[_0x1ff0('0x38')](_0xcb18ee[_0x1ff0('0x34')],qs[_0x1ff0('0x39')](_0x5dae47[_0x1ff0('0x35')][_0x1ff0('0x39')]));_0x7ba586[_0x1ff0('0x3a')]=_0x7ba586['attributes'][_0x1ff0('0x3b')]?_0x7ba586['attributes']:_0xcb18ee[_0x1ff0('0x34')];_0x7ba586[_0x1ff0('0x3e')]=qs[_0x1ff0('0x3f')](_0x5dae47[_0x1ff0('0x35')][_0x1ff0('0x3f')]);_0x7ba586[_0x1ff0('0x40')]=qs[_0x1ff0('0x37')](_[_0x1ff0('0x5b')](_0x5dae47[_0x1ff0('0x35')],_0xcb18ee[_0x1ff0('0x37')]));if(_0x5dae47[_0x1ff0('0x35')][_0x1ff0('0x5a')]){_0x7ba586[_0x1ff0('0x40')]=_['merge'](_0x7ba586[_0x1ff0('0x40')],{'$or':_['map'](_0x7ba586[_0x1ff0('0x3a')],function(_0x5675e0){var _0x14dd42={};_0x14dd42[_0x5675e0]={'$like':'%'+_0x5dae47[_0x1ff0('0x35')][_0x1ff0('0x5a')]+'%'};return _0x14dd42;})});}_0x7ba586=_[_0x1ff0('0x41')]({},_0x7ba586,_0x5dae47[_0x1ff0('0x43')]);return _0x2db221[_0x1ff0('0x5c')](_0x7ba586);}})[_0x1ff0('0x27')](function(_0x5c6357){if(_0x5c6357){_0x522195=_0x5c6357[_0x1ff0('0x3b')];if(!_0x5dae47['query'][_0x1ff0('0x3c')](_0x1ff0('0x3d'))){_0x7ba586[_0x1ff0('0x1f')]=qs[_0x1ff0('0x1f')](_0x5dae47[_0x1ff0('0x35')]['limit']);_0x7ba586[_0x1ff0('0x1c')]=qs[_0x1ff0('0x1c')](_0x5dae47[_0x1ff0('0x35')][_0x1ff0('0x1c')]);}return _0x2db221[_0x1ff0('0x5c')](_0x7ba586);}})[_0x1ff0('0x27')](function(_0xe48f07){if(_0xe48f07){return _0xe48f07?{'count':_0x522195,'rows':_0xe48f07}:null;}})[_0x1ff0('0x27')](respondWithResult(_0x3f9915,null))[_0x1ff0('0x48')](handleError(_0x3f9915,null));};exports['addAction']=function(_0x38deb4,_0x12ed84,_0x119460){if(_0x38deb4[_0x1ff0('0x4e')]['id']){delete _0x38deb4['body']['id'];}return db[_0x1ff0('0x30')][_0x1ff0('0x4c')]({'where':{'id':_0x38deb4[_0x1ff0('0x4a')]['id']}})[_0x1ff0('0x27')](handleEntityNotFound(_0x12ed84,null))[_0x1ff0('0x27')](function(_0x217835){if(_0x217835){_0x38deb4['body'][_0x1ff0('0x5d')]=_0x217835['id'];return db[_0x1ff0('0x5e')][_0x1ff0('0x4d')](_0x38deb4['body']);}})[_0x1ff0('0x27')](respondWithResult(_0x12ed84,null))[_0x1ff0('0x48')](handleError(_0x12ed84,null));};exports[_0x1ff0('0x5f')]=function(_0x191068,_0x16fff9,_0x58be10){var _0x35c5df={};var _0x1d6f06={};var _0x8e320c;var _0x16ab85;return db[_0x1ff0('0x30')][_0x1ff0('0x60')]({'where':{'id':_0x191068[_0x1ff0('0x4a')]['id']}})['then'](handleEntityNotFound(_0x16fff9,null))[_0x1ff0('0x27')](function(_0x4a83f4){if(_0x4a83f4){_0x8e320c=_0x4a83f4;_0x1d6f06['model']=_[_0x1ff0('0x36')](db[_0x1ff0('0x5e')][_0x1ff0('0x4b')]);_0x1d6f06[_0x1ff0('0x35')]=_['keys'](_0x191068[_0x1ff0('0x35')]);_0x1d6f06[_0x1ff0('0x37')]=_[_0x1ff0('0x38')](_0x1d6f06[_0x1ff0('0x34')],_0x1d6f06[_0x1ff0('0x35')]);_0x35c5df[_0x1ff0('0x3a')]=_[_0x1ff0('0x38')](_0x1d6f06[_0x1ff0('0x34')],qs[_0x1ff0('0x39')](_0x191068[_0x1ff0('0x35')][_0x1ff0('0x39')]));_0x35c5df['attributes']=_0x35c5df['attributes'][_0x1ff0('0x3b')]?_0x35c5df['attributes']:_0x1d6f06[_0x1ff0('0x34')];_0x35c5df[_0x1ff0('0x3e')]=qs[_0x1ff0('0x3f')](_0x191068[_0x1ff0('0x35')][_0x1ff0('0x3f')]);_0x35c5df[_0x1ff0('0x40')]=qs['filters'](_[_0x1ff0('0x5b')](_0x191068[_0x1ff0('0x35')],_0x1d6f06[_0x1ff0('0x37')]));if(_0x191068[_0x1ff0('0x35')][_0x1ff0('0x5a')]){_0x35c5df[_0x1ff0('0x40')]=_[_0x1ff0('0x41')](_0x35c5df['where'],{'$or':_[_0x1ff0('0x2f')](_0x35c5df[_0x1ff0('0x3a')],function(_0x5e4dd1){var _0x5eb2ff={};_0x5eb2ff[_0x5e4dd1]={'$like':'%'+_0x191068['query'][_0x1ff0('0x5a')]+'%'};return _0x5eb2ff;})});}_0x35c5df=_[_0x1ff0('0x41')]({},_0x35c5df,_0x191068[_0x1ff0('0x43')]);return _0x8e320c[_0x1ff0('0x5f')](_0x35c5df);}})[_0x1ff0('0x27')](function(_0x4251c5){if(_0x4251c5){_0x16ab85=_0x4251c5[_0x1ff0('0x3b')];if(!_0x191068['query'][_0x1ff0('0x3c')]('nolimit')){_0x35c5df[_0x1ff0('0x1f')]=qs[_0x1ff0('0x1f')](_0x191068['query'][_0x1ff0('0x1f')]);_0x35c5df[_0x1ff0('0x1c')]=qs[_0x1ff0('0x1c')](_0x191068[_0x1ff0('0x35')][_0x1ff0('0x1c')]);}return _0x8e320c['getActions'](_0x35c5df);}})[_0x1ff0('0x27')](function(_0x4f8d1b){if(_0x4f8d1b){return _0x4f8d1b?{'count':_0x16ab85,'rows':_0x4f8d1b}:null;}})[_0x1ff0('0x27')](respondWithResult(_0x16fff9,null))['catch'](handleError(_0x16fff9,null));};