40f288725070039c0900e7995fc67aa170023162
[motion2.git] / server / api / intZendeskConfiguration / intZendeskConfiguration.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 _0xb7b4=['includeAll','include','findAll','show','params','keys','catch','create','body','find','destroy','findOne','ZendeskField','pick','getFields','getSubjects','getDescriptions','getTags','Tag','setTags','ids','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','status','json','undefined','limit','count','offset','set','Content-Range','apply','reject','save','update','then','end','sendStatus','error','name','send','map','ZendeskConfiguration','rawAttributes','type','key','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','options'];(function(_0x406a3a,_0x44b922){var _0x3e239d=function(_0x328d16){while(--_0x328d16){_0x406a3a['push'](_0x406a3a['shift']());}};_0x3e239d(++_0x44b922);}(_0xb7b4,0x1be));var _0x4b7b=function(_0xb7cad3,_0x8ad5e3){_0xb7cad3=_0xb7cad3-0x0;var _0x262567=_0xb7b4[_0xb7cad3];return _0x262567;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x4b7b('0x0'));var jsonpatch=require(_0x4b7b('0x1'));var rp=require(_0x4b7b('0x2'));var moment=require(_0x4b7b('0x3'));var BPromise=require(_0x4b7b('0x4'));var Mustache=require(_0x4b7b('0x5'));var util=require(_0x4b7b('0x6'));var path=require(_0x4b7b('0x7'));var sox=require('sox');var csv=require(_0x4b7b('0x8'));var ejs=require(_0x4b7b('0x9'));var fs=require('fs');var fs_extra=require(_0x4b7b('0xa'));var _=require(_0x4b7b('0xb'));var squel=require(_0x4b7b('0xc'));var crypto=require(_0x4b7b('0xd'));var jsforce=require(_0x4b7b('0xe'));var deskjs=require(_0x4b7b('0xf'));var toCsv=require(_0x4b7b('0x8'));var querystring=require(_0x4b7b('0x10'));var Papa=require(_0x4b7b('0x11'));var Redis=require(_0x4b7b('0x12'));var authService=require(_0x4b7b('0x13'));var qs=require(_0x4b7b('0x14'));var as=require(_0x4b7b('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x4b7b('0x16'))('api');var utils=require('../../config/utils');var config=require(_0x4b7b('0x17'));var licenseUtil=require(_0x4b7b('0x18'));var db=require(_0x4b7b('0x19'))['db'];function respondWithStatusCode(_0x5a89f6,_0x1114e4){_0x1114e4=_0x1114e4||0xcc;return function(_0x389a12){if(_0x389a12){return _0x5a89f6['sendStatus'](_0x1114e4);}return _0x5a89f6['status'](_0x1114e4)['end']();};}function respondWithResult(_0x5563c6,_0x3819af){_0x3819af=_0x3819af||0xc8;return function(_0x2c974c){if(_0x2c974c){return _0x5563c6[_0x4b7b('0x1a')](_0x3819af)[_0x4b7b('0x1b')](_0x2c974c);}};}function respondWithFilteredResult(_0x5b125a,_0x449925){return function(_0x24db2d){if(_0x24db2d){var _0x49050c=typeof _0x449925['offset']===_0x4b7b('0x1c')&&typeof _0x449925[_0x4b7b('0x1d')]==='undefined';var _0xe3b82e=_0x24db2d[_0x4b7b('0x1e')];var _0x2b11b6=_0x49050c?0x0:_0x449925[_0x4b7b('0x1f')];var _0x284d27=_0x49050c?_0x24db2d['count']:_0x449925['offset']+_0x449925['limit'];var _0xc7a54a;if(_0x284d27>=_0xe3b82e){_0x284d27=_0xe3b82e;_0xc7a54a=0xc8;}else{_0xc7a54a=0xce;}_0x5b125a['status'](_0xc7a54a);return _0x5b125a[_0x4b7b('0x20')](_0x4b7b('0x21'),_0x2b11b6+'-'+_0x284d27+'/'+_0xe3b82e)['json'](_0x24db2d);}return null;};}function patchUpdates(_0x139093){return function(_0x15487e){try{jsonpatch[_0x4b7b('0x22')](_0x15487e,_0x139093,!![]);}catch(_0x4a06e2){return BPromise[_0x4b7b('0x23')](_0x4a06e2);}return _0x15487e[_0x4b7b('0x24')]();};}function saveUpdates(_0x3ad3dc,_0x35fc60){return function(_0x1ca3e9){if(_0x1ca3e9){return _0x1ca3e9[_0x4b7b('0x25')](_0x3ad3dc)[_0x4b7b('0x26')](function(_0xaaaaf0){return _0xaaaaf0;});}return null;};}function removeEntity(_0x189a1b,_0x5d5712){return function(_0x2f073f){if(_0x2f073f){return _0x2f073f['destroy']()[_0x4b7b('0x26')](function(){_0x189a1b[_0x4b7b('0x1a')](0xcc)[_0x4b7b('0x27')]();});}};}function handleEntityNotFound(_0x5b6c8e,_0x9a5d71){return function(_0x4b4cda){if(!_0x4b4cda){_0x5b6c8e[_0x4b7b('0x28')](0x194);}return _0x4b4cda;};}function handleError(_0x2c7655,_0x3e5c33){_0x3e5c33=_0x3e5c33||0x1f4;return function(_0x939e4){logger[_0x4b7b('0x29')](_0x939e4['stack']);if(_0x939e4[_0x4b7b('0x2a')]){delete _0x939e4['name'];}_0x2c7655[_0x4b7b('0x1a')](_0x3e5c33)[_0x4b7b('0x2b')](_0x939e4);};}exports['index']=function(_0x25b18f,_0x38e292){var _0x4cedf6={},_0x4814a3={},_0x2e87f5={'count':0x0,'rows':[]};var _0x57de40=_[_0x4b7b('0x2c')](db[_0x4b7b('0x2d')][_0x4b7b('0x2e')],function(_0x49b7e4){return{'name':_0x49b7e4['fieldName'],'type':_0x49b7e4[_0x4b7b('0x2f')][_0x4b7b('0x30')]};});_0x4814a3[_0x4b7b('0x31')]=_[_0x4b7b('0x2c')](_0x57de40,'name');_0x4814a3[_0x4b7b('0x32')]=_['keys'](_0x25b18f[_0x4b7b('0x32')]);_0x4814a3[_0x4b7b('0x33')]=_['intersection'](_0x4814a3['model'],_0x4814a3[_0x4b7b('0x32')]);_0x4cedf6['attributes']=_[_0x4b7b('0x34')](_0x4814a3[_0x4b7b('0x31')],qs[_0x4b7b('0x35')](_0x25b18f[_0x4b7b('0x32')][_0x4b7b('0x35')]));_0x4cedf6[_0x4b7b('0x36')]=_0x4cedf6['attributes'][_0x4b7b('0x37')]?_0x4cedf6[_0x4b7b('0x36')]:_0x4814a3[_0x4b7b('0x31')];if(!_0x25b18f['query'][_0x4b7b('0x38')](_0x4b7b('0x39'))){_0x4cedf6[_0x4b7b('0x1d')]=qs['limit'](_0x25b18f[_0x4b7b('0x32')][_0x4b7b('0x1d')]);_0x4cedf6[_0x4b7b('0x1f')]=qs[_0x4b7b('0x1f')](_0x25b18f[_0x4b7b('0x32')]['offset']);}_0x4cedf6[_0x4b7b('0x3a')]=qs[_0x4b7b('0x3b')](_0x25b18f[_0x4b7b('0x32')][_0x4b7b('0x3b')]);_0x4cedf6[_0x4b7b('0x3c')]=qs[_0x4b7b('0x33')](_['pick'](_0x25b18f[_0x4b7b('0x32')],_0x4814a3[_0x4b7b('0x33')]),_0x57de40);if(_0x25b18f[_0x4b7b('0x32')][_0x4b7b('0x3d')]){_0x4cedf6[_0x4b7b('0x3c')]=_[_0x4b7b('0x3e')](_0x4cedf6[_0x4b7b('0x3c')],{'$or':_[_0x4b7b('0x2c')](_0x57de40,function(_0x43e9e7){if(_0x43e9e7[_0x4b7b('0x2f')]!=='VIRTUAL'){var _0x1f60b4={};_0x1f60b4[_0x43e9e7[_0x4b7b('0x2a')]]={'$like':'%'+_0x25b18f['query'][_0x4b7b('0x3d')]+'%'};return _0x1f60b4;}})});}_0x4cedf6=_[_0x4b7b('0x3e')]({},_0x4cedf6,_0x25b18f[_0x4b7b('0x3f')]);var _0x4deb68={'where':_0x4cedf6[_0x4b7b('0x3c')]};return db[_0x4b7b('0x2d')]['count'](_0x4deb68)['then'](function(_0x231c00){_0x2e87f5[_0x4b7b('0x1e')]=_0x231c00;if(_0x25b18f[_0x4b7b('0x32')][_0x4b7b('0x40')]){_0x4cedf6[_0x4b7b('0x41')]=[{'all':!![]}];}return db['ZendeskConfiguration'][_0x4b7b('0x42')](_0x4cedf6);})[_0x4b7b('0x26')](function(_0x51d09a){_0x2e87f5['rows']=_0x51d09a;return _0x2e87f5;})[_0x4b7b('0x26')](respondWithFilteredResult(_0x38e292,_0x4cedf6))['catch'](handleError(_0x38e292,null));};exports[_0x4b7b('0x43')]=function(_0x4cfcb5,_0x16ad0f){var _0x44d376={'raw':![],'where':{'id':_0x4cfcb5[_0x4b7b('0x44')]['id']}},_0x494adc={};_0x494adc[_0x4b7b('0x31')]=_[_0x4b7b('0x45')](db[_0x4b7b('0x2d')][_0x4b7b('0x2e')]);_0x494adc[_0x4b7b('0x32')]=_[_0x4b7b('0x45')](_0x4cfcb5[_0x4b7b('0x32')]);_0x494adc[_0x4b7b('0x33')]=_['intersection'](_0x494adc[_0x4b7b('0x31')],_0x494adc[_0x4b7b('0x32')]);_0x44d376[_0x4b7b('0x36')]=_[_0x4b7b('0x34')](_0x494adc[_0x4b7b('0x31')],qs[_0x4b7b('0x35')](_0x4cfcb5['query'][_0x4b7b('0x35')]));_0x44d376[_0x4b7b('0x36')]=_0x44d376['attributes'][_0x4b7b('0x37')]?_0x44d376['attributes']:_0x494adc[_0x4b7b('0x31')];if(_0x4cfcb5[_0x4b7b('0x32')][_0x4b7b('0x40')]){_0x44d376[_0x4b7b('0x41')]=[{'all':!![]}];}_0x44d376=_['merge']({},_0x44d376,_0x4cfcb5[_0x4b7b('0x3f')]);return db[_0x4b7b('0x2d')]['find'](_0x44d376)[_0x4b7b('0x26')](handleEntityNotFound(_0x16ad0f,null))[_0x4b7b('0x26')](respondWithResult(_0x16ad0f,null))[_0x4b7b('0x46')](handleError(_0x16ad0f,null));};exports[_0x4b7b('0x47')]=function(_0x5a2f6d,_0x3a397e){return db[_0x4b7b('0x2d')][_0x4b7b('0x47')](_0x5a2f6d['body'],{})['then'](respondWithResult(_0x3a397e,0xc9))[_0x4b7b('0x46')](handleError(_0x3a397e,null));};exports[_0x4b7b('0x25')]=function(_0x537e71,_0x556fbc){if(_0x537e71[_0x4b7b('0x48')]['id']){delete _0x537e71[_0x4b7b('0x48')]['id'];}return db['ZendeskConfiguration'][_0x4b7b('0x49')]({'where':{'id':_0x537e71[_0x4b7b('0x44')]['id']}})[_0x4b7b('0x26')](handleEntityNotFound(_0x556fbc,null))[_0x4b7b('0x26')](saveUpdates(_0x537e71[_0x4b7b('0x48')],null))[_0x4b7b('0x26')](respondWithResult(_0x556fbc,null))[_0x4b7b('0x46')](handleError(_0x556fbc,null));};exports[_0x4b7b('0x4a')]=function(_0x47ab5a,_0x4be845){return db[_0x4b7b('0x2d')][_0x4b7b('0x49')]({'where':{'id':_0x47ab5a[_0x4b7b('0x44')]['id']}})[_0x4b7b('0x26')](handleEntityNotFound(_0x4be845,null))[_0x4b7b('0x26')](removeEntity(_0x4be845,null))[_0x4b7b('0x46')](handleError(_0x4be845,null));};exports['getFields']=function(_0x209345,_0x2fbb30,_0x592966){var _0x2f2be6={};var _0x4312be={};var _0x44e2ce;var _0x4e4817;return db['ZendeskConfiguration'][_0x4b7b('0x4b')]({'where':{'id':_0x209345[_0x4b7b('0x44')]['id']}})[_0x4b7b('0x26')](handleEntityNotFound(_0x2fbb30,null))[_0x4b7b('0x26')](function(_0x3010e8){if(_0x3010e8){_0x44e2ce=_0x3010e8;_0x4312be[_0x4b7b('0x31')]=_['keys'](db[_0x4b7b('0x4c')][_0x4b7b('0x2e')]);_0x4312be[_0x4b7b('0x32')]=_['keys'](_0x209345['query']);_0x4312be[_0x4b7b('0x33')]=_[_0x4b7b('0x34')](_0x4312be[_0x4b7b('0x31')],_0x4312be[_0x4b7b('0x32')]);_0x2f2be6[_0x4b7b('0x36')]=_[_0x4b7b('0x34')](_0x4312be[_0x4b7b('0x31')],qs[_0x4b7b('0x35')](_0x209345['query'][_0x4b7b('0x35')]));_0x2f2be6['attributes']=_0x2f2be6[_0x4b7b('0x36')][_0x4b7b('0x37')]?_0x2f2be6[_0x4b7b('0x36')]:_0x4312be[_0x4b7b('0x31')];_0x2f2be6['order']=qs['sort'](_0x209345[_0x4b7b('0x32')]['sort']);_0x2f2be6[_0x4b7b('0x3c')]=qs['filters'](_[_0x4b7b('0x4d')](_0x209345[_0x4b7b('0x32')],_0x4312be[_0x4b7b('0x33')]));if(_0x209345['query'][_0x4b7b('0x3d')]){_0x2f2be6[_0x4b7b('0x3c')]=_['merge'](_0x2f2be6[_0x4b7b('0x3c')],{'$or':_['map'](_0x2f2be6['attributes'],function(_0x3dfbd5){var _0x3a75a7={};_0x3a75a7[_0x3dfbd5]={'$like':'%'+_0x209345[_0x4b7b('0x32')]['filter']+'%'};return _0x3a75a7;})});}_0x2f2be6=_[_0x4b7b('0x3e')]({},_0x2f2be6,_0x209345[_0x4b7b('0x3f')]);return _0x44e2ce['getFields'](_0x2f2be6);}})[_0x4b7b('0x26')](function(_0x19c235){if(_0x19c235){_0x4e4817=_0x19c235['length'];if(!_0x209345[_0x4b7b('0x32')][_0x4b7b('0x38')](_0x4b7b('0x39'))){_0x2f2be6['limit']=qs[_0x4b7b('0x1d')](_0x209345[_0x4b7b('0x32')]['limit']);_0x2f2be6[_0x4b7b('0x1f')]=qs[_0x4b7b('0x1f')](_0x209345[_0x4b7b('0x32')][_0x4b7b('0x1f')]);}return _0x44e2ce[_0x4b7b('0x4e')](_0x2f2be6);}})[_0x4b7b('0x26')](function(_0x25e1ec){if(_0x25e1ec){return _0x25e1ec?{'count':_0x4e4817,'rows':_0x25e1ec}:null;}})[_0x4b7b('0x26')](respondWithResult(_0x2fbb30,null))[_0x4b7b('0x46')](handleError(_0x2fbb30,null));};exports[_0x4b7b('0x4f')]=function(_0x30d821,_0x45030a,_0x83807b){var _0x420271={};var _0x2363da={};var _0x38603c;var _0xc69df0;return db[_0x4b7b('0x2d')][_0x4b7b('0x4b')]({'where':{'id':_0x30d821[_0x4b7b('0x44')]['id']}})['then'](handleEntityNotFound(_0x45030a,null))['then'](function(_0x129034){if(_0x129034){_0x38603c=_0x129034;_0x2363da[_0x4b7b('0x31')]=_[_0x4b7b('0x45')](db['ZendeskField'][_0x4b7b('0x2e')]);_0x2363da[_0x4b7b('0x32')]=_[_0x4b7b('0x45')](_0x30d821['query']);_0x2363da[_0x4b7b('0x33')]=_[_0x4b7b('0x34')](_0x2363da[_0x4b7b('0x31')],_0x2363da['query']);_0x420271[_0x4b7b('0x36')]=_['intersection'](_0x2363da[_0x4b7b('0x31')],qs[_0x4b7b('0x35')](_0x30d821[_0x4b7b('0x32')]['fields']));_0x420271[_0x4b7b('0x36')]=_0x420271['attributes'][_0x4b7b('0x37')]?_0x420271['attributes']:_0x2363da[_0x4b7b('0x31')];_0x420271['order']=qs[_0x4b7b('0x3b')](_0x30d821[_0x4b7b('0x32')]['sort']);_0x420271[_0x4b7b('0x3c')]=qs['filters'](_[_0x4b7b('0x4d')](_0x30d821[_0x4b7b('0x32')],_0x2363da['filters']));if(_0x30d821[_0x4b7b('0x32')]['filter']){_0x420271[_0x4b7b('0x3c')]=_['merge'](_0x420271[_0x4b7b('0x3c')],{'$or':_[_0x4b7b('0x2c')](_0x420271[_0x4b7b('0x36')],function(_0x7a4a05){var _0x2ce48f={};_0x2ce48f[_0x7a4a05]={'$like':'%'+_0x30d821[_0x4b7b('0x32')][_0x4b7b('0x3d')]+'%'};return _0x2ce48f;})});}_0x420271=_[_0x4b7b('0x3e')]({},_0x420271,_0x30d821[_0x4b7b('0x3f')]);return _0x38603c[_0x4b7b('0x4f')](_0x420271);}})[_0x4b7b('0x26')](function(_0xf14ef){if(_0xf14ef){_0xc69df0=_0xf14ef[_0x4b7b('0x37')];if(!_0x30d821[_0x4b7b('0x32')][_0x4b7b('0x38')]('nolimit')){_0x420271[_0x4b7b('0x1d')]=qs[_0x4b7b('0x1d')](_0x30d821[_0x4b7b('0x32')]['limit']);_0x420271[_0x4b7b('0x1f')]=qs[_0x4b7b('0x1f')](_0x30d821[_0x4b7b('0x32')][_0x4b7b('0x1f')]);}return _0x38603c['getSubjects'](_0x420271);}})[_0x4b7b('0x26')](function(_0x28a72e){if(_0x28a72e){return _0x28a72e?{'count':_0xc69df0,'rows':_0x28a72e}:null;}})[_0x4b7b('0x26')](respondWithResult(_0x45030a,null))['catch'](handleError(_0x45030a,null));};exports[_0x4b7b('0x50')]=function(_0x3a03ad,_0x2e13b1,_0x335adf){var _0x332c67={};var _0x2eccdd={};var _0x31a46e;var _0x275f91;return db[_0x4b7b('0x2d')][_0x4b7b('0x4b')]({'where':{'id':_0x3a03ad[_0x4b7b('0x44')]['id']}})[_0x4b7b('0x26')](handleEntityNotFound(_0x2e13b1,null))[_0x4b7b('0x26')](function(_0x2e8621){if(_0x2e8621){_0x31a46e=_0x2e8621;_0x2eccdd['model']=_[_0x4b7b('0x45')](db[_0x4b7b('0x4c')][_0x4b7b('0x2e')]);_0x2eccdd[_0x4b7b('0x32')]=_[_0x4b7b('0x45')](_0x3a03ad[_0x4b7b('0x32')]);_0x2eccdd[_0x4b7b('0x33')]=_[_0x4b7b('0x34')](_0x2eccdd[_0x4b7b('0x31')],_0x2eccdd[_0x4b7b('0x32')]);_0x332c67['attributes']=_[_0x4b7b('0x34')](_0x2eccdd[_0x4b7b('0x31')],qs[_0x4b7b('0x35')](_0x3a03ad[_0x4b7b('0x32')]['fields']));_0x332c67[_0x4b7b('0x36')]=_0x332c67['attributes'][_0x4b7b('0x37')]?_0x332c67[_0x4b7b('0x36')]:_0x2eccdd['model'];_0x332c67[_0x4b7b('0x3a')]=qs['sort'](_0x3a03ad[_0x4b7b('0x32')]['sort']);_0x332c67[_0x4b7b('0x3c')]=qs[_0x4b7b('0x33')](_[_0x4b7b('0x4d')](_0x3a03ad[_0x4b7b('0x32')],_0x2eccdd[_0x4b7b('0x33')]));if(_0x3a03ad['query'][_0x4b7b('0x3d')]){_0x332c67[_0x4b7b('0x3c')]=_['merge'](_0x332c67['where'],{'$or':_[_0x4b7b('0x2c')](_0x332c67[_0x4b7b('0x36')],function(_0x5ca934){var _0xb4ec56={};_0xb4ec56[_0x5ca934]={'$like':'%'+_0x3a03ad[_0x4b7b('0x32')][_0x4b7b('0x3d')]+'%'};return _0xb4ec56;})});}_0x332c67=_[_0x4b7b('0x3e')]({},_0x332c67,_0x3a03ad['options']);return _0x31a46e[_0x4b7b('0x50')](_0x332c67);}})[_0x4b7b('0x26')](function(_0x380249){if(_0x380249){_0x275f91=_0x380249[_0x4b7b('0x37')];if(!_0x3a03ad[_0x4b7b('0x32')][_0x4b7b('0x38')](_0x4b7b('0x39'))){_0x332c67[_0x4b7b('0x1d')]=qs['limit'](_0x3a03ad['query'][_0x4b7b('0x1d')]);_0x332c67['offset']=qs[_0x4b7b('0x1f')](_0x3a03ad[_0x4b7b('0x32')]['offset']);}return _0x31a46e[_0x4b7b('0x50')](_0x332c67);}})[_0x4b7b('0x26')](function(_0x1e21fd){if(_0x1e21fd){return _0x1e21fd?{'count':_0x275f91,'rows':_0x1e21fd}:null;}})['then'](respondWithResult(_0x2e13b1,null))[_0x4b7b('0x46')](handleError(_0x2e13b1,null));};exports[_0x4b7b('0x51')]=function(_0x5b6267,_0x2555bb,_0x1221fe){var _0x50ef2d={};var _0x12ba22={};var _0x4abd30;var _0x1bea04;return db[_0x4b7b('0x2d')]['findOne']({'where':{'id':_0x5b6267[_0x4b7b('0x44')]['id']}})[_0x4b7b('0x26')](handleEntityNotFound(_0x2555bb,null))[_0x4b7b('0x26')](function(_0x30457a){if(_0x30457a){_0x4abd30=_0x30457a;_0x12ba22[_0x4b7b('0x31')]=_['keys'](db[_0x4b7b('0x52')][_0x4b7b('0x2e')]);_0x12ba22[_0x4b7b('0x32')]=_[_0x4b7b('0x45')](_0x5b6267[_0x4b7b('0x32')]);_0x12ba22[_0x4b7b('0x33')]=_[_0x4b7b('0x34')](_0x12ba22[_0x4b7b('0x31')],_0x12ba22[_0x4b7b('0x32')]);_0x50ef2d[_0x4b7b('0x36')]=_[_0x4b7b('0x34')](_0x12ba22['model'],qs[_0x4b7b('0x35')](_0x5b6267[_0x4b7b('0x32')][_0x4b7b('0x35')]));_0x50ef2d['attributes']=_0x50ef2d[_0x4b7b('0x36')][_0x4b7b('0x37')]?_0x50ef2d['attributes']:_0x12ba22['model'];_0x50ef2d[_0x4b7b('0x3a')]=qs['sort'](_0x5b6267[_0x4b7b('0x32')][_0x4b7b('0x3b')]);_0x50ef2d[_0x4b7b('0x3c')]=qs[_0x4b7b('0x33')](_[_0x4b7b('0x4d')](_0x5b6267[_0x4b7b('0x32')],_0x12ba22['filters']));if(_0x5b6267[_0x4b7b('0x32')][_0x4b7b('0x3d')]){_0x50ef2d[_0x4b7b('0x3c')]=_['merge'](_0x50ef2d[_0x4b7b('0x3c')],{'$or':_[_0x4b7b('0x2c')](_0x50ef2d[_0x4b7b('0x36')],function(_0xb90b5f){var _0x2acb1b={};_0x2acb1b[_0xb90b5f]={'$like':'%'+_0x5b6267['query']['filter']+'%'};return _0x2acb1b;})});}_0x50ef2d=_['merge']({},_0x50ef2d,_0x5b6267[_0x4b7b('0x3f')]);return _0x4abd30[_0x4b7b('0x51')](_0x50ef2d);}})['then'](function(_0x208a12){if(_0x208a12){_0x1bea04=_0x208a12[_0x4b7b('0x37')];if(!_0x5b6267[_0x4b7b('0x32')][_0x4b7b('0x38')](_0x4b7b('0x39'))){_0x50ef2d['limit']=qs['limit'](_0x5b6267['query'][_0x4b7b('0x1d')]);_0x50ef2d[_0x4b7b('0x1f')]=qs[_0x4b7b('0x1f')](_0x5b6267[_0x4b7b('0x32')]['offset']);}return _0x4abd30['getTags'](_0x50ef2d);}})[_0x4b7b('0x26')](function(_0x57abfc){if(_0x57abfc){return _0x57abfc?{'count':_0x1bea04,'rows':_0x57abfc}:null;}})[_0x4b7b('0x26')](respondWithResult(_0x2555bb,null))[_0x4b7b('0x46')](handleError(_0x2555bb,null));};exports['setTags']=function(_0x1a7a22,_0x57b9ed,_0x119ac3){if(_0x1a7a22[_0x4b7b('0x48')]['id']){delete _0x1a7a22[_0x4b7b('0x48')]['id'];}return db[_0x4b7b('0x2d')][_0x4b7b('0x4b')]({'where':{'id':_0x1a7a22['params']['id']}})[_0x4b7b('0x26')](handleEntityNotFound(_0x57b9ed,null))[_0x4b7b('0x26')](function(_0x521436){if(_0x521436){return _0x521436[_0x4b7b('0x53')](_0x1a7a22[_0x4b7b('0x48')][_0x4b7b('0x54')]||[]);}return null;})[_0x4b7b('0x26')](respondWithResult(_0x57b9ed,null))['catch'](handleError(_0x57b9ed,null));};