7f7b2a94ad57835676b3520e9ae9b3fd530aab25
[motion2.git] / server / api / intDeskConfiguration / intDeskConfiguration.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 _0xf994=['ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','jayson/promise','client','http','request','then','info','DeskConfiguration,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','result','catch','sendStatus','status','end','json','count','offset','apply','reject','save','update','name','send','index','map','DeskConfiguration','rawAttributes','fieldName','type','key','query','keys','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','limit','sort','where','filters','pick','filter','merge','VIRTUAL','options','includeAll','include','show','params','create','body','destroy','find','getFields','findOne','DeskField','order','getSubjects','getDescriptions','getTags','Tag','setTags','ids','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','sox','to-csv'];(function(_0x19fba9,_0x2ca356){var _0x420bf6=function(_0x7a62ae){while(--_0x7a62ae){_0x19fba9['push'](_0x19fba9['shift']());}};_0x420bf6(++_0x2ca356);}(_0xf994,0x171));var _0x4f99=function(_0x556b95,_0x13849e){_0x556b95=_0x556b95-0x0;var _0x1c5bbb=_0xf994[_0x556b95];return _0x1c5bbb;};'use strict';var pdf=require(_0x4f99('0x0'));var emlformat=require(_0x4f99('0x1'));var rimraf=require(_0x4f99('0x2'));var zipdir=require(_0x4f99('0x3'));var jsonpatch=require(_0x4f99('0x4'));var rp=require(_0x4f99('0x5'));var moment=require(_0x4f99('0x6'));var BPromise=require('bluebird');var Mustache=require(_0x4f99('0x7'));var util=require(_0x4f99('0x8'));var path=require('path');var sox=require(_0x4f99('0x9'));var csv=require(_0x4f99('0xa'));var ejs=require(_0x4f99('0xb'));var fs=require('fs');var _=require(_0x4f99('0xc'));var squel=require(_0x4f99('0xd'));var crypto=require(_0x4f99('0xe'));var jsforce=require(_0x4f99('0xf'));var deskjs=require(_0x4f99('0x10'));var toCsv=require(_0x4f99('0xa'));var querystring=require('querystring');var Papa=require(_0x4f99('0x11'));var Redis=require(_0x4f99('0x12'));var authService=require(_0x4f99('0x13'));var qs=require(_0x4f99('0x14'));var as=require(_0x4f99('0x15'));var hardwareService=require(_0x4f99('0x16'));var logger=require(_0x4f99('0x17'))(_0x4f99('0x18'));var utils=require(_0x4f99('0x19'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];var jayson=require(_0x4f99('0x1a'));var client=jayson[_0x4f99('0x1b')][_0x4f99('0x1c')]({'port':0x232a});function respondWithRpcPromise(_0x1527a8,_0x204291,_0x89413d,_0x2e5b9c){return new BPromise(function(_0x1ee8c8,_0x330be4){var _0x148c63=_0x2e5b9c||client;return _0x148c63[_0x4f99('0x1d')](_0x1527a8,_0x89413d)[_0x4f99('0x1e')](function(_0x29a607){logger[_0x4f99('0x1f')](_0x4f99('0x20'),_0x204291,_0x4f99('0x21'));logger['debug']('DeskConfiguration,\x20%s,\x20%s,\x20%s',_0x204291,'request\x20sent',JSON[_0x4f99('0x22')](_0x29a607));if(_0x29a607[_0x4f99('0x23')]){if(_0x29a607['error'][_0x4f99('0x24')]===0x1f4){logger[_0x4f99('0x23')](_0x4f99('0x20'),_0x204291,_0x29a607['error']['message']);return _0x330be4(_0x29a607[_0x4f99('0x23')][_0x4f99('0x25')]);}logger[_0x4f99('0x23')](_0x4f99('0x20'),_0x204291,_0x29a607[_0x4f99('0x23')]['message']);return _0x1ee8c8(_0x29a607['error']['message']);}else{logger[_0x4f99('0x1f')](_0x4f99('0x20'),_0x204291,_0x4f99('0x21'));_0x1ee8c8(_0x29a607[_0x4f99('0x26')]['message']);}})[_0x4f99('0x27')](function(_0xbec019){logger[_0x4f99('0x23')](_0x4f99('0x20'),_0x204291,_0xbec019);_0x330be4(_0xbec019);});});}function respondWithStatusCode(_0x55b355,_0x495164){_0x495164=_0x495164||0xcc;return function(_0x241708){if(_0x241708){return _0x55b355[_0x4f99('0x28')](_0x495164);}return _0x55b355[_0x4f99('0x29')](_0x495164)[_0x4f99('0x2a')]();};}function respondWithResult(_0x5ad839,_0x5ffa0f){_0x5ffa0f=_0x5ffa0f||0xc8;return function(_0x27ecef){if(_0x27ecef){return _0x5ad839[_0x4f99('0x29')](_0x5ffa0f)[_0x4f99('0x2b')](_0x27ecef);}};}function respondWithFilteredResult(_0x431fc8,_0x31d58e){return function(_0x4caabd){if(_0x4caabd){var _0x3d27bf=_0x4caabd[_0x4f99('0x2c')],_0x44f2db=_0x31d58e[_0x4f99('0x2d')],_0x4ff6b6=_0x31d58e['offset']+_0x31d58e['limit'],_0x42dc43;if(_0x4ff6b6>=_0x3d27bf){_0x4ff6b6=_0x3d27bf;_0x42dc43=0xc8;}else{_0x42dc43=0xce;}_0x431fc8[_0x4f99('0x29')](_0x42dc43);return _0x431fc8['set']('Content-Range',_0x44f2db+'-'+_0x4ff6b6+'/'+_0x3d27bf)['json'](_0x4caabd);}return null;};}function patchUpdates(_0x1d0204){return function(_0x370f69){try{jsonpatch[_0x4f99('0x2e')](_0x370f69,_0x1d0204,!![]);}catch(_0x328500){return BPromise[_0x4f99('0x2f')](_0x328500);}return _0x370f69[_0x4f99('0x30')]();};}function saveUpdates(_0x8b7076,_0x49bf1b){return function(_0x231e3d){if(_0x231e3d){return _0x231e3d[_0x4f99('0x31')](_0x8b7076)['then'](function(_0x571fbd){return _0x571fbd;});}return null;};}function removeEntity(_0x3ea02b,_0x251e27){return function(_0x39564b){if(_0x39564b){return _0x39564b['destroy']()[_0x4f99('0x1e')](function(){_0x3ea02b[_0x4f99('0x29')](0xcc)[_0x4f99('0x2a')]();});}};}function handleEntityNotFound(_0xdd9a88,_0x2a2898){return function(_0xa0c39d){if(!_0xa0c39d){_0xdd9a88[_0x4f99('0x28')](0x194);}return _0xa0c39d;};}function handleError(_0xe3f802,_0x2cd159){_0x2cd159=_0x2cd159||0x1f4;return function(_0x5d0e32){logger[_0x4f99('0x23')](_0x5d0e32['stack']);if(_0x5d0e32[_0x4f99('0x32')]){delete _0x5d0e32[_0x4f99('0x32')];}_0xe3f802['status'](_0x2cd159)[_0x4f99('0x33')](_0x5d0e32);};}exports[_0x4f99('0x34')]=function(_0xc9b436,_0x144759){var _0x3daaf8={},_0x50452d={},_0x2f7192={'count':0x0,'rows':[]};var _0x3a9443=_[_0x4f99('0x35')](db[_0x4f99('0x36')][_0x4f99('0x37')],function(_0x44445b){return{'name':_0x44445b[_0x4f99('0x38')],'type':_0x44445b[_0x4f99('0x39')][_0x4f99('0x3a')]};});_0x50452d['model']=_[_0x4f99('0x35')](_0x3a9443,_0x4f99('0x32'));_0x50452d[_0x4f99('0x3b')]=_[_0x4f99('0x3c')](_0xc9b436[_0x4f99('0x3b')]);_0x50452d['filters']=_[_0x4f99('0x3d')](_0x50452d[_0x4f99('0x3e')],_0x50452d[_0x4f99('0x3b')]);_0x3daaf8[_0x4f99('0x3f')]=_[_0x4f99('0x3d')](_0x50452d[_0x4f99('0x3e')],qs[_0x4f99('0x40')](_0xc9b436[_0x4f99('0x3b')][_0x4f99('0x40')]));_0x3daaf8[_0x4f99('0x3f')]=_0x3daaf8['attributes'][_0x4f99('0x41')]?_0x3daaf8[_0x4f99('0x3f')]:_0x50452d[_0x4f99('0x3e')];if(!_0xc9b436['query'][_0x4f99('0x42')](_0x4f99('0x43'))){_0x3daaf8[_0x4f99('0x44')]=qs[_0x4f99('0x44')](_0xc9b436[_0x4f99('0x3b')][_0x4f99('0x44')]);_0x3daaf8[_0x4f99('0x2d')]=qs[_0x4f99('0x2d')](_0xc9b436[_0x4f99('0x3b')][_0x4f99('0x2d')]);}_0x3daaf8['order']=qs[_0x4f99('0x45')](_0xc9b436['query']['sort']);_0x3daaf8[_0x4f99('0x46')]=qs[_0x4f99('0x47')](_[_0x4f99('0x48')](_0xc9b436[_0x4f99('0x3b')],_0x50452d[_0x4f99('0x47')]),_0x3a9443);if(_0xc9b436['query'][_0x4f99('0x49')]){_0x3daaf8[_0x4f99('0x46')]=_[_0x4f99('0x4a')](_0x3daaf8['where'],{'$or':_[_0x4f99('0x35')](_0x3a9443,function(_0x457b8d){if(_0x457b8d[_0x4f99('0x39')]!==_0x4f99('0x4b')){var _0xb7f223={};_0xb7f223[_0x457b8d[_0x4f99('0x32')]]={'$like':'%'+_0xc9b436[_0x4f99('0x3b')]['filter']+'%'};return _0xb7f223;}})});}_0x3daaf8=_[_0x4f99('0x4a')]({},_0x3daaf8,_0xc9b436[_0x4f99('0x4c')]);var _0x1d03ad={'where':_0x3daaf8[_0x4f99('0x46')]};return db['DeskConfiguration'][_0x4f99('0x2c')](_0x1d03ad)[_0x4f99('0x1e')](function(_0x3c5c7f){_0x2f7192[_0x4f99('0x2c')]=_0x3c5c7f;if(_0xc9b436['query'][_0x4f99('0x4d')]){_0x3daaf8[_0x4f99('0x4e')]=[{'all':!![]}];}return db['DeskConfiguration']['findAll'](_0x3daaf8);})[_0x4f99('0x1e')](function(_0x3b36b8){_0x2f7192['rows']=_0x3b36b8;return _0x2f7192;})[_0x4f99('0x1e')](respondWithFilteredResult(_0x144759,_0x3daaf8))[_0x4f99('0x27')](handleError(_0x144759,null));};exports[_0x4f99('0x4f')]=function(_0x4e0d26,_0x159cdd){var _0x478709={'raw':![],'where':{'id':_0x4e0d26[_0x4f99('0x50')]['id']}},_0x207fb6={};_0x207fb6[_0x4f99('0x3e')]=_[_0x4f99('0x3c')](db[_0x4f99('0x36')][_0x4f99('0x37')]);_0x207fb6[_0x4f99('0x3b')]=_[_0x4f99('0x3c')](_0x4e0d26['query']);_0x207fb6[_0x4f99('0x47')]=_[_0x4f99('0x3d')](_0x207fb6[_0x4f99('0x3e')],_0x207fb6[_0x4f99('0x3b')]);_0x478709[_0x4f99('0x3f')]=_['intersection'](_0x207fb6[_0x4f99('0x3e')],qs[_0x4f99('0x40')](_0x4e0d26[_0x4f99('0x3b')][_0x4f99('0x40')]));_0x478709[_0x4f99('0x3f')]=_0x478709['attributes']['length']?_0x478709['attributes']:_0x207fb6[_0x4f99('0x3e')];if(_0x4e0d26['query']['includeAll']){_0x478709['include']=[{'all':!![]}];}_0x478709=_['merge']({},_0x478709,_0x4e0d26[_0x4f99('0x4c')]);return db[_0x4f99('0x36')]['find'](_0x478709)[_0x4f99('0x1e')](handleEntityNotFound(_0x159cdd,null))[_0x4f99('0x1e')](respondWithResult(_0x159cdd,null))['catch'](handleError(_0x159cdd,null));};exports['create']=function(_0xe7859b,_0xc6cb52){return db[_0x4f99('0x36')][_0x4f99('0x51')](_0xe7859b['body'],{})[_0x4f99('0x1e')](respondWithResult(_0xc6cb52,0xc9))[_0x4f99('0x27')](handleError(_0xc6cb52,null));};exports[_0x4f99('0x31')]=function(_0x459092,_0x523de8){if(_0x459092[_0x4f99('0x52')]['id']){delete _0x459092[_0x4f99('0x52')]['id'];}return db[_0x4f99('0x36')]['find']({'where':{'id':_0x459092['params']['id']}})['then'](handleEntityNotFound(_0x523de8,null))['then'](saveUpdates(_0x459092['body'],null))[_0x4f99('0x1e')](respondWithResult(_0x523de8,null))[_0x4f99('0x27')](handleError(_0x523de8,null));};exports[_0x4f99('0x53')]=function(_0x178d2a,_0x39d729){return db[_0x4f99('0x36')][_0x4f99('0x54')]({'where':{'id':_0x178d2a[_0x4f99('0x50')]['id']}})[_0x4f99('0x1e')](handleEntityNotFound(_0x39d729,null))[_0x4f99('0x1e')](removeEntity(_0x39d729,null))[_0x4f99('0x27')](handleError(_0x39d729,null));};exports[_0x4f99('0x55')]=function(_0x54043b,_0x1cbd69,_0x112beb){var _0x1aed85={};var _0x24b646={};var _0x5379cd;var _0x391eec;return db[_0x4f99('0x36')][_0x4f99('0x56')]({'where':{'id':_0x54043b[_0x4f99('0x50')]['id']}})[_0x4f99('0x1e')](handleEntityNotFound(_0x1cbd69,null))[_0x4f99('0x1e')](function(_0x39cf8f){if(_0x39cf8f){_0x5379cd=_0x39cf8f;_0x24b646[_0x4f99('0x3e')]=_[_0x4f99('0x3c')](db[_0x4f99('0x57')][_0x4f99('0x37')]);_0x24b646[_0x4f99('0x3b')]=_[_0x4f99('0x3c')](_0x54043b[_0x4f99('0x3b')]);_0x24b646['filters']=_[_0x4f99('0x3d')](_0x24b646['model'],_0x24b646['query']);_0x1aed85['attributes']=_['intersection'](_0x24b646[_0x4f99('0x3e')],qs['fields'](_0x54043b[_0x4f99('0x3b')]['fields']));_0x1aed85[_0x4f99('0x3f')]=_0x1aed85[_0x4f99('0x3f')][_0x4f99('0x41')]?_0x1aed85[_0x4f99('0x3f')]:_0x24b646[_0x4f99('0x3e')];_0x1aed85[_0x4f99('0x58')]=qs[_0x4f99('0x45')](_0x54043b['query']['sort']);_0x1aed85['where']=qs[_0x4f99('0x47')](_[_0x4f99('0x48')](_0x54043b['query'],_0x24b646['filters']));if(_0x54043b['query'][_0x4f99('0x49')]){_0x1aed85[_0x4f99('0x46')]=_[_0x4f99('0x4a')](_0x1aed85[_0x4f99('0x46')],{'$or':_[_0x4f99('0x35')](_0x1aed85[_0x4f99('0x3f')],function(_0x40f2e0){var _0x815ae5={};_0x815ae5[_0x40f2e0]={'$like':'%'+_0x54043b[_0x4f99('0x3b')]['filter']+'%'};return _0x815ae5;})});}_0x1aed85=_[_0x4f99('0x4a')]({},_0x1aed85,_0x54043b['options']);return _0x5379cd[_0x4f99('0x55')](_0x1aed85);}})[_0x4f99('0x1e')](function(_0x56c683){if(_0x56c683){_0x391eec=_0x56c683[_0x4f99('0x41')];if(!_0x54043b[_0x4f99('0x3b')][_0x4f99('0x42')](_0x4f99('0x43'))){_0x1aed85[_0x4f99('0x44')]=qs[_0x4f99('0x44')](_0x54043b[_0x4f99('0x3b')]['limit']);_0x1aed85['offset']=qs[_0x4f99('0x2d')](_0x54043b[_0x4f99('0x3b')]['offset']);}return _0x5379cd['getFields'](_0x1aed85);}})[_0x4f99('0x1e')](function(_0x50329b){if(_0x50329b){return _0x50329b?{'count':_0x391eec,'rows':_0x50329b}:null;}})[_0x4f99('0x1e')](respondWithResult(_0x1cbd69,null))[_0x4f99('0x27')](handleError(_0x1cbd69,null));};exports['getSubjects']=function(_0x42ab85,_0x106c23,_0x440467){var _0x128531={};var _0x370773={};var _0x463304;var _0x22b9fe;return db['DeskConfiguration'][_0x4f99('0x56')]({'where':{'id':_0x42ab85['params']['id']}})[_0x4f99('0x1e')](handleEntityNotFound(_0x106c23,null))[_0x4f99('0x1e')](function(_0x427259){if(_0x427259){_0x463304=_0x427259;_0x370773['model']=_[_0x4f99('0x3c')](db[_0x4f99('0x57')][_0x4f99('0x37')]);_0x370773[_0x4f99('0x3b')]=_[_0x4f99('0x3c')](_0x42ab85[_0x4f99('0x3b')]);_0x370773[_0x4f99('0x47')]=_[_0x4f99('0x3d')](_0x370773[_0x4f99('0x3e')],_0x370773[_0x4f99('0x3b')]);_0x128531[_0x4f99('0x3f')]=_['intersection'](_0x370773['model'],qs['fields'](_0x42ab85[_0x4f99('0x3b')][_0x4f99('0x40')]));_0x128531[_0x4f99('0x3f')]=_0x128531['attributes'][_0x4f99('0x41')]?_0x128531['attributes']:_0x370773[_0x4f99('0x3e')];_0x128531[_0x4f99('0x58')]=qs['sort'](_0x42ab85[_0x4f99('0x3b')][_0x4f99('0x45')]);_0x128531[_0x4f99('0x46')]=qs[_0x4f99('0x47')](_[_0x4f99('0x48')](_0x42ab85['query'],_0x370773[_0x4f99('0x47')]));if(_0x42ab85[_0x4f99('0x3b')][_0x4f99('0x49')]){_0x128531[_0x4f99('0x46')]=_['merge'](_0x128531['where'],{'$or':_[_0x4f99('0x35')](_0x128531[_0x4f99('0x3f')],function(_0x5d3708){var _0x2a24f9={};_0x2a24f9[_0x5d3708]={'$like':'%'+_0x42ab85[_0x4f99('0x3b')][_0x4f99('0x49')]+'%'};return _0x2a24f9;})});}_0x128531=_[_0x4f99('0x4a')]({},_0x128531,_0x42ab85[_0x4f99('0x4c')]);return _0x463304[_0x4f99('0x59')](_0x128531);}})[_0x4f99('0x1e')](function(_0xc4ed8e){if(_0xc4ed8e){_0x22b9fe=_0xc4ed8e[_0x4f99('0x41')];if(!_0x42ab85[_0x4f99('0x3b')][_0x4f99('0x42')]('nolimit')){_0x128531[_0x4f99('0x44')]=qs['limit'](_0x42ab85[_0x4f99('0x3b')][_0x4f99('0x44')]);_0x128531[_0x4f99('0x2d')]=qs[_0x4f99('0x2d')](_0x42ab85['query'][_0x4f99('0x2d')]);}return _0x463304[_0x4f99('0x59')](_0x128531);}})['then'](function(_0x125afe){if(_0x125afe){return _0x125afe?{'count':_0x22b9fe,'rows':_0x125afe}:null;}})[_0x4f99('0x1e')](respondWithResult(_0x106c23,null))[_0x4f99('0x27')](handleError(_0x106c23,null));};exports[_0x4f99('0x5a')]=function(_0x4880c8,_0xda33c0,_0x32170a){var _0x51795c={};var _0xbf5cde={};var _0x38c2cf;var _0x1b7138;return db['DeskConfiguration'][_0x4f99('0x56')]({'where':{'id':_0x4880c8['params']['id']}})[_0x4f99('0x1e')](handleEntityNotFound(_0xda33c0,null))[_0x4f99('0x1e')](function(_0x15b0ae){if(_0x15b0ae){_0x38c2cf=_0x15b0ae;_0xbf5cde[_0x4f99('0x3e')]=_[_0x4f99('0x3c')](db[_0x4f99('0x57')][_0x4f99('0x37')]);_0xbf5cde['query']=_[_0x4f99('0x3c')](_0x4880c8['query']);_0xbf5cde[_0x4f99('0x47')]=_[_0x4f99('0x3d')](_0xbf5cde[_0x4f99('0x3e')],_0xbf5cde[_0x4f99('0x3b')]);_0x51795c[_0x4f99('0x3f')]=_[_0x4f99('0x3d')](_0xbf5cde[_0x4f99('0x3e')],qs[_0x4f99('0x40')](_0x4880c8['query'][_0x4f99('0x40')]));_0x51795c[_0x4f99('0x3f')]=_0x51795c[_0x4f99('0x3f')][_0x4f99('0x41')]?_0x51795c[_0x4f99('0x3f')]:_0xbf5cde[_0x4f99('0x3e')];_0x51795c[_0x4f99('0x58')]=qs['sort'](_0x4880c8[_0x4f99('0x3b')][_0x4f99('0x45')]);_0x51795c[_0x4f99('0x46')]=qs[_0x4f99('0x47')](_[_0x4f99('0x48')](_0x4880c8['query'],_0xbf5cde['filters']));if(_0x4880c8[_0x4f99('0x3b')]['filter']){_0x51795c['where']=_[_0x4f99('0x4a')](_0x51795c[_0x4f99('0x46')],{'$or':_['map'](_0x51795c[_0x4f99('0x3f')],function(_0x367169){var _0x3588f7={};_0x3588f7[_0x367169]={'$like':'%'+_0x4880c8['query'][_0x4f99('0x49')]+'%'};return _0x3588f7;})});}_0x51795c=_[_0x4f99('0x4a')]({},_0x51795c,_0x4880c8[_0x4f99('0x4c')]);return _0x38c2cf[_0x4f99('0x5a')](_0x51795c);}})[_0x4f99('0x1e')](function(_0x485c01){if(_0x485c01){_0x1b7138=_0x485c01[_0x4f99('0x41')];if(!_0x4880c8[_0x4f99('0x3b')]['hasOwnProperty'](_0x4f99('0x43'))){_0x51795c[_0x4f99('0x44')]=qs[_0x4f99('0x44')](_0x4880c8[_0x4f99('0x3b')][_0x4f99('0x44')]);_0x51795c[_0x4f99('0x2d')]=qs[_0x4f99('0x2d')](_0x4880c8[_0x4f99('0x3b')][_0x4f99('0x2d')]);}return _0x38c2cf[_0x4f99('0x5a')](_0x51795c);}})[_0x4f99('0x1e')](function(_0x30ad79){if(_0x30ad79){return _0x30ad79?{'count':_0x1b7138,'rows':_0x30ad79}:null;}})[_0x4f99('0x1e')](respondWithResult(_0xda33c0,null))[_0x4f99('0x27')](handleError(_0xda33c0,null));};exports[_0x4f99('0x5b')]=function(_0x3e27eb,_0x1d0df9,_0x4014da){var _0x4304ed={};var _0x489beb={};var _0x54402c;var _0x2c61b9;return db['DeskConfiguration']['findOne']({'where':{'id':_0x3e27eb[_0x4f99('0x50')]['id']}})[_0x4f99('0x1e')](handleEntityNotFound(_0x1d0df9,null))[_0x4f99('0x1e')](function(_0x22e329){if(_0x22e329){_0x54402c=_0x22e329;_0x489beb['model']=_['keys'](db[_0x4f99('0x5c')][_0x4f99('0x37')]);_0x489beb[_0x4f99('0x3b')]=_[_0x4f99('0x3c')](_0x3e27eb[_0x4f99('0x3b')]);_0x489beb['filters']=_[_0x4f99('0x3d')](_0x489beb[_0x4f99('0x3e')],_0x489beb['query']);_0x4304ed[_0x4f99('0x3f')]=_[_0x4f99('0x3d')](_0x489beb[_0x4f99('0x3e')],qs['fields'](_0x3e27eb[_0x4f99('0x3b')]['fields']));_0x4304ed[_0x4f99('0x3f')]=_0x4304ed[_0x4f99('0x3f')]['length']?_0x4304ed[_0x4f99('0x3f')]:_0x489beb[_0x4f99('0x3e')];_0x4304ed[_0x4f99('0x58')]=qs[_0x4f99('0x45')](_0x3e27eb[_0x4f99('0x3b')]['sort']);_0x4304ed[_0x4f99('0x46')]=qs[_0x4f99('0x47')](_[_0x4f99('0x48')](_0x3e27eb['query'],_0x489beb[_0x4f99('0x47')]));if(_0x3e27eb[_0x4f99('0x3b')][_0x4f99('0x49')]){_0x4304ed[_0x4f99('0x46')]=_[_0x4f99('0x4a')](_0x4304ed[_0x4f99('0x46')],{'$or':_[_0x4f99('0x35')](_0x4304ed[_0x4f99('0x3f')],function(_0x1c1f81){var _0x16747a={};_0x16747a[_0x1c1f81]={'$like':'%'+_0x3e27eb[_0x4f99('0x3b')][_0x4f99('0x49')]+'%'};return _0x16747a;})});}_0x4304ed=_[_0x4f99('0x4a')]({},_0x4304ed,_0x3e27eb['options']);return _0x54402c[_0x4f99('0x5b')](_0x4304ed);}})['then'](function(_0x273f80){if(_0x273f80){_0x2c61b9=_0x273f80[_0x4f99('0x41')];if(!_0x3e27eb[_0x4f99('0x3b')][_0x4f99('0x42')](_0x4f99('0x43'))){_0x4304ed[_0x4f99('0x44')]=qs[_0x4f99('0x44')](_0x3e27eb[_0x4f99('0x3b')][_0x4f99('0x44')]);_0x4304ed[_0x4f99('0x2d')]=qs['offset'](_0x3e27eb[_0x4f99('0x3b')]['offset']);}return _0x54402c[_0x4f99('0x5b')](_0x4304ed);}})['then'](function(_0x5a501c){if(_0x5a501c){return _0x5a501c?{'count':_0x2c61b9,'rows':_0x5a501c}:null;}})[_0x4f99('0x1e')](respondWithResult(_0x1d0df9,null))[_0x4f99('0x27')](handleError(_0x1d0df9,null));};exports[_0x4f99('0x5d')]=function(_0x34acff,_0x310464,_0x588449){if(_0x34acff['body']['id']){delete _0x34acff['body']['id'];}return db[_0x4f99('0x36')][_0x4f99('0x56')]({'where':{'id':_0x34acff[_0x4f99('0x50')]['id']}})['then'](handleEntityNotFound(_0x310464,null))['then'](function(_0x26fea6){if(_0x26fea6){return _0x26fea6[_0x4f99('0x5d')](_0x34acff['body'][_0x4f99('0x5e')]||[]);}return null;})[_0x4f99('0x1e')](respondWithResult(_0x310464,null))['catch'](handleError(_0x310464,null));};