c890662fda04876113fec6d28ae553dff71c7aca
[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 _0xe689=['ids','eml-format','rimraf','request-promise','moment','bluebird','mustache','path','sox','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','jayson/promise','http','request','then','info','ZendeskConfiguration,\x20%s,\x20%s','request\x20sent','debug','ZendeskConfiguration,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','end','status','offset','limit','set','Content-Range','json','apply','save','destroy','send','index','map','ZendeskConfiguration','rawAttributes','fieldName','model','name','query','filters','intersection','attributes','fields','length','hasOwnProperty','sort','where','pick','filter','merge','type','VIRTUAL','options','count','includeAll','findAll','rows','show','keys','find','create','body','update','params','getFields','findOne','ZendeskField','order','nolimit','getSubjects','getDescriptions','getTags','setTags'];(function(_0x2ace95,_0x186b37){var _0x35ecfa=function(_0x26ce5a){while(--_0x26ce5a){_0x2ace95['push'](_0x2ace95['shift']());}};_0x35ecfa(++_0x186b37);}(_0xe689,0x1dc));var _0x9e68=function(_0x2c129f,_0xda24b5){_0x2c129f=_0x2c129f-0x0;var _0x1f7219=_0xe689[_0x2c129f];return _0x1f7219;};'use strict';var emlformat=require(_0x9e68('0x0'));var rimraf=require(_0x9e68('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x9e68('0x2'));var moment=require(_0x9e68('0x3'));var BPromise=require(_0x9e68('0x4'));var Mustache=require(_0x9e68('0x5'));var util=require('util');var path=require(_0x9e68('0x6'));var sox=require(_0x9e68('0x7'));var csv=require('to-csv');var ejs=require(_0x9e68('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x9e68('0x9'));var squel=require(_0x9e68('0xa'));var crypto=require(_0x9e68('0xb'));var jsforce=require(_0x9e68('0xc'));var deskjs=require(_0x9e68('0xd'));var toCsv=require('to-csv');var querystring=require(_0x9e68('0xe'));var Papa=require(_0x9e68('0xf'));var Redis=require(_0x9e68('0x10'));var authService=require(_0x9e68('0x11'));var qs=require(_0x9e68('0x12'));var as=require(_0x9e68('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x9e68('0x14'));var utils=require(_0x9e68('0x15'));var config=require(_0x9e68('0x16'));var licenseUtil=require(_0x9e68('0x17'));var db=require(_0x9e68('0x18'))['db'];var jayson=require(_0x9e68('0x19'));var client=jayson['client'][_0x9e68('0x1a')]({'port':0x232a});function respondWithRpcPromise(_0x2b52b9,_0x36bbf7,_0x18022c,_0x46c748){return new BPromise(function(_0x47b0b9,_0x5548b9){var _0x2f5024=_0x46c748||client;return _0x2f5024[_0x9e68('0x1b')](_0x2b52b9,_0x18022c)[_0x9e68('0x1c')](function(_0x36ea0e){logger[_0x9e68('0x1d')](_0x9e68('0x1e'),_0x36bbf7,_0x9e68('0x1f'));logger[_0x9e68('0x20')](_0x9e68('0x21'),_0x36bbf7,_0x9e68('0x1f'),JSON[_0x9e68('0x22')](_0x36ea0e));if(_0x36ea0e['error']){if(_0x36ea0e[_0x9e68('0x23')][_0x9e68('0x24')]===0x1f4){logger[_0x9e68('0x23')](_0x9e68('0x1e'),_0x36bbf7,_0x36ea0e[_0x9e68('0x23')]['message']);return _0x5548b9(_0x36ea0e['error'][_0x9e68('0x25')]);}logger[_0x9e68('0x23')](_0x9e68('0x1e'),_0x36bbf7,_0x36ea0e['error'][_0x9e68('0x25')]);return _0x47b0b9(_0x36ea0e[_0x9e68('0x23')]['message']);}else{logger[_0x9e68('0x1d')]('ZendeskConfiguration,\x20%s,\x20%s',_0x36bbf7,_0x9e68('0x1f'));_0x47b0b9(_0x36ea0e[_0x9e68('0x26')][_0x9e68('0x25')]);}})[_0x9e68('0x27')](function(_0x483a98){logger['error']('ZendeskConfiguration,\x20%s,\x20%s',_0x36bbf7,_0x483a98);_0x5548b9(_0x483a98);});});}function respondWithStatusCode(_0x369696,_0x46c605){_0x46c605=_0x46c605||0xcc;return function(_0x4c27b4){if(_0x4c27b4){return _0x369696[_0x9e68('0x28')](_0x46c605);}return _0x369696['status'](_0x46c605)[_0x9e68('0x29')]();};}function respondWithResult(_0x4266a8,_0x389486){_0x389486=_0x389486||0xc8;return function(_0x48781b){if(_0x48781b){return _0x4266a8[_0x9e68('0x2a')](_0x389486)['json'](_0x48781b);}};}function respondWithFilteredResult(_0x2def53,_0x613874){return function(_0x3266cb){if(_0x3266cb){var _0x34bdcb=_0x3266cb['count'],_0x4ae0ec=_0x613874[_0x9e68('0x2b')],_0xa8bf8c=_0x613874[_0x9e68('0x2b')]+_0x613874[_0x9e68('0x2c')],_0x419b05;if(_0xa8bf8c>=_0x34bdcb){_0xa8bf8c=_0x34bdcb;_0x419b05=0xc8;}else{_0x419b05=0xce;}_0x2def53['status'](_0x419b05);return _0x2def53[_0x9e68('0x2d')](_0x9e68('0x2e'),_0x4ae0ec+'-'+_0xa8bf8c+'/'+_0x34bdcb)[_0x9e68('0x2f')](_0x3266cb);}return null;};}function patchUpdates(_0x79a2e9){return function(_0x115618){try{jsonpatch[_0x9e68('0x30')](_0x115618,_0x79a2e9,!![]);}catch(_0xd0fa0){return BPromise['reject'](_0xd0fa0);}return _0x115618[_0x9e68('0x31')]();};}function saveUpdates(_0x4646b2,_0x223e58){return function(_0x51b7d1){if(_0x51b7d1){return _0x51b7d1['update'](_0x4646b2)[_0x9e68('0x1c')](function(_0x234813){return _0x234813;});}return null;};}function removeEntity(_0xbb7510,_0x5cae98){return function(_0x325632){if(_0x325632){return _0x325632[_0x9e68('0x32')]()[_0x9e68('0x1c')](function(){_0xbb7510['status'](0xcc)[_0x9e68('0x29')]();});}};}function handleEntityNotFound(_0x1d4384,_0xcfc306){return function(_0x25d17c){if(!_0x25d17c){_0x1d4384['sendStatus'](0x194);}return _0x25d17c;};}function handleError(_0x274d18,_0x3164b1){_0x3164b1=_0x3164b1||0x1f4;return function(_0x445154){logger['error'](_0x445154['stack']);if(_0x445154['name']){delete _0x445154['name'];}_0x274d18[_0x9e68('0x2a')](_0x3164b1)[_0x9e68('0x33')](_0x445154);};}exports[_0x9e68('0x34')]=function(_0x38048a,_0x49036a){var _0x413fc7={},_0x2aca43={},_0x226f40={'count':0x0,'rows':[]};var _0xe4b94d=_[_0x9e68('0x35')](db[_0x9e68('0x36')][_0x9e68('0x37')],function(_0xbc5949){return{'name':_0xbc5949[_0x9e68('0x38')],'type':_0xbc5949['type']['key']};});_0x2aca43[_0x9e68('0x39')]=_['map'](_0xe4b94d,_0x9e68('0x3a'));_0x2aca43['query']=_['keys'](_0x38048a[_0x9e68('0x3b')]);_0x2aca43[_0x9e68('0x3c')]=_[_0x9e68('0x3d')](_0x2aca43[_0x9e68('0x39')],_0x2aca43[_0x9e68('0x3b')]);_0x413fc7[_0x9e68('0x3e')]=_[_0x9e68('0x3d')](_0x2aca43[_0x9e68('0x39')],qs[_0x9e68('0x3f')](_0x38048a[_0x9e68('0x3b')][_0x9e68('0x3f')]));_0x413fc7[_0x9e68('0x3e')]=_0x413fc7[_0x9e68('0x3e')][_0x9e68('0x40')]?_0x413fc7[_0x9e68('0x3e')]:_0x2aca43['model'];if(!_0x38048a[_0x9e68('0x3b')][_0x9e68('0x41')]('nolimit')){_0x413fc7[_0x9e68('0x2c')]=qs['limit'](_0x38048a[_0x9e68('0x3b')]['limit']);_0x413fc7[_0x9e68('0x2b')]=qs[_0x9e68('0x2b')](_0x38048a['query'][_0x9e68('0x2b')]);}_0x413fc7['order']=qs[_0x9e68('0x42')](_0x38048a[_0x9e68('0x3b')]['sort']);_0x413fc7[_0x9e68('0x43')]=qs[_0x9e68('0x3c')](_[_0x9e68('0x44')](_0x38048a[_0x9e68('0x3b')],_0x2aca43[_0x9e68('0x3c')]),_0xe4b94d);if(_0x38048a[_0x9e68('0x3b')][_0x9e68('0x45')]){_0x413fc7[_0x9e68('0x43')]=_[_0x9e68('0x46')](_0x413fc7[_0x9e68('0x43')],{'$or':_['map'](_0xe4b94d,function(_0x1628fe){if(_0x1628fe[_0x9e68('0x47')]!==_0x9e68('0x48')){var _0x48b874={};_0x48b874[_0x1628fe['name']]={'$like':'%'+_0x38048a[_0x9e68('0x3b')][_0x9e68('0x45')]+'%'};return _0x48b874;}})});}_0x413fc7=_['merge']({},_0x413fc7,_0x38048a[_0x9e68('0x49')]);var _0x346eef={'where':_0x413fc7[_0x9e68('0x43')]};return db[_0x9e68('0x36')][_0x9e68('0x4a')](_0x346eef)[_0x9e68('0x1c')](function(_0x5737cb){_0x226f40[_0x9e68('0x4a')]=_0x5737cb;if(_0x38048a[_0x9e68('0x3b')][_0x9e68('0x4b')]){_0x413fc7['include']=[{'all':!![]}];}return db[_0x9e68('0x36')][_0x9e68('0x4c')](_0x413fc7);})[_0x9e68('0x1c')](function(_0x4a15c4){_0x226f40[_0x9e68('0x4d')]=_0x4a15c4;return _0x226f40;})[_0x9e68('0x1c')](respondWithFilteredResult(_0x49036a,_0x413fc7))[_0x9e68('0x27')](handleError(_0x49036a,null));};exports[_0x9e68('0x4e')]=function(_0x3103e6,_0x240541){var _0x26db33={'raw':![],'where':{'id':_0x3103e6['params']['id']}},_0x12e44f={};_0x12e44f[_0x9e68('0x39')]=_[_0x9e68('0x4f')](db[_0x9e68('0x36')][_0x9e68('0x37')]);_0x12e44f[_0x9e68('0x3b')]=_['keys'](_0x3103e6[_0x9e68('0x3b')]);_0x12e44f['filters']=_['intersection'](_0x12e44f['model'],_0x12e44f[_0x9e68('0x3b')]);_0x26db33[_0x9e68('0x3e')]=_[_0x9e68('0x3d')](_0x12e44f[_0x9e68('0x39')],qs[_0x9e68('0x3f')](_0x3103e6['query']['fields']));_0x26db33['attributes']=_0x26db33['attributes'][_0x9e68('0x40')]?_0x26db33['attributes']:_0x12e44f['model'];if(_0x3103e6[_0x9e68('0x3b')][_0x9e68('0x4b')]){_0x26db33['include']=[{'all':!![]}];}_0x26db33=_[_0x9e68('0x46')]({},_0x26db33,_0x3103e6[_0x9e68('0x49')]);return db[_0x9e68('0x36')][_0x9e68('0x50')](_0x26db33)[_0x9e68('0x1c')](handleEntityNotFound(_0x240541,null))['then'](respondWithResult(_0x240541,null))[_0x9e68('0x27')](handleError(_0x240541,null));};exports[_0x9e68('0x51')]=function(_0x2ddf16,_0x42e95a){return db['ZendeskConfiguration'][_0x9e68('0x51')](_0x2ddf16[_0x9e68('0x52')],{})[_0x9e68('0x1c')](respondWithResult(_0x42e95a,0xc9))[_0x9e68('0x27')](handleError(_0x42e95a,null));};exports[_0x9e68('0x53')]=function(_0x2b8a8a,_0x279efe){if(_0x2b8a8a[_0x9e68('0x52')]['id']){delete _0x2b8a8a[_0x9e68('0x52')]['id'];}return db[_0x9e68('0x36')][_0x9e68('0x50')]({'where':{'id':_0x2b8a8a[_0x9e68('0x54')]['id']}})[_0x9e68('0x1c')](handleEntityNotFound(_0x279efe,null))[_0x9e68('0x1c')](saveUpdates(_0x2b8a8a[_0x9e68('0x52')],null))['then'](respondWithResult(_0x279efe,null))[_0x9e68('0x27')](handleError(_0x279efe,null));};exports['destroy']=function(_0x3f3349,_0x124abd){return db[_0x9e68('0x36')][_0x9e68('0x50')]({'where':{'id':_0x3f3349[_0x9e68('0x54')]['id']}})['then'](handleEntityNotFound(_0x124abd,null))[_0x9e68('0x1c')](removeEntity(_0x124abd,null))[_0x9e68('0x27')](handleError(_0x124abd,null));};exports[_0x9e68('0x55')]=function(_0x551907,_0x2b10f8,_0x3bd728){var _0x1f7cb2={};var _0x4e6832={};var _0x1e3435;var _0x234e46;return db[_0x9e68('0x36')][_0x9e68('0x56')]({'where':{'id':_0x551907[_0x9e68('0x54')]['id']}})['then'](handleEntityNotFound(_0x2b10f8,null))[_0x9e68('0x1c')](function(_0x5189e6){if(_0x5189e6){_0x1e3435=_0x5189e6;_0x4e6832[_0x9e68('0x39')]=_[_0x9e68('0x4f')](db[_0x9e68('0x57')][_0x9e68('0x37')]);_0x4e6832[_0x9e68('0x3b')]=_[_0x9e68('0x4f')](_0x551907[_0x9e68('0x3b')]);_0x4e6832[_0x9e68('0x3c')]=_[_0x9e68('0x3d')](_0x4e6832['model'],_0x4e6832[_0x9e68('0x3b')]);_0x1f7cb2['attributes']=_[_0x9e68('0x3d')](_0x4e6832[_0x9e68('0x39')],qs[_0x9e68('0x3f')](_0x551907[_0x9e68('0x3b')][_0x9e68('0x3f')]));_0x1f7cb2[_0x9e68('0x3e')]=_0x1f7cb2['attributes']['length']?_0x1f7cb2[_0x9e68('0x3e')]:_0x4e6832[_0x9e68('0x39')];_0x1f7cb2[_0x9e68('0x58')]=qs[_0x9e68('0x42')](_0x551907['query'][_0x9e68('0x42')]);_0x1f7cb2[_0x9e68('0x43')]=qs['filters'](_['pick'](_0x551907[_0x9e68('0x3b')],_0x4e6832[_0x9e68('0x3c')]));if(_0x551907[_0x9e68('0x3b')][_0x9e68('0x45')]){_0x1f7cb2['where']=_['merge'](_0x1f7cb2[_0x9e68('0x43')],{'$or':_[_0x9e68('0x35')](_0x1f7cb2['attributes'],function(_0x59bdb1){var _0x402d37={};_0x402d37[_0x59bdb1]={'$like':'%'+_0x551907[_0x9e68('0x3b')]['filter']+'%'};return _0x402d37;})});}_0x1f7cb2=_[_0x9e68('0x46')]({},_0x1f7cb2,_0x551907['options']);return _0x1e3435[_0x9e68('0x55')](_0x1f7cb2);}})[_0x9e68('0x1c')](function(_0x17f2cd){if(_0x17f2cd){_0x234e46=_0x17f2cd[_0x9e68('0x40')];if(!_0x551907['query'][_0x9e68('0x41')](_0x9e68('0x59'))){_0x1f7cb2[_0x9e68('0x2c')]=qs[_0x9e68('0x2c')](_0x551907['query'][_0x9e68('0x2c')]);_0x1f7cb2['offset']=qs[_0x9e68('0x2b')](_0x551907[_0x9e68('0x3b')][_0x9e68('0x2b')]);}return _0x1e3435['getFields'](_0x1f7cb2);}})[_0x9e68('0x1c')](function(_0x38f743){if(_0x38f743){return _0x38f743?{'count':_0x234e46,'rows':_0x38f743}:null;}})[_0x9e68('0x1c')](respondWithResult(_0x2b10f8,null))['catch'](handleError(_0x2b10f8,null));};exports[_0x9e68('0x5a')]=function(_0x541a17,_0x27afa4,_0xa7321f){var _0x4efa74={};var _0x1d858b={};var _0x130d56;var _0x370e4c;return db[_0x9e68('0x36')][_0x9e68('0x56')]({'where':{'id':_0x541a17[_0x9e68('0x54')]['id']}})[_0x9e68('0x1c')](handleEntityNotFound(_0x27afa4,null))['then'](function(_0x16500d){if(_0x16500d){_0x130d56=_0x16500d;_0x1d858b[_0x9e68('0x39')]=_[_0x9e68('0x4f')](db['ZendeskField'][_0x9e68('0x37')]);_0x1d858b[_0x9e68('0x3b')]=_['keys'](_0x541a17[_0x9e68('0x3b')]);_0x1d858b[_0x9e68('0x3c')]=_['intersection'](_0x1d858b[_0x9e68('0x39')],_0x1d858b[_0x9e68('0x3b')]);_0x4efa74[_0x9e68('0x3e')]=_[_0x9e68('0x3d')](_0x1d858b[_0x9e68('0x39')],qs[_0x9e68('0x3f')](_0x541a17[_0x9e68('0x3b')][_0x9e68('0x3f')]));_0x4efa74[_0x9e68('0x3e')]=_0x4efa74[_0x9e68('0x3e')][_0x9e68('0x40')]?_0x4efa74['attributes']:_0x1d858b[_0x9e68('0x39')];_0x4efa74['order']=qs[_0x9e68('0x42')](_0x541a17[_0x9e68('0x3b')][_0x9e68('0x42')]);_0x4efa74[_0x9e68('0x43')]=qs['filters'](_[_0x9e68('0x44')](_0x541a17[_0x9e68('0x3b')],_0x1d858b[_0x9e68('0x3c')]));if(_0x541a17[_0x9e68('0x3b')][_0x9e68('0x45')]){_0x4efa74[_0x9e68('0x43')]=_[_0x9e68('0x46')](_0x4efa74[_0x9e68('0x43')],{'$or':_['map'](_0x4efa74[_0x9e68('0x3e')],function(_0x5bf143){var _0x5bad04={};_0x5bad04[_0x5bf143]={'$like':'%'+_0x541a17[_0x9e68('0x3b')]['filter']+'%'};return _0x5bad04;})});}_0x4efa74=_[_0x9e68('0x46')]({},_0x4efa74,_0x541a17[_0x9e68('0x49')]);return _0x130d56['getSubjects'](_0x4efa74);}})[_0x9e68('0x1c')](function(_0x2cb319){if(_0x2cb319){_0x370e4c=_0x2cb319[_0x9e68('0x40')];if(!_0x541a17[_0x9e68('0x3b')][_0x9e68('0x41')]('nolimit')){_0x4efa74['limit']=qs['limit'](_0x541a17[_0x9e68('0x3b')][_0x9e68('0x2c')]);_0x4efa74[_0x9e68('0x2b')]=qs['offset'](_0x541a17[_0x9e68('0x3b')][_0x9e68('0x2b')]);}return _0x130d56[_0x9e68('0x5a')](_0x4efa74);}})[_0x9e68('0x1c')](function(_0x14af0a){if(_0x14af0a){return _0x14af0a?{'count':_0x370e4c,'rows':_0x14af0a}:null;}})['then'](respondWithResult(_0x27afa4,null))[_0x9e68('0x27')](handleError(_0x27afa4,null));};exports[_0x9e68('0x5b')]=function(_0x27e3fa,_0x263a5d,_0x1abda2){var _0x1201df={};var _0x4dca52={};var _0x268cb9;var _0x2d7d8a;return db[_0x9e68('0x36')][_0x9e68('0x56')]({'where':{'id':_0x27e3fa['params']['id']}})[_0x9e68('0x1c')](handleEntityNotFound(_0x263a5d,null))[_0x9e68('0x1c')](function(_0xfdbc7d){if(_0xfdbc7d){_0x268cb9=_0xfdbc7d;_0x4dca52[_0x9e68('0x39')]=_[_0x9e68('0x4f')](db['ZendeskField']['rawAttributes']);_0x4dca52['query']=_[_0x9e68('0x4f')](_0x27e3fa[_0x9e68('0x3b')]);_0x4dca52[_0x9e68('0x3c')]=_[_0x9e68('0x3d')](_0x4dca52[_0x9e68('0x39')],_0x4dca52['query']);_0x1201df['attributes']=_[_0x9e68('0x3d')](_0x4dca52[_0x9e68('0x39')],qs[_0x9e68('0x3f')](_0x27e3fa[_0x9e68('0x3b')][_0x9e68('0x3f')]));_0x1201df['attributes']=_0x1201df['attributes'][_0x9e68('0x40')]?_0x1201df[_0x9e68('0x3e')]:_0x4dca52[_0x9e68('0x39')];_0x1201df[_0x9e68('0x58')]=qs[_0x9e68('0x42')](_0x27e3fa[_0x9e68('0x3b')][_0x9e68('0x42')]);_0x1201df['where']=qs[_0x9e68('0x3c')](_[_0x9e68('0x44')](_0x27e3fa[_0x9e68('0x3b')],_0x4dca52['filters']));if(_0x27e3fa[_0x9e68('0x3b')][_0x9e68('0x45')]){_0x1201df[_0x9e68('0x43')]=_['merge'](_0x1201df[_0x9e68('0x43')],{'$or':_[_0x9e68('0x35')](_0x1201df['attributes'],function(_0x4918c0){var _0x1ddcc2={};_0x1ddcc2[_0x4918c0]={'$like':'%'+_0x27e3fa[_0x9e68('0x3b')][_0x9e68('0x45')]+'%'};return _0x1ddcc2;})});}_0x1201df=_[_0x9e68('0x46')]({},_0x1201df,_0x27e3fa[_0x9e68('0x49')]);return _0x268cb9[_0x9e68('0x5b')](_0x1201df);}})['then'](function(_0x5a5f71){if(_0x5a5f71){_0x2d7d8a=_0x5a5f71[_0x9e68('0x40')];if(!_0x27e3fa[_0x9e68('0x3b')]['hasOwnProperty']('nolimit')){_0x1201df[_0x9e68('0x2c')]=qs[_0x9e68('0x2c')](_0x27e3fa[_0x9e68('0x3b')]['limit']);_0x1201df['offset']=qs[_0x9e68('0x2b')](_0x27e3fa['query']['offset']);}return _0x268cb9[_0x9e68('0x5b')](_0x1201df);}})[_0x9e68('0x1c')](function(_0x14e0e6){if(_0x14e0e6){return _0x14e0e6?{'count':_0x2d7d8a,'rows':_0x14e0e6}:null;}})[_0x9e68('0x1c')](respondWithResult(_0x263a5d,null))[_0x9e68('0x27')](handleError(_0x263a5d,null));};exports[_0x9e68('0x5c')]=function(_0x4a9243,_0x37e57a,_0xcd8a7e){var _0x17201a={};var _0xdb9762={};var _0x14d6d2;var _0x7c7523;return db[_0x9e68('0x36')][_0x9e68('0x56')]({'where':{'id':_0x4a9243[_0x9e68('0x54')]['id']}})[_0x9e68('0x1c')](handleEntityNotFound(_0x37e57a,null))[_0x9e68('0x1c')](function(_0xafd241){if(_0xafd241){_0x14d6d2=_0xafd241;_0xdb9762[_0x9e68('0x39')]=_['keys'](db['Tag'][_0x9e68('0x37')]);_0xdb9762['query']=_[_0x9e68('0x4f')](_0x4a9243[_0x9e68('0x3b')]);_0xdb9762[_0x9e68('0x3c')]=_[_0x9e68('0x3d')](_0xdb9762[_0x9e68('0x39')],_0xdb9762['query']);_0x17201a['attributes']=_[_0x9e68('0x3d')](_0xdb9762[_0x9e68('0x39')],qs[_0x9e68('0x3f')](_0x4a9243['query'][_0x9e68('0x3f')]));_0x17201a['attributes']=_0x17201a[_0x9e68('0x3e')][_0x9e68('0x40')]?_0x17201a['attributes']:_0xdb9762[_0x9e68('0x39')];_0x17201a[_0x9e68('0x58')]=qs[_0x9e68('0x42')](_0x4a9243['query'][_0x9e68('0x42')]);_0x17201a[_0x9e68('0x43')]=qs[_0x9e68('0x3c')](_[_0x9e68('0x44')](_0x4a9243[_0x9e68('0x3b')],_0xdb9762[_0x9e68('0x3c')]));if(_0x4a9243[_0x9e68('0x3b')][_0x9e68('0x45')]){_0x17201a['where']=_['merge'](_0x17201a[_0x9e68('0x43')],{'$or':_['map'](_0x17201a[_0x9e68('0x3e')],function(_0x3fd51a){var _0x11dbe4={};_0x11dbe4[_0x3fd51a]={'$like':'%'+_0x4a9243[_0x9e68('0x3b')]['filter']+'%'};return _0x11dbe4;})});}_0x17201a=_[_0x9e68('0x46')]({},_0x17201a,_0x4a9243['options']);return _0x14d6d2[_0x9e68('0x5c')](_0x17201a);}})[_0x9e68('0x1c')](function(_0x12be68){if(_0x12be68){_0x7c7523=_0x12be68['length'];if(!_0x4a9243[_0x9e68('0x3b')][_0x9e68('0x41')](_0x9e68('0x59'))){_0x17201a[_0x9e68('0x2c')]=qs[_0x9e68('0x2c')](_0x4a9243[_0x9e68('0x3b')][_0x9e68('0x2c')]);_0x17201a[_0x9e68('0x2b')]=qs[_0x9e68('0x2b')](_0x4a9243[_0x9e68('0x3b')]['offset']);}return _0x14d6d2[_0x9e68('0x5c')](_0x17201a);}})[_0x9e68('0x1c')](function(_0xb3d0c5){if(_0xb3d0c5){return _0xb3d0c5?{'count':_0x7c7523,'rows':_0xb3d0c5}:null;}})[_0x9e68('0x1c')](respondWithResult(_0x37e57a,null))[_0x9e68('0x27')](handleError(_0x37e57a,null));};exports[_0x9e68('0x5d')]=function(_0x5f0a23,_0x494443,_0x1156cc){if(_0x5f0a23[_0x9e68('0x52')]['id']){delete _0x5f0a23[_0x9e68('0x52')]['id'];}return db[_0x9e68('0x36')][_0x9e68('0x56')]({'where':{'id':_0x5f0a23[_0x9e68('0x54')]['id']}})[_0x9e68('0x1c')](handleEntityNotFound(_0x494443,null))[_0x9e68('0x1c')](function(_0xa70d82){if(_0xa70d82){return _0xa70d82[_0x9e68('0x5d')](_0x5f0a23[_0x9e68('0x52')][_0x9e68('0x5e')]||[]);}return null;})[_0x9e68('0x1c')](respondWithResult(_0x494443,null))[_0x9e68('0x27')](handleError(_0x494443,null));};