4d527555dd8e27cb215433dda80f7c1cbdf60eb1
[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 _0x69f4=['error','message','request\x20sent','result','catch','sendStatus','status','end','json','offset','limit','set','apply','reject','save','destroy','stack','name','send','index','map','FreshdeskConfiguration','rawAttributes','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','pick','filter','where','merge','VIRTUAL','options','count','includeAll','include','findAll','rows','find','create','update','body','params','getFields','FreshdeskField','order','getSubjects','findOne','getDescriptions','getTags','Tag','setTags','html-pdf','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','jayson/promise','client','http','test','Sequelize','ValidationError','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','request','then','info','FreshdeskConfiguration,\x20%s,\x20%s','debug','FreshdeskConfiguration,\x20%s,\x20%s,\x20%s','code'];(function(_0x2ee922,_0x3b3c54){var _0x49e807=function(_0x36eb7b){while(--_0x36eb7b){_0x2ee922['push'](_0x2ee922['shift']());}};_0x49e807(++_0x3b3c54);}(_0x69f4,0xa1));var _0x469f=function(_0x309b09,_0xe4c181){_0x309b09=_0x309b09-0x0;var _0x7b38d7=_0x69f4[_0x309b09];return _0x7b38d7;};'use strict';var pdf=require(_0x469f('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x469f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x469f('0x2'));var rp=require(_0x469f('0x3'));var moment=require(_0x469f('0x4'));var BPromise=require(_0x469f('0x5'));var Mustache=require(_0x469f('0x6'));var util=require(_0x469f('0x7'));var path=require(_0x469f('0x8'));var sox=require(_0x469f('0x9'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0x469f('0xa'));var crypto=require(_0x469f('0xb'));var jsforce=require(_0x469f('0xc'));var deskjs=require(_0x469f('0xd'));var toCsv=require('to-csv');var querystring=require(_0x469f('0xe'));var Papa=require(_0x469f('0xf'));var Redis=require('ioredis');var authService=require(_0x469f('0x10'));var qs=require(_0x469f('0x11'));var as=require(_0x469f('0x12'));var hardwareService=require(_0x469f('0x13'));var logger=require(_0x469f('0x14'))(_0x469f('0x15'));var utils=require(_0x469f('0x16'));var config=require(_0x469f('0x17'));var db=require(_0x469f('0x18'))['db'];var jayson=require(_0x469f('0x19'));var client=jayson[_0x469f('0x1a')][_0x469f('0x1b')]({'port':0x232a});function checkPasswordPattern(_0x3718b8,_0x542d50,_0x442355){if(_0x442355){var _0x3f2f3a=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x3f2f3a[_0x469f('0x1c')](_0x542d50)){return _0x3718b8;}else{throw new db[(_0x469f('0x1d'))][(_0x469f('0x1e'))](_0x469f('0x1f'));}}else{return _0x3718b8;}}function respondWithRpcPromise(_0x240d57,_0x305579,_0x360a0a,_0x335cc9){return new BPromise(function(_0x3f5274,_0x4fb43d){var _0x3f226f=_0x335cc9||client;return _0x3f226f[_0x469f('0x20')](_0x240d57,_0x360a0a)[_0x469f('0x21')](function(_0x27baea){logger[_0x469f('0x22')](_0x469f('0x23'),_0x305579,'request\x20sent');logger[_0x469f('0x24')](_0x469f('0x25'),_0x305579,'request\x20sent',JSON['stringify'](_0x27baea));if(_0x27baea['error']){if(_0x27baea['error'][_0x469f('0x26')]===0x1f4){logger[_0x469f('0x27')]('FreshdeskConfiguration,\x20%s,\x20%s',_0x305579,_0x27baea['error'][_0x469f('0x28')]);return _0x4fb43d(_0x27baea[_0x469f('0x27')][_0x469f('0x28')]);}logger[_0x469f('0x27')](_0x469f('0x23'),_0x305579,_0x27baea['error'][_0x469f('0x28')]);return _0x3f5274(_0x27baea['error'][_0x469f('0x28')]);}else{logger['info']('FreshdeskConfiguration,\x20%s,\x20%s',_0x305579,_0x469f('0x29'));_0x3f5274(_0x27baea[_0x469f('0x2a')]['message']);}})[_0x469f('0x2b')](function(_0x515322){logger[_0x469f('0x27')](_0x469f('0x23'),_0x305579,_0x515322);_0x4fb43d(_0x515322);});});}function respondWithStatusCode(_0x2a09fa,_0x3c3c7c){_0x3c3c7c=_0x3c3c7c||0xcc;return function(_0x562b71){if(_0x562b71){return _0x2a09fa[_0x469f('0x2c')](_0x3c3c7c);}return _0x2a09fa[_0x469f('0x2d')](_0x3c3c7c)[_0x469f('0x2e')]();};}function respondWithResult(_0x9f507c,_0x29fcb1){_0x29fcb1=_0x29fcb1||0xc8;return function(_0x188ad6){if(_0x188ad6){return _0x9f507c[_0x469f('0x2d')](_0x29fcb1)[_0x469f('0x2f')](_0x188ad6);}};}function respondWithFilteredResult(_0x1ce9e6,_0x53f9ab){return function(_0x4c3a92){if(_0x4c3a92){var _0x453ea0=_0x4c3a92['count'],_0x4a274f=_0x53f9ab[_0x469f('0x30')],_0x40483c=_0x53f9ab[_0x469f('0x30')]+_0x53f9ab[_0x469f('0x31')],_0x4ca58e;if(_0x40483c>=_0x453ea0){_0x40483c=_0x453ea0;_0x4ca58e=0xc8;}else{_0x4ca58e=0xce;}_0x1ce9e6[_0x469f('0x2d')](_0x4ca58e);return _0x1ce9e6[_0x469f('0x32')]('Content-Range',_0x4a274f+'-'+_0x40483c+'/'+_0x453ea0)[_0x469f('0x2f')](_0x4c3a92);}return null;};}function patchUpdates(_0x2eb27b){return function(_0x4097a0){try{jsonpatch[_0x469f('0x33')](_0x4097a0,_0x2eb27b,!![]);}catch(_0xb741f){return BPromise[_0x469f('0x34')](_0xb741f);}return _0x4097a0[_0x469f('0x35')]();};}function saveUpdates(_0x150d85,_0x410861){return function(_0x407458){if(_0x407458){return _0x407458['update'](_0x150d85)[_0x469f('0x21')](function(_0x417c06){return _0x417c06;});}return null;};}function removeEntity(_0x3422c5,_0x21de11){return function(_0x3ef793){if(_0x3ef793){return _0x3ef793[_0x469f('0x36')]()[_0x469f('0x21')](function(){_0x3422c5[_0x469f('0x2d')](0xcc)[_0x469f('0x2e')]();});}};}function handleEntityNotFound(_0x42b823,_0x327852){return function(_0x465cb){if(!_0x465cb){_0x42b823[_0x469f('0x2c')](0x194);}return _0x465cb;};}function handleError(_0x3e5b93,_0x14df9a){_0x14df9a=_0x14df9a||0x1f4;return function(_0x1d53e0){logger[_0x469f('0x27')](_0x1d53e0[_0x469f('0x37')]);if(_0x1d53e0[_0x469f('0x38')]){delete _0x1d53e0[_0x469f('0x38')];}_0x3e5b93['status'](_0x14df9a)[_0x469f('0x39')](_0x1d53e0);};}exports[_0x469f('0x3a')]=function(_0x464bd0,_0x5f315c){var _0x350dc7={},_0x5c9c6f={},_0x219da5={'count':0x0,'rows':[]};var _0x39e682=_[_0x469f('0x3b')](db[_0x469f('0x3c')][_0x469f('0x3d')],function(_0x1d968a){return{'name':_0x1d968a['fieldName'],'type':_0x1d968a[_0x469f('0x3e')][_0x469f('0x3f')]};});_0x5c9c6f[_0x469f('0x40')]=_[_0x469f('0x3b')](_0x39e682,'name');_0x5c9c6f[_0x469f('0x41')]=_[_0x469f('0x42')](_0x464bd0[_0x469f('0x41')]);_0x5c9c6f[_0x469f('0x43')]=_[_0x469f('0x44')](_0x5c9c6f['model'],_0x5c9c6f[_0x469f('0x41')]);_0x350dc7[_0x469f('0x45')]=_['intersection'](_0x5c9c6f[_0x469f('0x40')],qs[_0x469f('0x46')](_0x464bd0['query'][_0x469f('0x46')]));_0x350dc7[_0x469f('0x45')]=_0x350dc7['attributes'][_0x469f('0x47')]?_0x350dc7[_0x469f('0x45')]:_0x5c9c6f[_0x469f('0x40')];if(!_0x464bd0[_0x469f('0x41')][_0x469f('0x48')](_0x469f('0x49'))){_0x350dc7['limit']=qs[_0x469f('0x31')](_0x464bd0[_0x469f('0x41')][_0x469f('0x31')]);_0x350dc7['offset']=qs[_0x469f('0x30')](_0x464bd0['query'][_0x469f('0x30')]);}_0x350dc7['order']=qs[_0x469f('0x4a')](_0x464bd0['query'][_0x469f('0x4a')]);_0x350dc7['where']=qs['filters'](_[_0x469f('0x4b')](_0x464bd0['query'],_0x5c9c6f[_0x469f('0x43')]));if(_0x464bd0[_0x469f('0x41')][_0x469f('0x4c')]){_0x350dc7[_0x469f('0x4d')]=_[_0x469f('0x4e')](_0x350dc7[_0x469f('0x4d')],{'$or':_['map'](_0x39e682,function(_0x435ff4){if(_0x435ff4[_0x469f('0x3e')]!==_0x469f('0x4f')){var _0x3a768f={};_0x3a768f[_0x435ff4[_0x469f('0x38')]]={'$like':'%'+_0x464bd0[_0x469f('0x41')][_0x469f('0x4c')]+'%'};return _0x3a768f;}})});}_0x350dc7=_[_0x469f('0x4e')]({},_0x350dc7,_0x464bd0[_0x469f('0x50')]);var _0x58ea69={'where':_0x350dc7['where']};return db[_0x469f('0x3c')]['count'](_0x58ea69)[_0x469f('0x21')](function(_0x121b65){_0x219da5[_0x469f('0x51')]=_0x121b65;if(_0x464bd0['query'][_0x469f('0x52')]){_0x350dc7[_0x469f('0x53')]=[{'all':!![]}];}return db['FreshdeskConfiguration'][_0x469f('0x54')](_0x350dc7);})['then'](function(_0x11307a){_0x219da5[_0x469f('0x55')]=_0x11307a;return _0x219da5;})[_0x469f('0x21')](respondWithFilteredResult(_0x5f315c,_0x350dc7))[_0x469f('0x2b')](handleError(_0x5f315c,null));};exports['show']=function(_0x552308,_0x38bfa4){var _0x5164b3={'raw':![],'where':{'id':_0x552308['params']['id']}},_0x5b77a7={};_0x5b77a7[_0x469f('0x40')]=_[_0x469f('0x42')](db[_0x469f('0x3c')][_0x469f('0x3d')]);_0x5b77a7[_0x469f('0x41')]=_['keys'](_0x552308[_0x469f('0x41')]);_0x5b77a7[_0x469f('0x43')]=_[_0x469f('0x44')](_0x5b77a7[_0x469f('0x40')],_0x5b77a7['query']);_0x5164b3['attributes']=_['intersection'](_0x5b77a7[_0x469f('0x40')],qs['fields'](_0x552308['query'][_0x469f('0x46')]));_0x5164b3[_0x469f('0x45')]=_0x5164b3['attributes'][_0x469f('0x47')]?_0x5164b3[_0x469f('0x45')]:_0x5b77a7[_0x469f('0x40')];if(_0x552308[_0x469f('0x41')][_0x469f('0x52')]){_0x5164b3[_0x469f('0x53')]=[{'all':!![]}];}_0x5164b3=_['merge']({},_0x5164b3,_0x552308[_0x469f('0x50')]);return db[_0x469f('0x3c')][_0x469f('0x56')](_0x5164b3)[_0x469f('0x21')](handleEntityNotFound(_0x38bfa4,null))[_0x469f('0x21')](respondWithResult(_0x38bfa4,null))[_0x469f('0x2b')](handleError(_0x38bfa4,null));};exports[_0x469f('0x57')]=function(_0x1bd5d8,_0xf0e7fa){return db[_0x469f('0x3c')]['create'](_0x1bd5d8['body'],{})[_0x469f('0x21')](respondWithResult(_0xf0e7fa,0xc9))[_0x469f('0x2b')](handleError(_0xf0e7fa,null));};exports[_0x469f('0x58')]=function(_0x134a13,_0x5b699){if(_0x134a13[_0x469f('0x59')]['id']){delete _0x134a13[_0x469f('0x59')]['id'];}return db[_0x469f('0x3c')]['find']({'where':{'id':_0x134a13[_0x469f('0x5a')]['id']}})['then'](handleEntityNotFound(_0x5b699,null))[_0x469f('0x21')](saveUpdates(_0x134a13[_0x469f('0x59')],null))[_0x469f('0x21')](respondWithResult(_0x5b699,null))[_0x469f('0x2b')](handleError(_0x5b699,null));};exports[_0x469f('0x36')]=function(_0x146b5d,_0x283243){return db[_0x469f('0x3c')]['find']({'where':{'id':_0x146b5d[_0x469f('0x5a')]['id']}})[_0x469f('0x21')](handleEntityNotFound(_0x283243,null))[_0x469f('0x21')](removeEntity(_0x283243,null))[_0x469f('0x2b')](handleError(_0x283243,null));};exports[_0x469f('0x5b')]=function(_0x4e919b,_0x54be3a,_0x43ec13){var _0x18713c={};var _0x391c35={};var _0x385fb3;var _0x24a8f5;return db['FreshdeskConfiguration']['findOne']({'where':{'id':_0x4e919b[_0x469f('0x5a')]['id']}})['then'](handleEntityNotFound(_0x54be3a,null))[_0x469f('0x21')](function(_0x2b1912){if(_0x2b1912){_0x385fb3=_0x2b1912;_0x391c35['model']=_[_0x469f('0x42')](db[_0x469f('0x5c')][_0x469f('0x3d')]);_0x391c35['query']=_['keys'](_0x4e919b['query']);_0x391c35[_0x469f('0x43')]=_['intersection'](_0x391c35[_0x469f('0x40')],_0x391c35['query']);_0x18713c[_0x469f('0x45')]=_[_0x469f('0x44')](_0x391c35[_0x469f('0x40')],qs[_0x469f('0x46')](_0x4e919b['query'][_0x469f('0x46')]));_0x18713c['attributes']=_0x18713c[_0x469f('0x45')]['length']?_0x18713c[_0x469f('0x45')]:_0x391c35['model'];_0x18713c[_0x469f('0x5d')]=qs[_0x469f('0x4a')](_0x4e919b[_0x469f('0x41')]['sort']);_0x18713c[_0x469f('0x4d')]=qs[_0x469f('0x43')](_['pick'](_0x4e919b[_0x469f('0x41')],_0x391c35[_0x469f('0x43')]));if(_0x4e919b[_0x469f('0x41')]['filter']){_0x18713c[_0x469f('0x4d')]=_[_0x469f('0x4e')](_0x18713c[_0x469f('0x4d')],{'$or':_[_0x469f('0x3b')](_0x18713c[_0x469f('0x45')],function(_0x15b0ff){var _0x15f7a7={};_0x15f7a7[_0x15b0ff]={'$like':'%'+_0x4e919b['query'][_0x469f('0x4c')]+'%'};return _0x15f7a7;})});}_0x18713c=_[_0x469f('0x4e')]({},_0x18713c,_0x4e919b['options']);return _0x385fb3[_0x469f('0x5b')](_0x18713c);}})[_0x469f('0x21')](function(_0x2f303c){if(_0x2f303c){_0x24a8f5=_0x2f303c[_0x469f('0x47')];if(!_0x4e919b[_0x469f('0x41')][_0x469f('0x48')](_0x469f('0x49'))){_0x18713c[_0x469f('0x31')]=qs['limit'](_0x4e919b[_0x469f('0x41')][_0x469f('0x31')]);_0x18713c[_0x469f('0x30')]=qs[_0x469f('0x30')](_0x4e919b[_0x469f('0x41')][_0x469f('0x30')]);}return _0x385fb3[_0x469f('0x5b')](_0x18713c);}})[_0x469f('0x21')](function(_0x11f813){if(_0x11f813){return _0x11f813?{'count':_0x24a8f5,'rows':_0x11f813}:null;}})[_0x469f('0x21')](respondWithResult(_0x54be3a,null))[_0x469f('0x2b')](handleError(_0x54be3a,null));};exports[_0x469f('0x5e')]=function(_0x1c5201,_0x4cec80,_0x5c08aa){var _0x138271={};var _0x5d3464={};var _0x1585ab;var _0x548b2e;return db[_0x469f('0x3c')][_0x469f('0x5f')]({'where':{'id':_0x1c5201['params']['id']}})[_0x469f('0x21')](handleEntityNotFound(_0x4cec80,null))[_0x469f('0x21')](function(_0x513ff3){if(_0x513ff3){_0x1585ab=_0x513ff3;_0x5d3464['model']=_[_0x469f('0x42')](db[_0x469f('0x5c')][_0x469f('0x3d')]);_0x5d3464[_0x469f('0x41')]=_['keys'](_0x1c5201[_0x469f('0x41')]);_0x5d3464['filters']=_[_0x469f('0x44')](_0x5d3464[_0x469f('0x40')],_0x5d3464['query']);_0x138271[_0x469f('0x45')]=_['intersection'](_0x5d3464[_0x469f('0x40')],qs[_0x469f('0x46')](_0x1c5201[_0x469f('0x41')][_0x469f('0x46')]));_0x138271[_0x469f('0x45')]=_0x138271[_0x469f('0x45')][_0x469f('0x47')]?_0x138271[_0x469f('0x45')]:_0x5d3464['model'];_0x138271['order']=qs[_0x469f('0x4a')](_0x1c5201['query'][_0x469f('0x4a')]);_0x138271['where']=qs['filters'](_[_0x469f('0x4b')](_0x1c5201[_0x469f('0x41')],_0x5d3464[_0x469f('0x43')]));if(_0x1c5201['query']['filter']){_0x138271['where']=_[_0x469f('0x4e')](_0x138271[_0x469f('0x4d')],{'$or':_[_0x469f('0x3b')](_0x138271[_0x469f('0x45')],function(_0x35f65b){var _0xfed47d={};_0xfed47d[_0x35f65b]={'$like':'%'+_0x1c5201['query']['filter']+'%'};return _0xfed47d;})});}_0x138271=_[_0x469f('0x4e')]({},_0x138271,_0x1c5201[_0x469f('0x50')]);return _0x1585ab[_0x469f('0x5e')](_0x138271);}})[_0x469f('0x21')](function(_0x484eec){if(_0x484eec){_0x548b2e=_0x484eec['length'];if(!_0x1c5201['query'][_0x469f('0x48')](_0x469f('0x49'))){_0x138271[_0x469f('0x31')]=qs[_0x469f('0x31')](_0x1c5201[_0x469f('0x41')][_0x469f('0x31')]);_0x138271[_0x469f('0x30')]=qs[_0x469f('0x30')](_0x1c5201['query'][_0x469f('0x30')]);}return _0x1585ab[_0x469f('0x5e')](_0x138271);}})[_0x469f('0x21')](function(_0x5cdcbd){if(_0x5cdcbd){return _0x5cdcbd?{'count':_0x548b2e,'rows':_0x5cdcbd}:null;}})[_0x469f('0x21')](respondWithResult(_0x4cec80,null))[_0x469f('0x2b')](handleError(_0x4cec80,null));};exports[_0x469f('0x60')]=function(_0x3f8c31,_0x1e2ff3,_0x33a280){var _0x3853c0={};var _0x106e5b={};var _0x28d798;var _0x3a336c;return db[_0x469f('0x3c')][_0x469f('0x5f')]({'where':{'id':_0x3f8c31[_0x469f('0x5a')]['id']}})['then'](handleEntityNotFound(_0x1e2ff3,null))[_0x469f('0x21')](function(_0x4bd5fe){if(_0x4bd5fe){_0x28d798=_0x4bd5fe;_0x106e5b[_0x469f('0x40')]=_[_0x469f('0x42')](db[_0x469f('0x5c')]['rawAttributes']);_0x106e5b['query']=_[_0x469f('0x42')](_0x3f8c31[_0x469f('0x41')]);_0x106e5b['filters']=_[_0x469f('0x44')](_0x106e5b[_0x469f('0x40')],_0x106e5b[_0x469f('0x41')]);_0x3853c0[_0x469f('0x45')]=_[_0x469f('0x44')](_0x106e5b[_0x469f('0x40')],qs[_0x469f('0x46')](_0x3f8c31[_0x469f('0x41')][_0x469f('0x46')]));_0x3853c0[_0x469f('0x45')]=_0x3853c0[_0x469f('0x45')]['length']?_0x3853c0['attributes']:_0x106e5b[_0x469f('0x40')];_0x3853c0[_0x469f('0x5d')]=qs[_0x469f('0x4a')](_0x3f8c31[_0x469f('0x41')][_0x469f('0x4a')]);_0x3853c0[_0x469f('0x4d')]=qs[_0x469f('0x43')](_['pick'](_0x3f8c31['query'],_0x106e5b[_0x469f('0x43')]));if(_0x3f8c31[_0x469f('0x41')]['filter']){_0x3853c0['where']=_[_0x469f('0x4e')](_0x3853c0['where'],{'$or':_[_0x469f('0x3b')](_0x3853c0['attributes'],function(_0xbb5be7){var _0x6a2f2f={};_0x6a2f2f[_0xbb5be7]={'$like':'%'+_0x3f8c31[_0x469f('0x41')]['filter']+'%'};return _0x6a2f2f;})});}_0x3853c0=_[_0x469f('0x4e')]({},_0x3853c0,_0x3f8c31[_0x469f('0x50')]);return _0x28d798[_0x469f('0x60')](_0x3853c0);}})[_0x469f('0x21')](function(_0x115eed){if(_0x115eed){_0x3a336c=_0x115eed[_0x469f('0x47')];if(!_0x3f8c31[_0x469f('0x41')]['hasOwnProperty'](_0x469f('0x49'))){_0x3853c0[_0x469f('0x31')]=qs['limit'](_0x3f8c31[_0x469f('0x41')][_0x469f('0x31')]);_0x3853c0['offset']=qs[_0x469f('0x30')](_0x3f8c31[_0x469f('0x41')][_0x469f('0x30')]);}return _0x28d798['getDescriptions'](_0x3853c0);}})['then'](function(_0x1591eb){if(_0x1591eb){return _0x1591eb?{'count':_0x3a336c,'rows':_0x1591eb}:null;}})[_0x469f('0x21')](respondWithResult(_0x1e2ff3,null))[_0x469f('0x2b')](handleError(_0x1e2ff3,null));};exports[_0x469f('0x61')]=function(_0xa5fde4,_0x5edd3d,_0x13f2e0){var _0x440ec3={};var _0x62b9d4={};var _0x3f86d1;var _0x17ebea;return db['FreshdeskConfiguration'][_0x469f('0x5f')]({'where':{'id':_0xa5fde4['params']['id']}})[_0x469f('0x21')](handleEntityNotFound(_0x5edd3d,null))[_0x469f('0x21')](function(_0x1c4b9b){if(_0x1c4b9b){_0x3f86d1=_0x1c4b9b;_0x62b9d4[_0x469f('0x40')]=_[_0x469f('0x42')](db[_0x469f('0x62')][_0x469f('0x3d')]);_0x62b9d4[_0x469f('0x41')]=_['keys'](_0xa5fde4[_0x469f('0x41')]);_0x62b9d4[_0x469f('0x43')]=_[_0x469f('0x44')](_0x62b9d4[_0x469f('0x40')],_0x62b9d4['query']);_0x440ec3['attributes']=_['intersection'](_0x62b9d4[_0x469f('0x40')],qs[_0x469f('0x46')](_0xa5fde4[_0x469f('0x41')][_0x469f('0x46')]));_0x440ec3[_0x469f('0x45')]=_0x440ec3[_0x469f('0x45')]['length']?_0x440ec3[_0x469f('0x45')]:_0x62b9d4[_0x469f('0x40')];_0x440ec3[_0x469f('0x5d')]=qs[_0x469f('0x4a')](_0xa5fde4[_0x469f('0x41')][_0x469f('0x4a')]);_0x440ec3[_0x469f('0x4d')]=qs[_0x469f('0x43')](_[_0x469f('0x4b')](_0xa5fde4['query'],_0x62b9d4[_0x469f('0x43')]));if(_0xa5fde4[_0x469f('0x41')][_0x469f('0x4c')]){_0x440ec3[_0x469f('0x4d')]=_['merge'](_0x440ec3[_0x469f('0x4d')],{'$or':_['map'](_0x440ec3[_0x469f('0x45')],function(_0x31c99e){var _0x33fb33={};_0x33fb33[_0x31c99e]={'$like':'%'+_0xa5fde4['query'][_0x469f('0x4c')]+'%'};return _0x33fb33;})});}_0x440ec3=_['merge']({},_0x440ec3,_0xa5fde4[_0x469f('0x50')]);return _0x3f86d1[_0x469f('0x61')](_0x440ec3);}})['then'](function(_0x11c52e){if(_0x11c52e){_0x17ebea=_0x11c52e['length'];if(!_0xa5fde4[_0x469f('0x41')][_0x469f('0x48')](_0x469f('0x49'))){_0x440ec3['limit']=qs[_0x469f('0x31')](_0xa5fde4[_0x469f('0x41')][_0x469f('0x31')]);_0x440ec3[_0x469f('0x30')]=qs[_0x469f('0x30')](_0xa5fde4[_0x469f('0x41')][_0x469f('0x30')]);}return _0x3f86d1[_0x469f('0x61')](_0x440ec3);}})[_0x469f('0x21')](function(_0x4226ad){if(_0x4226ad){return _0x4226ad?{'count':_0x17ebea,'rows':_0x4226ad}:null;}})['then'](respondWithResult(_0x5edd3d,null))[_0x469f('0x2b')](handleError(_0x5edd3d,null));};exports[_0x469f('0x63')]=function(_0x4759b6,_0x5b172e,_0x2a6f7f){if(_0x4759b6['body']['id']){delete _0x4759b6[_0x469f('0x59')]['id'];}return db[_0x469f('0x3c')][_0x469f('0x5f')]({'where':{'id':_0x4759b6[_0x469f('0x5a')]['id']}})['then'](handleEntityNotFound(_0x5b172e,null))[_0x469f('0x21')](function(_0xa07f78){if(_0xa07f78){return _0xa07f78[_0x469f('0x63')](_0x4759b6[_0x469f('0x59')]['ids']||[]);}return null;})[_0x469f('0x21')](respondWithResult(_0x5b172e,null))[_0x469f('0x2b')](handleError(_0x5b172e,null));};