90bb04ebfc584d786bdf7184b4b1adc1867bfc15
[motion2.git] / server / api / intFreshdeskConfiguration / intFreshdeskConfiguration.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 _0xb02b=['catch','show','params','includeAll','create','body','find','getFields','findOne','length','FreshdeskField','getSubjects','getDescriptions','getTags','setTags','ids','eml-format','zip-dir','fast-json-patch','request-promise','moment','util','path','sox','ejs','fs-extra','crypto','to-csv','querystring','../../components/auth/service','../../config/license/hardware','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','reject','save','update','destroy','error','stack','name','map','FreshdeskConfiguration','rawAttributes','fieldName','type','model','query','keys','attributes','intersection','fields','hasOwnProperty','nolimit','order','sort','filters','pick','where','merge','filter','options','then','include','findAll'];(function(_0x18732d,_0x3e1ff3){var _0x1ccfe8=function(_0x4c8c53){while(--_0x4c8c53){_0x18732d['push'](_0x18732d['shift']());}};_0x1ccfe8(++_0x3e1ff3);}(_0xb02b,0xa6));var _0xbb02=function(_0x4846f1,_0x2a0c61){_0x4846f1=_0x4846f1-0x0;var _0x2da056=_0xb02b[_0x4846f1];return _0x2da056;};'use strict';var emlformat=require(_0xbb02('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xbb02('0x1'));var jsonpatch=require(_0xbb02('0x2'));var rp=require(_0xbb02('0x3'));var moment=require(_0xbb02('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xbb02('0x5'));var path=require(_0xbb02('0x6'));var sox=require(_0xbb02('0x7'));var csv=require('to-csv');var ejs=require(_0xbb02('0x8'));var fs=require('fs');var fs_extra=require(_0xbb02('0x9'));var _=require('lodash');var squel=require('squel');var crypto=require(_0xbb02('0xa'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xbb02('0xb'));var querystring=require(_0xbb02('0xc'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xbb02('0xd'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xbb02('0xe'));var logger=require('../../config/logger')(_0xbb02('0xf'));var utils=require(_0xbb02('0x10'));var config=require('../../config/environment');var licenseUtil=require(_0xbb02('0x11'));var db=require(_0xbb02('0x12'))['db'];function respondWithStatusCode(_0x2055cb,_0x34974e){_0x34974e=_0x34974e||0xcc;return function(_0x9b6dab){if(_0x9b6dab){return _0x2055cb[_0xbb02('0x13')](_0x34974e);}return _0x2055cb[_0xbb02('0x14')](_0x34974e)[_0xbb02('0x15')]();};}function respondWithResult(_0x5e3e42,_0x4ab807){_0x4ab807=_0x4ab807||0xc8;return function(_0x1dfc4a){if(_0x1dfc4a){return _0x5e3e42[_0xbb02('0x14')](_0x4ab807)[_0xbb02('0x16')](_0x1dfc4a);}};}function respondWithFilteredResult(_0x2a9723,_0x1f796f){return function(_0x47c4da){if(_0x47c4da){var _0xbabe46=typeof _0x1f796f[_0xbb02('0x17')]===_0xbb02('0x18')&&typeof _0x1f796f[_0xbb02('0x19')]==='undefined';var _0xc378ef=_0x47c4da[_0xbb02('0x1a')];var _0x1a19cd=_0xbabe46?0x0:_0x1f796f[_0xbb02('0x17')];var _0x20539a=_0xbabe46?_0x47c4da[_0xbb02('0x1a')]:_0x1f796f['offset']+_0x1f796f[_0xbb02('0x19')];var _0x4793c1;if(_0x20539a>=_0xc378ef){_0x20539a=_0xc378ef;_0x4793c1=0xc8;}else{_0x4793c1=0xce;}_0x2a9723[_0xbb02('0x14')](_0x4793c1);return _0x2a9723[_0xbb02('0x1b')]('Content-Range',_0x1a19cd+'-'+_0x20539a+'/'+_0xc378ef)[_0xbb02('0x16')](_0x47c4da);}return null;};}function patchUpdates(_0x3b6578){return function(_0x2d1fae){try{jsonpatch['apply'](_0x2d1fae,_0x3b6578,!![]);}catch(_0x8f4f1a){return BPromise[_0xbb02('0x1c')](_0x8f4f1a);}return _0x2d1fae[_0xbb02('0x1d')]();};}function saveUpdates(_0x5286c4,_0x4ea845){return function(_0x36699a){if(_0x36699a){return _0x36699a[_0xbb02('0x1e')](_0x5286c4)['then'](function(_0x249c12){return _0x249c12;});}return null;};}function removeEntity(_0x52db78,_0x16c360){return function(_0x44f7c5){if(_0x44f7c5){return _0x44f7c5[_0xbb02('0x1f')]()['then'](function(){_0x52db78['status'](0xcc)[_0xbb02('0x15')]();});}};}function handleEntityNotFound(_0x3f435b,_0x2905bd){return function(_0x34c9de){if(!_0x34c9de){_0x3f435b[_0xbb02('0x13')](0x194);}return _0x34c9de;};}function handleError(_0x46bb8f,_0x4e4c68){_0x4e4c68=_0x4e4c68||0x1f4;return function(_0x52b71f){logger[_0xbb02('0x20')](_0x52b71f[_0xbb02('0x21')]);if(_0x52b71f[_0xbb02('0x22')]){delete _0x52b71f[_0xbb02('0x22')];}_0x46bb8f[_0xbb02('0x14')](_0x4e4c68)['send'](_0x52b71f);};}exports['index']=function(_0x463058,_0x4685aa){var _0x3b5754={},_0x4955a7={},_0xaabc61={'count':0x0,'rows':[]};var _0x4284c7=_[_0xbb02('0x23')](db[_0xbb02('0x24')][_0xbb02('0x25')],function(_0x2339e2){return{'name':_0x2339e2[_0xbb02('0x26')],'type':_0x2339e2[_0xbb02('0x27')]['key']};});_0x4955a7[_0xbb02('0x28')]=_['map'](_0x4284c7,_0xbb02('0x22'));_0x4955a7[_0xbb02('0x29')]=_[_0xbb02('0x2a')](_0x463058[_0xbb02('0x29')]);_0x4955a7['filters']=_['intersection'](_0x4955a7[_0xbb02('0x28')],_0x4955a7['query']);_0x3b5754[_0xbb02('0x2b')]=_[_0xbb02('0x2c')](_0x4955a7[_0xbb02('0x28')],qs[_0xbb02('0x2d')](_0x463058[_0xbb02('0x29')][_0xbb02('0x2d')]));_0x3b5754[_0xbb02('0x2b')]=_0x3b5754[_0xbb02('0x2b')]['length']?_0x3b5754[_0xbb02('0x2b')]:_0x4955a7[_0xbb02('0x28')];if(!_0x463058[_0xbb02('0x29')][_0xbb02('0x2e')](_0xbb02('0x2f'))){_0x3b5754['limit']=qs[_0xbb02('0x19')](_0x463058['query'][_0xbb02('0x19')]);_0x3b5754[_0xbb02('0x17')]=qs[_0xbb02('0x17')](_0x463058['query']['offset']);}_0x3b5754[_0xbb02('0x30')]=qs['sort'](_0x463058[_0xbb02('0x29')][_0xbb02('0x31')]);_0x3b5754['where']=qs[_0xbb02('0x32')](_[_0xbb02('0x33')](_0x463058[_0xbb02('0x29')],_0x4955a7[_0xbb02('0x32')]),_0x4284c7);if(_0x463058[_0xbb02('0x29')]['filter']){_0x3b5754[_0xbb02('0x34')]=_[_0xbb02('0x35')](_0x3b5754[_0xbb02('0x34')],{'$or':_[_0xbb02('0x23')](_0x4284c7,function(_0x1e73bf){if(_0x1e73bf[_0xbb02('0x27')]!=='VIRTUAL'){var _0x1aadca={};_0x1aadca[_0x1e73bf[_0xbb02('0x22')]]={'$like':'%'+_0x463058[_0xbb02('0x29')][_0xbb02('0x36')]+'%'};return _0x1aadca;}})});}_0x3b5754=_[_0xbb02('0x35')]({},_0x3b5754,_0x463058[_0xbb02('0x37')]);var _0x2acaf8={'where':_0x3b5754[_0xbb02('0x34')]};return db[_0xbb02('0x24')][_0xbb02('0x1a')](_0x2acaf8)[_0xbb02('0x38')](function(_0x2159f3){_0xaabc61[_0xbb02('0x1a')]=_0x2159f3;if(_0x463058[_0xbb02('0x29')]['includeAll']){_0x3b5754[_0xbb02('0x39')]=[{'all':!![]}];}return db[_0xbb02('0x24')][_0xbb02('0x3a')](_0x3b5754);})[_0xbb02('0x38')](function(_0x3271a8){_0xaabc61['rows']=_0x3271a8;return _0xaabc61;})['then'](respondWithFilteredResult(_0x4685aa,_0x3b5754))[_0xbb02('0x3b')](handleError(_0x4685aa,null));};exports[_0xbb02('0x3c')]=function(_0x168c0f,_0x357219){var _0x3f0a58={'raw':![],'where':{'id':_0x168c0f[_0xbb02('0x3d')]['id']}},_0x257dd6={};_0x257dd6[_0xbb02('0x28')]=_[_0xbb02('0x2a')](db['FreshdeskConfiguration'][_0xbb02('0x25')]);_0x257dd6[_0xbb02('0x29')]=_[_0xbb02('0x2a')](_0x168c0f['query']);_0x257dd6['filters']=_['intersection'](_0x257dd6[_0xbb02('0x28')],_0x257dd6[_0xbb02('0x29')]);_0x3f0a58[_0xbb02('0x2b')]=_[_0xbb02('0x2c')](_0x257dd6['model'],qs[_0xbb02('0x2d')](_0x168c0f[_0xbb02('0x29')]['fields']));_0x3f0a58[_0xbb02('0x2b')]=_0x3f0a58[_0xbb02('0x2b')]['length']?_0x3f0a58['attributes']:_0x257dd6['model'];if(_0x168c0f['query'][_0xbb02('0x3e')]){_0x3f0a58[_0xbb02('0x39')]=[{'all':!![]}];}_0x3f0a58=_['merge']({},_0x3f0a58,_0x168c0f[_0xbb02('0x37')]);return db['FreshdeskConfiguration']['find'](_0x3f0a58)[_0xbb02('0x38')](handleEntityNotFound(_0x357219,null))[_0xbb02('0x38')](respondWithResult(_0x357219,null))[_0xbb02('0x3b')](handleError(_0x357219,null));};exports[_0xbb02('0x3f')]=function(_0x20bbea,_0x4b654d){return db[_0xbb02('0x24')][_0xbb02('0x3f')](_0x20bbea[_0xbb02('0x40')],{})[_0xbb02('0x38')](respondWithResult(_0x4b654d,0xc9))[_0xbb02('0x3b')](handleError(_0x4b654d,null));};exports[_0xbb02('0x1e')]=function(_0x11cbd2,_0x1b4628){if(_0x11cbd2['body']['id']){delete _0x11cbd2[_0xbb02('0x40')]['id'];}return db['FreshdeskConfiguration'][_0xbb02('0x41')]({'where':{'id':_0x11cbd2[_0xbb02('0x3d')]['id']}})[_0xbb02('0x38')](handleEntityNotFound(_0x1b4628,null))[_0xbb02('0x38')](saveUpdates(_0x11cbd2[_0xbb02('0x40')],null))[_0xbb02('0x38')](respondWithResult(_0x1b4628,null))[_0xbb02('0x3b')](handleError(_0x1b4628,null));};exports[_0xbb02('0x1f')]=function(_0x2288f3,_0x59c36e){return db[_0xbb02('0x24')][_0xbb02('0x41')]({'where':{'id':_0x2288f3[_0xbb02('0x3d')]['id']}})[_0xbb02('0x38')](handleEntityNotFound(_0x59c36e,null))['then'](removeEntity(_0x59c36e,null))[_0xbb02('0x3b')](handleError(_0x59c36e,null));};exports[_0xbb02('0x42')]=function(_0x3fe527,_0x1e9bff,_0x34289a){var _0xa40cf={};var _0x27cf1a={};var _0x40e7ca;var _0x2b78e7;return db[_0xbb02('0x24')][_0xbb02('0x43')]({'where':{'id':_0x3fe527[_0xbb02('0x3d')]['id']}})['then'](handleEntityNotFound(_0x1e9bff,null))[_0xbb02('0x38')](function(_0x559fe3){if(_0x559fe3){_0x40e7ca=_0x559fe3;_0x27cf1a[_0xbb02('0x28')]=_[_0xbb02('0x2a')](db['FreshdeskField'][_0xbb02('0x25')]);_0x27cf1a['query']=_[_0xbb02('0x2a')](_0x3fe527['query']);_0x27cf1a[_0xbb02('0x32')]=_[_0xbb02('0x2c')](_0x27cf1a[_0xbb02('0x28')],_0x27cf1a['query']);_0xa40cf[_0xbb02('0x2b')]=_[_0xbb02('0x2c')](_0x27cf1a[_0xbb02('0x28')],qs[_0xbb02('0x2d')](_0x3fe527[_0xbb02('0x29')][_0xbb02('0x2d')]));_0xa40cf[_0xbb02('0x2b')]=_0xa40cf[_0xbb02('0x2b')][_0xbb02('0x44')]?_0xa40cf[_0xbb02('0x2b')]:_0x27cf1a[_0xbb02('0x28')];_0xa40cf[_0xbb02('0x30')]=qs[_0xbb02('0x31')](_0x3fe527[_0xbb02('0x29')][_0xbb02('0x31')]);_0xa40cf[_0xbb02('0x34')]=qs[_0xbb02('0x32')](_[_0xbb02('0x33')](_0x3fe527[_0xbb02('0x29')],_0x27cf1a[_0xbb02('0x32')]));if(_0x3fe527[_0xbb02('0x29')][_0xbb02('0x36')]){_0xa40cf[_0xbb02('0x34')]=_[_0xbb02('0x35')](_0xa40cf['where'],{'$or':_[_0xbb02('0x23')](_0xa40cf[_0xbb02('0x2b')],function(_0x2ed799){var _0x3f4c5a={};_0x3f4c5a[_0x2ed799]={'$like':'%'+_0x3fe527['query'][_0xbb02('0x36')]+'%'};return _0x3f4c5a;})});}_0xa40cf=_[_0xbb02('0x35')]({},_0xa40cf,_0x3fe527[_0xbb02('0x37')]);return _0x40e7ca[_0xbb02('0x42')](_0xa40cf);}})[_0xbb02('0x38')](function(_0x46bf80){if(_0x46bf80){_0x2b78e7=_0x46bf80[_0xbb02('0x44')];if(!_0x3fe527[_0xbb02('0x29')]['hasOwnProperty'](_0xbb02('0x2f'))){_0xa40cf[_0xbb02('0x19')]=qs['limit'](_0x3fe527[_0xbb02('0x29')][_0xbb02('0x19')]);_0xa40cf[_0xbb02('0x17')]=qs[_0xbb02('0x17')](_0x3fe527[_0xbb02('0x29')][_0xbb02('0x17')]);}return _0x40e7ca['getFields'](_0xa40cf);}})[_0xbb02('0x38')](function(_0x474bf8){if(_0x474bf8){return _0x474bf8?{'count':_0x2b78e7,'rows':_0x474bf8}:null;}})[_0xbb02('0x38')](respondWithResult(_0x1e9bff,null))[_0xbb02('0x3b')](handleError(_0x1e9bff,null));};exports['getSubjects']=function(_0x3b24fc,_0x57202e,_0x40e207){var _0x3b6f2b={};var _0xeb89d5={};var _0x1a8453;var _0x200d4d;return db[_0xbb02('0x24')][_0xbb02('0x43')]({'where':{'id':_0x3b24fc['params']['id']}})['then'](handleEntityNotFound(_0x57202e,null))[_0xbb02('0x38')](function(_0x2c9924){if(_0x2c9924){_0x1a8453=_0x2c9924;_0xeb89d5['model']=_['keys'](db[_0xbb02('0x45')][_0xbb02('0x25')]);_0xeb89d5[_0xbb02('0x29')]=_[_0xbb02('0x2a')](_0x3b24fc[_0xbb02('0x29')]);_0xeb89d5[_0xbb02('0x32')]=_[_0xbb02('0x2c')](_0xeb89d5[_0xbb02('0x28')],_0xeb89d5[_0xbb02('0x29')]);_0x3b6f2b[_0xbb02('0x2b')]=_[_0xbb02('0x2c')](_0xeb89d5[_0xbb02('0x28')],qs['fields'](_0x3b24fc[_0xbb02('0x29')]['fields']));_0x3b6f2b[_0xbb02('0x2b')]=_0x3b6f2b[_0xbb02('0x2b')]['length']?_0x3b6f2b[_0xbb02('0x2b')]:_0xeb89d5[_0xbb02('0x28')];_0x3b6f2b[_0xbb02('0x30')]=qs[_0xbb02('0x31')](_0x3b24fc['query'][_0xbb02('0x31')]);_0x3b6f2b['where']=qs['filters'](_[_0xbb02('0x33')](_0x3b24fc[_0xbb02('0x29')],_0xeb89d5['filters']));if(_0x3b24fc['query']['filter']){_0x3b6f2b[_0xbb02('0x34')]=_[_0xbb02('0x35')](_0x3b6f2b[_0xbb02('0x34')],{'$or':_[_0xbb02('0x23')](_0x3b6f2b[_0xbb02('0x2b')],function(_0x5e547a){var _0x4c9caf={};_0x4c9caf[_0x5e547a]={'$like':'%'+_0x3b24fc[_0xbb02('0x29')][_0xbb02('0x36')]+'%'};return _0x4c9caf;})});}_0x3b6f2b=_[_0xbb02('0x35')]({},_0x3b6f2b,_0x3b24fc[_0xbb02('0x37')]);return _0x1a8453[_0xbb02('0x46')](_0x3b6f2b);}})['then'](function(_0x191044){if(_0x191044){_0x200d4d=_0x191044[_0xbb02('0x44')];if(!_0x3b24fc['query']['hasOwnProperty'](_0xbb02('0x2f'))){_0x3b6f2b[_0xbb02('0x19')]=qs[_0xbb02('0x19')](_0x3b24fc[_0xbb02('0x29')][_0xbb02('0x19')]);_0x3b6f2b[_0xbb02('0x17')]=qs['offset'](_0x3b24fc[_0xbb02('0x29')]['offset']);}return _0x1a8453[_0xbb02('0x46')](_0x3b6f2b);}})['then'](function(_0x1f4e5f){if(_0x1f4e5f){return _0x1f4e5f?{'count':_0x200d4d,'rows':_0x1f4e5f}:null;}})[_0xbb02('0x38')](respondWithResult(_0x57202e,null))[_0xbb02('0x3b')](handleError(_0x57202e,null));};exports[_0xbb02('0x47')]=function(_0x385e6d,_0x36fa80,_0x2853a9){var _0x4ae924={};var _0x52dcb3={};var _0x43cc53;var _0x61d8e7;return db[_0xbb02('0x24')]['findOne']({'where':{'id':_0x385e6d[_0xbb02('0x3d')]['id']}})[_0xbb02('0x38')](handleEntityNotFound(_0x36fa80,null))['then'](function(_0x43b856){if(_0x43b856){_0x43cc53=_0x43b856;_0x52dcb3[_0xbb02('0x28')]=_['keys'](db[_0xbb02('0x45')][_0xbb02('0x25')]);_0x52dcb3[_0xbb02('0x29')]=_[_0xbb02('0x2a')](_0x385e6d[_0xbb02('0x29')]);_0x52dcb3[_0xbb02('0x32')]=_[_0xbb02('0x2c')](_0x52dcb3['model'],_0x52dcb3[_0xbb02('0x29')]);_0x4ae924['attributes']=_['intersection'](_0x52dcb3[_0xbb02('0x28')],qs['fields'](_0x385e6d['query'][_0xbb02('0x2d')]));_0x4ae924[_0xbb02('0x2b')]=_0x4ae924[_0xbb02('0x2b')][_0xbb02('0x44')]?_0x4ae924['attributes']:_0x52dcb3['model'];_0x4ae924[_0xbb02('0x30')]=qs[_0xbb02('0x31')](_0x385e6d[_0xbb02('0x29')][_0xbb02('0x31')]);_0x4ae924[_0xbb02('0x34')]=qs['filters'](_[_0xbb02('0x33')](_0x385e6d[_0xbb02('0x29')],_0x52dcb3[_0xbb02('0x32')]));if(_0x385e6d['query'][_0xbb02('0x36')]){_0x4ae924['where']=_[_0xbb02('0x35')](_0x4ae924[_0xbb02('0x34')],{'$or':_[_0xbb02('0x23')](_0x4ae924['attributes'],function(_0x14cc95){var _0x45aab5={};_0x45aab5[_0x14cc95]={'$like':'%'+_0x385e6d[_0xbb02('0x29')][_0xbb02('0x36')]+'%'};return _0x45aab5;})});}_0x4ae924=_[_0xbb02('0x35')]({},_0x4ae924,_0x385e6d[_0xbb02('0x37')]);return _0x43cc53[_0xbb02('0x47')](_0x4ae924);}})[_0xbb02('0x38')](function(_0x6bef4f){if(_0x6bef4f){_0x61d8e7=_0x6bef4f[_0xbb02('0x44')];if(!_0x385e6d['query'][_0xbb02('0x2e')](_0xbb02('0x2f'))){_0x4ae924[_0xbb02('0x19')]=qs[_0xbb02('0x19')](_0x385e6d[_0xbb02('0x29')][_0xbb02('0x19')]);_0x4ae924[_0xbb02('0x17')]=qs['offset'](_0x385e6d[_0xbb02('0x29')][_0xbb02('0x17')]);}return _0x43cc53[_0xbb02('0x47')](_0x4ae924);}})[_0xbb02('0x38')](function(_0x267778){if(_0x267778){return _0x267778?{'count':_0x61d8e7,'rows':_0x267778}:null;}})[_0xbb02('0x38')](respondWithResult(_0x36fa80,null))[_0xbb02('0x3b')](handleError(_0x36fa80,null));};exports['getTags']=function(_0x48aa9c,_0x2b1657,_0xa5b969){var _0x27767f={};var _0x399a24={};var _0x3026ff;var _0x347c57;return db[_0xbb02('0x24')][_0xbb02('0x43')]({'where':{'id':_0x48aa9c['params']['id']}})[_0xbb02('0x38')](handleEntityNotFound(_0x2b1657,null))[_0xbb02('0x38')](function(_0x53c5a2){if(_0x53c5a2){_0x3026ff=_0x53c5a2;_0x399a24[_0xbb02('0x28')]=_[_0xbb02('0x2a')](db['Tag'][_0xbb02('0x25')]);_0x399a24['query']=_[_0xbb02('0x2a')](_0x48aa9c[_0xbb02('0x29')]);_0x399a24[_0xbb02('0x32')]=_[_0xbb02('0x2c')](_0x399a24[_0xbb02('0x28')],_0x399a24[_0xbb02('0x29')]);_0x27767f[_0xbb02('0x2b')]=_['intersection'](_0x399a24[_0xbb02('0x28')],qs['fields'](_0x48aa9c[_0xbb02('0x29')][_0xbb02('0x2d')]));_0x27767f['attributes']=_0x27767f[_0xbb02('0x2b')]['length']?_0x27767f[_0xbb02('0x2b')]:_0x399a24[_0xbb02('0x28')];_0x27767f[_0xbb02('0x30')]=qs['sort'](_0x48aa9c[_0xbb02('0x29')]['sort']);_0x27767f[_0xbb02('0x34')]=qs['filters'](_[_0xbb02('0x33')](_0x48aa9c[_0xbb02('0x29')],_0x399a24[_0xbb02('0x32')]));if(_0x48aa9c['query'][_0xbb02('0x36')]){_0x27767f['where']=_[_0xbb02('0x35')](_0x27767f[_0xbb02('0x34')],{'$or':_[_0xbb02('0x23')](_0x27767f['attributes'],function(_0x5cebd1){var _0x16768d={};_0x16768d[_0x5cebd1]={'$like':'%'+_0x48aa9c[_0xbb02('0x29')][_0xbb02('0x36')]+'%'};return _0x16768d;})});}_0x27767f=_[_0xbb02('0x35')]({},_0x27767f,_0x48aa9c[_0xbb02('0x37')]);return _0x3026ff[_0xbb02('0x48')](_0x27767f);}})['then'](function(_0xb1ab51){if(_0xb1ab51){_0x347c57=_0xb1ab51[_0xbb02('0x44')];if(!_0x48aa9c[_0xbb02('0x29')][_0xbb02('0x2e')](_0xbb02('0x2f'))){_0x27767f[_0xbb02('0x19')]=qs[_0xbb02('0x19')](_0x48aa9c[_0xbb02('0x29')][_0xbb02('0x19')]);_0x27767f['offset']=qs[_0xbb02('0x17')](_0x48aa9c[_0xbb02('0x29')][_0xbb02('0x17')]);}return _0x3026ff[_0xbb02('0x48')](_0x27767f);}})[_0xbb02('0x38')](function(_0x40d494){if(_0x40d494){return _0x40d494?{'count':_0x347c57,'rows':_0x40d494}:null;}})[_0xbb02('0x38')](respondWithResult(_0x2b1657,null))[_0xbb02('0x3b')](handleError(_0x2b1657,null));};exports[_0xbb02('0x49')]=function(_0x51c4e6,_0x33f5b1,_0x46da19){if(_0x51c4e6[_0xbb02('0x40')]['id']){delete _0x51c4e6[_0xbb02('0x40')]['id'];}return db[_0xbb02('0x24')][_0xbb02('0x43')]({'where':{'id':_0x51c4e6[_0xbb02('0x3d')]['id']}})[_0xbb02('0x38')](handleEntityNotFound(_0x33f5b1,null))[_0xbb02('0x38')](function(_0x3530fa){if(_0x3530fa){return _0x3530fa[_0xbb02('0x49')](_0x51c4e6[_0xbb02('0x40')][_0xbb02('0x4a')]||[]);}return null;})[_0xbb02('0x38')](respondWithResult(_0x33f5b1,null))[_0xbb02('0x3b')](handleError(_0x33f5b1,null));};