Built motion from commit 43538d75.|2.5.35
[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 _0x2f76=['name','send','index','map','rawAttributes','fieldName','type','key','query','keys','intersection','model','attributes','fields','length','hasOwnProperty','order','sort','where','filters','pick','VIRTUAL','filter','Trigger','include','findAll','rows','show','includeAll','merge','catch','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','params','TriggerAllId','Condition','addAnyCondition','TriggerAnyId','getAllConditions','findOne','nolimit','getAnyConditions','options','addAction','TriggerId','Action','getActions','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','undefined','limit','count','offset','set','Content-Range','apply','reject','save','then','destroy','get','Triggers','UserProfileResource','sendStatus','error','stack'];(function(_0x19e35c,_0x29cd1e){var _0x3e1fe8=function(_0x17258b){while(--_0x17258b){_0x19e35c['push'](_0x19e35c['shift']());}};_0x3e1fe8(++_0x29cd1e);}(_0x2f76,0x1c2));var _0x62f7=function(_0x49e0c8,_0x45617f){_0x49e0c8=_0x49e0c8-0x0;var _0x1b6cd3=_0x2f76[_0x49e0c8];return _0x1b6cd3;};'use strict';var emlformat=require(_0x62f7('0x0'));var rimraf=require(_0x62f7('0x1'));var zipdir=require(_0x62f7('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x62f7('0x3'));var moment=require(_0x62f7('0x4'));var BPromise=require(_0x62f7('0x5'));var Mustache=require('mustache');var util=require(_0x62f7('0x6'));var path=require(_0x62f7('0x7'));var sox=require('sox');var csv=require(_0x62f7('0x8'));var ejs=require(_0x62f7('0x9'));var fs=require('fs');var fs_extra=require(_0x62f7('0xa'));var _=require(_0x62f7('0xb'));var squel=require(_0x62f7('0xc'));var crypto=require(_0x62f7('0xd'));var jsforce=require(_0x62f7('0xe'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x62f7('0xf'));var authService=require(_0x62f7('0x10'));var qs=require(_0x62f7('0x11'));var as=require(_0x62f7('0x12'));var hardwareService=require(_0x62f7('0x13'));var logger=require('../../config/logger')(_0x62f7('0x14'));var utils=require(_0x62f7('0x15'));var config=require(_0x62f7('0x16'));var licenseUtil=require(_0x62f7('0x17'));var db=require(_0x62f7('0x18'))['db'];function respondWithStatusCode(_0x16b4ef,_0x5696ae){_0x5696ae=_0x5696ae||0xcc;return function(_0x1b6f39){if(_0x1b6f39){return _0x16b4ef['sendStatus'](_0x5696ae);}return _0x16b4ef[_0x62f7('0x19')](_0x5696ae)[_0x62f7('0x1a')]();};}function respondWithResult(_0x24aa03,_0x3f5544){_0x3f5544=_0x3f5544||0xc8;return function(_0x432b52){if(_0x432b52){return _0x24aa03[_0x62f7('0x19')](_0x3f5544)[_0x62f7('0x1b')](_0x432b52);}};}function respondWithFilteredResult(_0x2d4594,_0x1ee43f){return function(_0x53f9ad){if(_0x53f9ad){var _0xfcfb6=typeof _0x1ee43f['offset']===_0x62f7('0x1c')&&typeof _0x1ee43f[_0x62f7('0x1d')]===_0x62f7('0x1c');var _0xaa0e3a=_0x53f9ad[_0x62f7('0x1e')];var _0x1bdb56=_0xfcfb6?0x0:_0x1ee43f['offset'];var _0x1e2408=_0xfcfb6?_0x53f9ad[_0x62f7('0x1e')]:_0x1ee43f[_0x62f7('0x1f')]+_0x1ee43f['limit'];var _0x2eb8ac;if(_0x1e2408>=_0xaa0e3a){_0x1e2408=_0xaa0e3a;_0x2eb8ac=0xc8;}else{_0x2eb8ac=0xce;}_0x2d4594['status'](_0x2eb8ac);return _0x2d4594[_0x62f7('0x20')](_0x62f7('0x21'),_0x1bdb56+'-'+_0x1e2408+'/'+_0xaa0e3a)[_0x62f7('0x1b')](_0x53f9ad);}return null;};}function patchUpdates(_0x7dd633){return function(_0x6301cf){try{jsonpatch[_0x62f7('0x22')](_0x6301cf,_0x7dd633,!![]);}catch(_0x83f2cb){return BPromise[_0x62f7('0x23')](_0x83f2cb);}return _0x6301cf[_0x62f7('0x24')]();};}function saveUpdates(_0x290bbc,_0x354635){return function(_0x528893){if(_0x528893){return _0x528893['update'](_0x290bbc)[_0x62f7('0x25')](function(_0x4b2cdd){return _0x4b2cdd;});}return null;};}function removeEntity(_0x2deb7f,_0x5c8ce9){return function(_0x3b2fac){if(_0x3b2fac){return _0x3b2fac[_0x62f7('0x26')]()[_0x62f7('0x25')](function(){var _0x4e457d=_0x3b2fac[_0x62f7('0x27')]({'plain':!![]});var _0x2bb5a5=_0x62f7('0x28');return db[_0x62f7('0x29')]['destroy']({'where':{'type':_0x2bb5a5,'resourceId':_0x4e457d['id']}})[_0x62f7('0x25')](function(){return _0x3b2fac;});})[_0x62f7('0x25')](function(){_0x2deb7f[_0x62f7('0x19')](0xcc)[_0x62f7('0x1a')]();});}};}function handleEntityNotFound(_0x2661fe,_0x17e3cc){return function(_0x13d2e7){if(!_0x13d2e7){_0x2661fe[_0x62f7('0x2a')](0x194);}return _0x13d2e7;};}function handleError(_0x48abca,_0x3cd413){_0x3cd413=_0x3cd413||0x1f4;return function(_0x26e8f8){logger[_0x62f7('0x2b')](_0x26e8f8[_0x62f7('0x2c')]);if(_0x26e8f8[_0x62f7('0x2d')]){delete _0x26e8f8['name'];}_0x48abca[_0x62f7('0x19')](_0x3cd413)[_0x62f7('0x2e')](_0x26e8f8);};}exports[_0x62f7('0x2f')]=function(_0x41c1da,_0x1539a7){var _0x4fa546={},_0x341878={},_0x257b56={'count':0x0,'rows':[]};var _0x127981=_[_0x62f7('0x30')](db['Trigger'][_0x62f7('0x31')],function(_0x37b0d9){return{'name':_0x37b0d9[_0x62f7('0x32')],'type':_0x37b0d9[_0x62f7('0x33')][_0x62f7('0x34')]};});_0x341878['model']=_[_0x62f7('0x30')](_0x127981,_0x62f7('0x2d'));_0x341878[_0x62f7('0x35')]=_[_0x62f7('0x36')](_0x41c1da['query']);_0x341878['filters']=_[_0x62f7('0x37')](_0x341878[_0x62f7('0x38')],_0x341878[_0x62f7('0x35')]);_0x4fa546[_0x62f7('0x39')]=_['intersection'](_0x341878[_0x62f7('0x38')],qs[_0x62f7('0x3a')](_0x41c1da[_0x62f7('0x35')][_0x62f7('0x3a')]));_0x4fa546[_0x62f7('0x39')]=_0x4fa546['attributes'][_0x62f7('0x3b')]?_0x4fa546[_0x62f7('0x39')]:_0x341878['model'];if(!_0x41c1da[_0x62f7('0x35')][_0x62f7('0x3c')]('nolimit')){_0x4fa546[_0x62f7('0x1d')]=qs[_0x62f7('0x1d')](_0x41c1da[_0x62f7('0x35')][_0x62f7('0x1d')]);_0x4fa546[_0x62f7('0x1f')]=qs[_0x62f7('0x1f')](_0x41c1da['query'][_0x62f7('0x1f')]);}_0x4fa546[_0x62f7('0x3d')]=qs['sort'](_0x41c1da[_0x62f7('0x35')][_0x62f7('0x3e')]);_0x4fa546[_0x62f7('0x3f')]=qs[_0x62f7('0x40')](_[_0x62f7('0x41')](_0x41c1da[_0x62f7('0x35')],_0x341878['filters']),_0x127981);if(_0x41c1da[_0x62f7('0x35')]['filter']){_0x4fa546[_0x62f7('0x3f')]=_['merge'](_0x4fa546['where'],{'$or':_[_0x62f7('0x30')](_0x127981,function(_0xae22f9){if(_0xae22f9[_0x62f7('0x33')]!==_0x62f7('0x42')){var _0x3e94fb={};_0x3e94fb[_0xae22f9[_0x62f7('0x2d')]]={'$like':'%'+_0x41c1da[_0x62f7('0x35')][_0x62f7('0x43')]+'%'};return _0x3e94fb;}})});}_0x4fa546=_['merge']({},_0x4fa546,_0x41c1da['options']);var _0x2bd890={'where':_0x4fa546[_0x62f7('0x3f')]};return db[_0x62f7('0x44')][_0x62f7('0x1e')](_0x2bd890)[_0x62f7('0x25')](function(_0x3e1001){_0x257b56['count']=_0x3e1001;if(_0x41c1da[_0x62f7('0x35')]['includeAll']){_0x4fa546[_0x62f7('0x45')]=[{'all':!![]}];}return db[_0x62f7('0x44')][_0x62f7('0x46')](_0x4fa546);})['then'](function(_0x55eda2){_0x257b56[_0x62f7('0x47')]=_0x55eda2;return _0x257b56;})[_0x62f7('0x25')](respondWithFilteredResult(_0x1539a7,_0x4fa546))['catch'](handleError(_0x1539a7,null));};exports[_0x62f7('0x48')]=function(_0x163bdc,_0x3a3070){var _0x318b97={'raw':![],'where':{'id':_0x163bdc['params']['id']}},_0x439f92={};_0x439f92[_0x62f7('0x38')]=_[_0x62f7('0x36')](db['Trigger'][_0x62f7('0x31')]);_0x439f92['query']=_[_0x62f7('0x36')](_0x163bdc['query']);_0x439f92[_0x62f7('0x40')]=_[_0x62f7('0x37')](_0x439f92['model'],_0x439f92['query']);_0x318b97['attributes']=_[_0x62f7('0x37')](_0x439f92['model'],qs[_0x62f7('0x3a')](_0x163bdc[_0x62f7('0x35')][_0x62f7('0x3a')]));_0x318b97['attributes']=_0x318b97[_0x62f7('0x39')][_0x62f7('0x3b')]?_0x318b97[_0x62f7('0x39')]:_0x439f92[_0x62f7('0x38')];if(_0x163bdc[_0x62f7('0x35')][_0x62f7('0x49')]){_0x318b97[_0x62f7('0x45')]=[{'all':!![]}];}_0x318b97=_[_0x62f7('0x4a')]({},_0x318b97,_0x163bdc['options']);return db[_0x62f7('0x44')]['find'](_0x318b97)['then'](handleEntityNotFound(_0x3a3070,null))[_0x62f7('0x25')](respondWithResult(_0x3a3070,null))[_0x62f7('0x4b')](handleError(_0x3a3070,null));};exports[_0x62f7('0x4c')]=function(_0x58e191,_0x1e0565){return db[_0x62f7('0x44')][_0x62f7('0x4c')](_0x58e191['body'],{})[_0x62f7('0x25')](function(_0x490325){var _0x45d847=_0x58e191[_0x62f7('0x4d')]['get']({'plain':!![]});if(!_0x45d847)throw new Error(_0x62f7('0x4e'));if(_0x45d847[_0x62f7('0x4f')]===_0x62f7('0x4d')){var _0x508710=_0x490325[_0x62f7('0x27')]({'plain':!![]});var _0x21c05f=_0x62f7('0x28');return db[_0x62f7('0x50')][_0x62f7('0x51')]({'where':{'name':_0x21c05f,'userProfileId':_0x45d847[_0x62f7('0x52')]},'raw':!![]})[_0x62f7('0x25')](function(_0x2077dc){if(_0x2077dc&&_0x2077dc['autoAssociation']===0x0){return db[_0x62f7('0x29')][_0x62f7('0x4c')]({'name':_0x508710[_0x62f7('0x2d')],'resourceId':_0x508710['id'],'type':_0x2077dc[_0x62f7('0x2d')],'sectionId':_0x2077dc['id']},{})['then'](function(){return _0x490325;});}else{return _0x490325;}})[_0x62f7('0x4b')](function(_0xe3dd06){logger[_0x62f7('0x2b')](_0x62f7('0x53'),_0xe3dd06);throw _0xe3dd06;});}return _0x490325;})[_0x62f7('0x25')](respondWithResult(_0x1e0565,0xc9))[_0x62f7('0x4b')](handleError(_0x1e0565,null));};exports['update']=function(_0x53b283,_0x434af2){if(_0x53b283[_0x62f7('0x54')]['id']){delete _0x53b283['body']['id'];}return db[_0x62f7('0x44')][_0x62f7('0x51')]({'where':{'id':_0x53b283['params']['id']}})['then'](handleEntityNotFound(_0x434af2,null))[_0x62f7('0x25')](saveUpdates(_0x53b283[_0x62f7('0x54')],null))[_0x62f7('0x25')](respondWithResult(_0x434af2,null))['catch'](handleError(_0x434af2,null));};exports['destroy']=function(_0x14943a,_0x26c128){return db[_0x62f7('0x44')][_0x62f7('0x51')]({'where':{'id':_0x14943a[_0x62f7('0x55')]['id']}})[_0x62f7('0x25')](handleEntityNotFound(_0x26c128,null))[_0x62f7('0x25')](removeEntity(_0x26c128,null))[_0x62f7('0x4b')](handleError(_0x26c128,null));};exports['addAllCondition']=function(_0x217b26,_0x5569e0,_0x36dbe2){if(_0x217b26['body']['id']){delete _0x217b26['body']['id'];}return db[_0x62f7('0x44')]['find']({'where':{'id':_0x217b26[_0x62f7('0x55')]['id']}})[_0x62f7('0x25')](handleEntityNotFound(_0x5569e0,null))[_0x62f7('0x25')](function(_0x317965){if(_0x317965){_0x217b26[_0x62f7('0x54')][_0x62f7('0x56')]=_0x317965['id'];return db[_0x62f7('0x57')][_0x62f7('0x4c')](_0x217b26[_0x62f7('0x54')]);}})[_0x62f7('0x25')](respondWithResult(_0x5569e0,null))['catch'](handleError(_0x5569e0,null));};exports[_0x62f7('0x58')]=function(_0x3f5adc,_0x112394,_0x571680){if(_0x3f5adc['body']['id']){delete _0x3f5adc[_0x62f7('0x54')]['id'];}return db['Trigger'][_0x62f7('0x51')]({'where':{'id':_0x3f5adc[_0x62f7('0x55')]['id']}})['then'](handleEntityNotFound(_0x112394,null))[_0x62f7('0x25')](function(_0x616aa7){if(_0x616aa7){_0x3f5adc[_0x62f7('0x54')][_0x62f7('0x59')]=_0x616aa7['id'];return db[_0x62f7('0x57')]['create'](_0x3f5adc[_0x62f7('0x54')]);}})[_0x62f7('0x25')](respondWithResult(_0x112394,null))[_0x62f7('0x4b')](handleError(_0x112394,null));};exports[_0x62f7('0x5a')]=function(_0xfbf68e,_0x3e3bb7,_0x5c9db6){var _0x4d83e1={};var _0x1b1893={};var _0x5d287a;var _0x349425;return db[_0x62f7('0x44')][_0x62f7('0x5b')]({'where':{'id':_0xfbf68e[_0x62f7('0x55')]['id']}})[_0x62f7('0x25')](handleEntityNotFound(_0x3e3bb7,null))[_0x62f7('0x25')](function(_0x1788c3){if(_0x1788c3){_0x5d287a=_0x1788c3;_0x1b1893[_0x62f7('0x38')]=_['keys'](db[_0x62f7('0x57')]['rawAttributes']);_0x1b1893[_0x62f7('0x35')]=_['keys'](_0xfbf68e[_0x62f7('0x35')]);_0x1b1893[_0x62f7('0x40')]=_['intersection'](_0x1b1893[_0x62f7('0x38')],_0x1b1893['query']);_0x4d83e1['attributes']=_[_0x62f7('0x37')](_0x1b1893[_0x62f7('0x38')],qs[_0x62f7('0x3a')](_0xfbf68e[_0x62f7('0x35')]['fields']));_0x4d83e1[_0x62f7('0x39')]=_0x4d83e1['attributes'][_0x62f7('0x3b')]?_0x4d83e1[_0x62f7('0x39')]:_0x1b1893[_0x62f7('0x38')];_0x4d83e1[_0x62f7('0x3d')]=qs['sort'](_0xfbf68e[_0x62f7('0x35')][_0x62f7('0x3e')]);_0x4d83e1[_0x62f7('0x3f')]=qs['filters'](_[_0x62f7('0x41')](_0xfbf68e[_0x62f7('0x35')],_0x1b1893[_0x62f7('0x40')]));if(_0xfbf68e[_0x62f7('0x35')][_0x62f7('0x43')]){_0x4d83e1['where']=_[_0x62f7('0x4a')](_0x4d83e1[_0x62f7('0x3f')],{'$or':_['map'](_0x4d83e1[_0x62f7('0x39')],function(_0x6fa67a){var _0x7ef5b1={};_0x7ef5b1[_0x6fa67a]={'$like':'%'+_0xfbf68e[_0x62f7('0x35')][_0x62f7('0x43')]+'%'};return _0x7ef5b1;})});}_0x4d83e1=_[_0x62f7('0x4a')]({},_0x4d83e1,_0xfbf68e['options']);return _0x5d287a['getAllConditions'](_0x4d83e1);}})[_0x62f7('0x25')](function(_0x2e54f9){if(_0x2e54f9){_0x349425=_0x2e54f9[_0x62f7('0x3b')];if(!_0xfbf68e[_0x62f7('0x35')]['hasOwnProperty'](_0x62f7('0x5c'))){_0x4d83e1['limit']=qs[_0x62f7('0x1d')](_0xfbf68e[_0x62f7('0x35')]['limit']);_0x4d83e1[_0x62f7('0x1f')]=qs[_0x62f7('0x1f')](_0xfbf68e[_0x62f7('0x35')][_0x62f7('0x1f')]);}return _0x5d287a[_0x62f7('0x5a')](_0x4d83e1);}})[_0x62f7('0x25')](function(_0x5f0901){if(_0x5f0901){return _0x5f0901?{'count':_0x349425,'rows':_0x5f0901}:null;}})[_0x62f7('0x25')](respondWithResult(_0x3e3bb7,null))[_0x62f7('0x4b')](handleError(_0x3e3bb7,null));};exports[_0x62f7('0x5d')]=function(_0xe3f1e2,_0x3f2358,_0x29d1b1){var _0x2a1077={};var _0x350ff5={};var _0x721e0c;var _0x3a9faf;return db['Trigger'][_0x62f7('0x5b')]({'where':{'id':_0xe3f1e2['params']['id']}})['then'](handleEntityNotFound(_0x3f2358,null))[_0x62f7('0x25')](function(_0x155b09){if(_0x155b09){_0x721e0c=_0x155b09;_0x350ff5[_0x62f7('0x38')]=_[_0x62f7('0x36')](db['Condition']['rawAttributes']);_0x350ff5['query']=_['keys'](_0xe3f1e2[_0x62f7('0x35')]);_0x350ff5[_0x62f7('0x40')]=_['intersection'](_0x350ff5[_0x62f7('0x38')],_0x350ff5[_0x62f7('0x35')]);_0x2a1077['attributes']=_[_0x62f7('0x37')](_0x350ff5[_0x62f7('0x38')],qs[_0x62f7('0x3a')](_0xe3f1e2[_0x62f7('0x35')][_0x62f7('0x3a')]));_0x2a1077[_0x62f7('0x39')]=_0x2a1077['attributes']['length']?_0x2a1077[_0x62f7('0x39')]:_0x350ff5[_0x62f7('0x38')];_0x2a1077[_0x62f7('0x3d')]=qs[_0x62f7('0x3e')](_0xe3f1e2[_0x62f7('0x35')][_0x62f7('0x3e')]);_0x2a1077['where']=qs[_0x62f7('0x40')](_[_0x62f7('0x41')](_0xe3f1e2[_0x62f7('0x35')],_0x350ff5[_0x62f7('0x40')]));if(_0xe3f1e2[_0x62f7('0x35')][_0x62f7('0x43')]){_0x2a1077[_0x62f7('0x3f')]=_[_0x62f7('0x4a')](_0x2a1077[_0x62f7('0x3f')],{'$or':_[_0x62f7('0x30')](_0x2a1077[_0x62f7('0x39')],function(_0x43c21a){var _0x10e7f5={};_0x10e7f5[_0x43c21a]={'$like':'%'+_0xe3f1e2[_0x62f7('0x35')]['filter']+'%'};return _0x10e7f5;})});}_0x2a1077=_[_0x62f7('0x4a')]({},_0x2a1077,_0xe3f1e2[_0x62f7('0x5e')]);return _0x721e0c[_0x62f7('0x5d')](_0x2a1077);}})[_0x62f7('0x25')](function(_0xd79ff9){if(_0xd79ff9){_0x3a9faf=_0xd79ff9[_0x62f7('0x3b')];if(!_0xe3f1e2['query'][_0x62f7('0x3c')]('nolimit')){_0x2a1077[_0x62f7('0x1d')]=qs['limit'](_0xe3f1e2[_0x62f7('0x35')]['limit']);_0x2a1077[_0x62f7('0x1f')]=qs[_0x62f7('0x1f')](_0xe3f1e2[_0x62f7('0x35')][_0x62f7('0x1f')]);}return _0x721e0c[_0x62f7('0x5d')](_0x2a1077);}})[_0x62f7('0x25')](function(_0x7c89f3){if(_0x7c89f3){return _0x7c89f3?{'count':_0x3a9faf,'rows':_0x7c89f3}:null;}})[_0x62f7('0x25')](respondWithResult(_0x3f2358,null))[_0x62f7('0x4b')](handleError(_0x3f2358,null));};exports[_0x62f7('0x5f')]=function(_0x19a284,_0x41a2fa,_0xde5815){if(_0x19a284[_0x62f7('0x54')]['id']){delete _0x19a284[_0x62f7('0x54')]['id'];}return db[_0x62f7('0x44')]['find']({'where':{'id':_0x19a284[_0x62f7('0x55')]['id']}})['then'](handleEntityNotFound(_0x41a2fa,null))['then'](function(_0x2f1f65){if(_0x2f1f65){_0x19a284[_0x62f7('0x54')][_0x62f7('0x60')]=_0x2f1f65['id'];return db[_0x62f7('0x61')][_0x62f7('0x4c')](_0x19a284['body']);}})[_0x62f7('0x25')](respondWithResult(_0x41a2fa,null))[_0x62f7('0x4b')](handleError(_0x41a2fa,null));};exports[_0x62f7('0x62')]=function(_0x4ab357,_0x52126d,_0x54c226){var _0x2a39b6={};var _0x2ed3a5={};var _0xb983e3;var _0x1b8701;return db['Trigger'][_0x62f7('0x5b')]({'where':{'id':_0x4ab357[_0x62f7('0x55')]['id']}})[_0x62f7('0x25')](handleEntityNotFound(_0x52126d,null))[_0x62f7('0x25')](function(_0x1a206d){if(_0x1a206d){_0xb983e3=_0x1a206d;_0x2ed3a5[_0x62f7('0x38')]=_[_0x62f7('0x36')](db[_0x62f7('0x61')][_0x62f7('0x31')]);_0x2ed3a5['query']=_[_0x62f7('0x36')](_0x4ab357['query']);_0x2ed3a5[_0x62f7('0x40')]=_[_0x62f7('0x37')](_0x2ed3a5['model'],_0x2ed3a5[_0x62f7('0x35')]);_0x2a39b6['attributes']=_[_0x62f7('0x37')](_0x2ed3a5[_0x62f7('0x38')],qs['fields'](_0x4ab357[_0x62f7('0x35')][_0x62f7('0x3a')]));_0x2a39b6['attributes']=_0x2a39b6[_0x62f7('0x39')]['length']?_0x2a39b6['attributes']:_0x2ed3a5[_0x62f7('0x38')];_0x2a39b6[_0x62f7('0x3d')]=qs[_0x62f7('0x3e')](_0x4ab357[_0x62f7('0x35')][_0x62f7('0x3e')]);_0x2a39b6['where']=qs[_0x62f7('0x40')](_[_0x62f7('0x41')](_0x4ab357[_0x62f7('0x35')],_0x2ed3a5['filters']));if(_0x4ab357[_0x62f7('0x35')][_0x62f7('0x43')]){_0x2a39b6[_0x62f7('0x3f')]=_[_0x62f7('0x4a')](_0x2a39b6[_0x62f7('0x3f')],{'$or':_[_0x62f7('0x30')](_0x2a39b6[_0x62f7('0x39')],function(_0x5f2c17){var _0x1e75af={};_0x1e75af[_0x5f2c17]={'$like':'%'+_0x4ab357[_0x62f7('0x35')][_0x62f7('0x43')]+'%'};return _0x1e75af;})});}_0x2a39b6=_['merge']({},_0x2a39b6,_0x4ab357[_0x62f7('0x5e')]);return _0xb983e3[_0x62f7('0x62')](_0x2a39b6);}})['then'](function(_0x4cd26c){if(_0x4cd26c){_0x1b8701=_0x4cd26c['length'];if(!_0x4ab357[_0x62f7('0x35')]['hasOwnProperty']('nolimit')){_0x2a39b6['limit']=qs[_0x62f7('0x1d')](_0x4ab357[_0x62f7('0x35')][_0x62f7('0x1d')]);_0x2a39b6[_0x62f7('0x1f')]=qs['offset'](_0x4ab357[_0x62f7('0x35')][_0x62f7('0x1f')]);}return _0xb983e3[_0x62f7('0x62')](_0x2a39b6);}})[_0x62f7('0x25')](function(_0x5a964d){if(_0x5a964d){return _0x5a964d?{'count':_0x1b8701,'rows':_0x5a964d}:null;}})['then'](respondWithResult(_0x52126d,null))['catch'](handleError(_0x52126d,null));};