Built motion from commit 67e5df37.|2.0.68
[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 _0x35f5=['ejs','lodash','crypto','desk.js','to-csv','papaparse','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','jayson/promise','client','http','then','FreshdeskConfiguration,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','info','result','catch','sendStatus','end','status','offset','Content-Range','json','apply','reject','update','destroy','stack','name','send','index','model','keys','FreshdeskConfiguration','rawAttributes','query','dateStart','dateEnd','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','sort','where','day','merge','map','filter','options','count','includeAll','include','findAll','rows','show','find','create','body','params','getFields','findOne','FreshdeskField','pick','getSubjects','order','getDescriptions','getTags','Tag','setTags','ids','fast-json-patch','moment','bluebird','mustache','util'];(function(_0x9aada2,_0xd2d349){var _0x196dff=function(_0x5ad061){while(--_0x5ad061){_0x9aada2['push'](_0x9aada2['shift']());}};_0x196dff(++_0xd2d349);}(_0x35f5,0x100));var _0x535f=function(_0x5d31f3,_0x4239b0){_0x5d31f3=_0x5d31f3-0x0;var _0x1cc88c=_0x35f5[_0x5d31f3];return _0x1cc88c;};'use strict';var jsonpatch=require(_0x535f('0x0'));var rp=require('request-promise');var moment=require(_0x535f('0x1'));var BPromise=require(_0x535f('0x2'));var Mustache=require(_0x535f('0x3'));var util=require(_0x535f('0x4'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x535f('0x5'));var fs=require('fs');var _=require(_0x535f('0x6'));var squel=require('squel');var crypto=require(_0x535f('0x7'));var jsforce=require('jsforce');var deskjs=require(_0x535f('0x8'));var toCsv=require(_0x535f('0x9'));var querystring=require('querystring');var Papa=require(_0x535f('0xa'));var qs=require('../../components/parsers/qs');var logger=require(_0x535f('0xb'))(_0x535f('0xc'));var utils=require(_0x535f('0xd'));var config=require(_0x535f('0xe'));var db=require(_0x535f('0xf'))['db'];var jayson=require(_0x535f('0x10'));var client=jayson[_0x535f('0x11')][_0x535f('0x12')]({'port':0x232a});function respondWithRpcPromise(_0x546837,_0xd7ae17,_0x3ebf54,_0x1e1c58){return new BPromise(function(_0x336e28,_0x39f1be){var _0x2d24cf=_0x1e1c58||client;return _0x2d24cf['request'](_0x546837,_0x3ebf54)[_0x535f('0x13')](function(_0x5e91ec){logger['info'](_0x535f('0x14'),_0xd7ae17,_0x535f('0x15'));logger[_0x535f('0x16')]('FreshdeskConfiguration,\x20%s,\x20%s,\x20%s',_0xd7ae17,'request\x20sent',JSON[_0x535f('0x17')](_0x5e91ec));if(_0x5e91ec['error']){if(_0x5e91ec[_0x535f('0x18')][_0x535f('0x19')]===0x1f4){logger['error']('FreshdeskConfiguration,\x20%s,\x20%s',_0xd7ae17,_0x5e91ec[_0x535f('0x18')]['message']);return _0x39f1be(_0x5e91ec[_0x535f('0x18')][_0x535f('0x1a')]);}logger[_0x535f('0x18')](_0x535f('0x14'),_0xd7ae17,_0x5e91ec[_0x535f('0x18')][_0x535f('0x1a')]);return _0x336e28(_0x5e91ec[_0x535f('0x18')][_0x535f('0x1a')]);}else{logger[_0x535f('0x1b')](_0x535f('0x14'),_0xd7ae17,_0x535f('0x15'));_0x336e28(_0x5e91ec[_0x535f('0x1c')][_0x535f('0x1a')]);}})[_0x535f('0x1d')](function(_0xa59e26){logger[_0x535f('0x18')](_0x535f('0x14'),_0xd7ae17,_0xa59e26);_0x39f1be(_0xa59e26);});});}function respondWithStatusCode(_0x1a8623,_0x4d08ee){_0x4d08ee=_0x4d08ee||0xcc;return function(_0x5565ff){if(_0x5565ff){return _0x1a8623[_0x535f('0x1e')](_0x4d08ee);}return _0x1a8623['status'](_0x4d08ee)[_0x535f('0x1f')]();};}function respondWithResult(_0xc0a552,_0x295a0f){_0x295a0f=_0x295a0f||0xc8;return function(_0x2f02b1){if(_0x2f02b1){return _0xc0a552[_0x535f('0x20')](_0x295a0f)['json'](_0x2f02b1);}};}function respondWithFilteredResult(_0x45eb4b,_0x2feda0){return function(_0x4c9222){if(_0x4c9222){var _0x197e3b=_0x4c9222['count'],_0x296d9c=_0x2feda0['offset'],_0xa6cf8=_0x2feda0[_0x535f('0x21')]+_0x2feda0['limit'],_0x293e05;if(_0xa6cf8>=_0x197e3b){_0xa6cf8=_0x197e3b;_0x293e05=0xc8;}else{_0x293e05=0xce;}_0x45eb4b[_0x535f('0x20')](_0x293e05);return _0x45eb4b['set'](_0x535f('0x22'),_0x296d9c+'-'+_0xa6cf8+'/'+_0x197e3b)[_0x535f('0x23')](_0x4c9222);}return null;};}function patchUpdates(_0x35a754){return function(_0x5c792c){try{jsonpatch[_0x535f('0x24')](_0x5c792c,_0x35a754,!![]);}catch(_0x447bf1){return BPromise[_0x535f('0x25')](_0x447bf1);}return _0x5c792c['save']();};}function saveUpdates(_0x122b7d,_0x38b464){return function(_0x285b9d){if(_0x285b9d){return _0x285b9d[_0x535f('0x26')](_0x122b7d)['then'](function(_0x5aac25){return _0x5aac25;});}return null;};}function removeEntity(_0x1bb199,_0x2af771){return function(_0x5239dc){if(_0x5239dc){return _0x5239dc[_0x535f('0x27')]()['then'](function(){_0x1bb199['status'](0xcc)[_0x535f('0x1f')]();});}};}function handleEntityNotFound(_0x55afae,_0x11f713){return function(_0x12e616){if(!_0x12e616){_0x55afae[_0x535f('0x1e')](0x194);}return _0x12e616;};}function handleError(_0x30b92b,_0x597307){_0x597307=_0x597307||0x1f4;return function(_0x410555){logger[_0x535f('0x18')](_0x410555[_0x535f('0x28')]);if(_0x410555[_0x535f('0x29')]){delete _0x410555[_0x535f('0x29')];}_0x30b92b[_0x535f('0x20')](_0x597307)[_0x535f('0x2a')](_0x410555);};}exports[_0x535f('0x2b')]=function(_0x34169b,_0x1a436c){var _0x316229={},_0x19df29={},_0x33782d={'count':0x0,'rows':[]};_0x19df29[_0x535f('0x2c')]=_[_0x535f('0x2d')](db[_0x535f('0x2e')][_0x535f('0x2f')]);var _0x38a6b4={'dateStart':_0x34169b[_0x535f('0x30')][_0x535f('0x31')],'dateEnd':_0x34169b['query'][_0x535f('0x32')]};delete _0x34169b[_0x535f('0x30')][_0x535f('0x31')];delete _0x34169b[_0x535f('0x30')]['dateEnd'];_0x19df29[_0x535f('0x30')]=_[_0x535f('0x2d')](_0x34169b[_0x535f('0x30')]);_0x19df29[_0x535f('0x33')]=_[_0x535f('0x34')](_0x19df29[_0x535f('0x2c')],_0x19df29[_0x535f('0x30')]);_0x316229[_0x535f('0x35')]=_[_0x535f('0x34')](_0x19df29[_0x535f('0x2c')],qs[_0x535f('0x36')](_0x34169b[_0x535f('0x30')][_0x535f('0x36')]));_0x316229[_0x535f('0x35')]=_0x316229['attributes'][_0x535f('0x37')]?_0x316229[_0x535f('0x35')]:_0x19df29[_0x535f('0x2c')];if(!_0x34169b[_0x535f('0x30')][_0x535f('0x38')](_0x535f('0x39'))){_0x316229[_0x535f('0x3a')]=qs[_0x535f('0x3a')](_0x34169b[_0x535f('0x30')][_0x535f('0x3a')]);_0x316229[_0x535f('0x21')]=qs[_0x535f('0x21')](_0x34169b[_0x535f('0x30')][_0x535f('0x21')]);}_0x316229['order']=qs[_0x535f('0x3b')](_0x34169b['query']['sort']);_0x316229[_0x535f('0x3c')]=qs[_0x535f('0x33')](_['pick'](_0x34169b[_0x535f('0x30')],_0x19df29[_0x535f('0x33')]));if(_0x38a6b4['dateStart']){if(_0x38a6b4[_0x535f('0x32')]){_0x38a6b4['dateEnd']=moment(_0x38a6b4['dateEnd'])['add'](0x1,_0x535f('0x3d'));}else{_0x38a6b4['dateEnd']=moment(_0x38a6b4['dateStart'])['add'](0x1,_0x535f('0x3d'));}_[_0x535f('0x3e')](_0x316229[_0x535f('0x3c')],{'createdAt':{'$gte':_0x38a6b4[_0x535f('0x31')],'$lte':_0x38a6b4[_0x535f('0x32')]}});}if(_0x34169b[_0x535f('0x30')]['filter']){_0x316229['where']=_['merge'](_0x316229[_0x535f('0x3c')],{'$or':_[_0x535f('0x3f')](_0x316229['attributes'],function(_0x1afb35){var _0x11942d={};_0x11942d[_0x1afb35]={'$like':'%'+_0x34169b[_0x535f('0x30')][_0x535f('0x40')]+'%'};return _0x11942d;})});}_0x316229=_[_0x535f('0x3e')]({},_0x316229,_0x34169b[_0x535f('0x41')]);var _0x35afc7={'where':_0x316229[_0x535f('0x3c')]};return db[_0x535f('0x2e')]['count'](_0x35afc7)[_0x535f('0x13')](function(_0x57a958){_0x33782d[_0x535f('0x42')]=_0x57a958;if(_0x34169b['query'][_0x535f('0x43')]){_0x316229[_0x535f('0x44')]=[{'all':!![]}];}return db['FreshdeskConfiguration'][_0x535f('0x45')](_0x316229);})['then'](function(_0x438b9a){_0x33782d[_0x535f('0x46')]=_0x438b9a;return _0x33782d;})[_0x535f('0x13')](respondWithFilteredResult(_0x1a436c,_0x316229))[_0x535f('0x1d')](handleError(_0x1a436c,null));};exports[_0x535f('0x47')]=function(_0xc77b70,_0x52bdf8){var _0x35383e={'raw':![],'where':{'id':_0xc77b70['params']['id']}},_0x51f4d4={};_0x51f4d4['model']=_['keys'](db['FreshdeskConfiguration']['rawAttributes']);_0x51f4d4[_0x535f('0x30')]=_['keys'](_0xc77b70['query']);_0x51f4d4['filters']=_[_0x535f('0x34')](_0x51f4d4[_0x535f('0x2c')],_0x51f4d4[_0x535f('0x30')]);_0x35383e[_0x535f('0x35')]=_[_0x535f('0x34')](_0x51f4d4[_0x535f('0x2c')],qs['fields'](_0xc77b70['query'][_0x535f('0x36')]));_0x35383e[_0x535f('0x35')]=_0x35383e['attributes']['length']?_0x35383e[_0x535f('0x35')]:_0x51f4d4[_0x535f('0x2c')];if(_0xc77b70[_0x535f('0x30')][_0x535f('0x43')]){_0x35383e[_0x535f('0x44')]=[{'all':!![]}];}_0x35383e=_[_0x535f('0x3e')]({},_0x35383e,_0xc77b70[_0x535f('0x41')]);return db[_0x535f('0x2e')][_0x535f('0x48')](_0x35383e)[_0x535f('0x13')](handleEntityNotFound(_0x52bdf8,null))['then'](respondWithResult(_0x52bdf8,null))[_0x535f('0x1d')](handleError(_0x52bdf8,null));};exports['create']=function(_0x4ac3bd,_0x208af3){return db[_0x535f('0x2e')][_0x535f('0x49')](_0x4ac3bd[_0x535f('0x4a')],{})[_0x535f('0x13')](respondWithResult(_0x208af3,0xc9))[_0x535f('0x1d')](handleError(_0x208af3,null));};exports[_0x535f('0x26')]=function(_0x186182,_0x445c80){if(_0x186182[_0x535f('0x4a')]['id']){delete _0x186182['body']['id'];}return db[_0x535f('0x2e')][_0x535f('0x48')]({'where':{'id':_0x186182['params']['id']}})['then'](handleEntityNotFound(_0x445c80,null))[_0x535f('0x13')](saveUpdates(_0x186182[_0x535f('0x4a')],null))[_0x535f('0x13')](respondWithResult(_0x445c80,null))['catch'](handleError(_0x445c80,null));};exports['destroy']=function(_0x3b1b6c,_0x53e0f7){return db[_0x535f('0x2e')]['find']({'where':{'id':_0x3b1b6c[_0x535f('0x4b')]['id']}})[_0x535f('0x13')](handleEntityNotFound(_0x53e0f7,null))[_0x535f('0x13')](removeEntity(_0x53e0f7,null))[_0x535f('0x1d')](handleError(_0x53e0f7,null));};exports[_0x535f('0x4c')]=function(_0x25a3f6,_0x32460e,_0x1c6d04){var _0xe0b9f9={};var _0x497129={};var _0x5c7443;var _0x15897a;return db[_0x535f('0x2e')][_0x535f('0x4d')]({'where':{'id':_0x25a3f6[_0x535f('0x4b')]['id']}})['then'](handleEntityNotFound(_0x32460e,null))[_0x535f('0x13')](function(_0x5161c2){if(_0x5161c2){_0x5c7443=_0x5161c2;_0x497129['model']=_[_0x535f('0x2d')](db[_0x535f('0x4e')]['rawAttributes']);_0x497129['query']=_['keys'](_0x25a3f6[_0x535f('0x30')]);_0x497129['filters']=_[_0x535f('0x34')](_0x497129[_0x535f('0x2c')],_0x497129[_0x535f('0x30')]);_0xe0b9f9[_0x535f('0x35')]=_[_0x535f('0x34')](_0x497129[_0x535f('0x2c')],qs[_0x535f('0x36')](_0x25a3f6['query']['fields']));_0xe0b9f9[_0x535f('0x35')]=_0xe0b9f9[_0x535f('0x35')][_0x535f('0x37')]?_0xe0b9f9[_0x535f('0x35')]:_0x497129[_0x535f('0x2c')];_0xe0b9f9['order']=qs['sort'](_0x25a3f6[_0x535f('0x30')][_0x535f('0x3b')]);_0xe0b9f9[_0x535f('0x3c')]=qs[_0x535f('0x33')](_[_0x535f('0x4f')](_0x25a3f6[_0x535f('0x30')],_0x497129[_0x535f('0x33')]));if(_0x25a3f6['query']['filter']){_0xe0b9f9[_0x535f('0x3c')]=_[_0x535f('0x3e')](_0xe0b9f9[_0x535f('0x3c')],{'$or':_[_0x535f('0x3f')](_0xe0b9f9['attributes'],function(_0x4ce5af){var _0x1f2421={};_0x1f2421[_0x4ce5af]={'$like':'%'+_0x25a3f6[_0x535f('0x30')][_0x535f('0x40')]+'%'};return _0x1f2421;})});}_0xe0b9f9=_[_0x535f('0x3e')]({},_0xe0b9f9,_0x25a3f6['options']);return _0x5c7443[_0x535f('0x4c')](_0xe0b9f9);}})['then'](function(_0x414515){if(_0x414515){_0x15897a=_0x414515[_0x535f('0x37')];if(!_0x25a3f6[_0x535f('0x30')][_0x535f('0x38')]('nolimit')){_0xe0b9f9[_0x535f('0x3a')]=qs[_0x535f('0x3a')](_0x25a3f6[_0x535f('0x30')][_0x535f('0x3a')]);_0xe0b9f9[_0x535f('0x21')]=qs['offset'](_0x25a3f6[_0x535f('0x30')][_0x535f('0x21')]);}return _0x5c7443[_0x535f('0x4c')](_0xe0b9f9);}})[_0x535f('0x13')](function(_0x38f59d){if(_0x38f59d){return _0x38f59d?{'count':_0x15897a,'rows':_0x38f59d}:null;}})['then'](respondWithResult(_0x32460e,null))[_0x535f('0x1d')](handleError(_0x32460e,null));};exports[_0x535f('0x50')]=function(_0x155d7c,_0x491e95,_0x214e33){var _0x3bc26d={};var _0x2e851b={};var _0xcfef3a;var _0x442b6a;return db[_0x535f('0x2e')][_0x535f('0x4d')]({'where':{'id':_0x155d7c[_0x535f('0x4b')]['id']}})['then'](handleEntityNotFound(_0x491e95,null))[_0x535f('0x13')](function(_0x2ad613){if(_0x2ad613){_0xcfef3a=_0x2ad613;_0x2e851b[_0x535f('0x2c')]=_[_0x535f('0x2d')](db[_0x535f('0x4e')][_0x535f('0x2f')]);_0x2e851b[_0x535f('0x30')]=_[_0x535f('0x2d')](_0x155d7c[_0x535f('0x30')]);_0x2e851b[_0x535f('0x33')]=_[_0x535f('0x34')](_0x2e851b[_0x535f('0x2c')],_0x2e851b[_0x535f('0x30')]);_0x3bc26d['attributes']=_['intersection'](_0x2e851b[_0x535f('0x2c')],qs['fields'](_0x155d7c[_0x535f('0x30')][_0x535f('0x36')]));_0x3bc26d[_0x535f('0x35')]=_0x3bc26d['attributes'][_0x535f('0x37')]?_0x3bc26d['attributes']:_0x2e851b['model'];_0x3bc26d[_0x535f('0x51')]=qs[_0x535f('0x3b')](_0x155d7c[_0x535f('0x30')][_0x535f('0x3b')]);_0x3bc26d[_0x535f('0x3c')]=qs[_0x535f('0x33')](_[_0x535f('0x4f')](_0x155d7c[_0x535f('0x30')],_0x2e851b[_0x535f('0x33')]));if(_0x155d7c[_0x535f('0x30')][_0x535f('0x40')]){_0x3bc26d[_0x535f('0x3c')]=_['merge'](_0x3bc26d['where'],{'$or':_[_0x535f('0x3f')](_0x3bc26d[_0x535f('0x35')],function(_0x15cf22){var _0x4f4aa8={};_0x4f4aa8[_0x15cf22]={'$like':'%'+_0x155d7c[_0x535f('0x30')][_0x535f('0x40')]+'%'};return _0x4f4aa8;})});}_0x3bc26d=_[_0x535f('0x3e')]({},_0x3bc26d,_0x155d7c[_0x535f('0x41')]);return _0xcfef3a[_0x535f('0x50')](_0x3bc26d);}})[_0x535f('0x13')](function(_0x3b3569){if(_0x3b3569){_0x442b6a=_0x3b3569[_0x535f('0x37')];if(!_0x155d7c['query']['hasOwnProperty'](_0x535f('0x39'))){_0x3bc26d['limit']=qs[_0x535f('0x3a')](_0x155d7c[_0x535f('0x30')]['limit']);_0x3bc26d[_0x535f('0x21')]=qs['offset'](_0x155d7c[_0x535f('0x30')][_0x535f('0x21')]);}return _0xcfef3a[_0x535f('0x50')](_0x3bc26d);}})[_0x535f('0x13')](function(_0x40d464){if(_0x40d464){return _0x40d464?{'count':_0x442b6a,'rows':_0x40d464}:null;}})[_0x535f('0x13')](respondWithResult(_0x491e95,null))[_0x535f('0x1d')](handleError(_0x491e95,null));};exports[_0x535f('0x52')]=function(_0x23fcbe,_0x5df58,_0xb389df){var _0x4fdc60={};var _0xb41c07={};var _0xbae4e1;var _0x5233cf;return db[_0x535f('0x2e')][_0x535f('0x4d')]({'where':{'id':_0x23fcbe[_0x535f('0x4b')]['id']}})[_0x535f('0x13')](handleEntityNotFound(_0x5df58,null))['then'](function(_0x531fe3){if(_0x531fe3){_0xbae4e1=_0x531fe3;_0xb41c07['model']=_[_0x535f('0x2d')](db['FreshdeskField'][_0x535f('0x2f')]);_0xb41c07[_0x535f('0x30')]=_[_0x535f('0x2d')](_0x23fcbe[_0x535f('0x30')]);_0xb41c07[_0x535f('0x33')]=_[_0x535f('0x34')](_0xb41c07['model'],_0xb41c07[_0x535f('0x30')]);_0x4fdc60[_0x535f('0x35')]=_['intersection'](_0xb41c07[_0x535f('0x2c')],qs[_0x535f('0x36')](_0x23fcbe[_0x535f('0x30')][_0x535f('0x36')]));_0x4fdc60['attributes']=_0x4fdc60[_0x535f('0x35')][_0x535f('0x37')]?_0x4fdc60[_0x535f('0x35')]:_0xb41c07[_0x535f('0x2c')];_0x4fdc60[_0x535f('0x51')]=qs[_0x535f('0x3b')](_0x23fcbe[_0x535f('0x30')]['sort']);_0x4fdc60[_0x535f('0x3c')]=qs[_0x535f('0x33')](_['pick'](_0x23fcbe[_0x535f('0x30')],_0xb41c07['filters']));if(_0x23fcbe[_0x535f('0x30')]['filter']){_0x4fdc60[_0x535f('0x3c')]=_[_0x535f('0x3e')](_0x4fdc60[_0x535f('0x3c')],{'$or':_[_0x535f('0x3f')](_0x4fdc60['attributes'],function(_0x4ead70){var _0x29972c={};_0x29972c[_0x4ead70]={'$like':'%'+_0x23fcbe[_0x535f('0x30')][_0x535f('0x40')]+'%'};return _0x29972c;})});}_0x4fdc60=_['merge']({},_0x4fdc60,_0x23fcbe[_0x535f('0x41')]);return _0xbae4e1[_0x535f('0x52')](_0x4fdc60);}})[_0x535f('0x13')](function(_0x33a4c4){if(_0x33a4c4){_0x5233cf=_0x33a4c4['length'];if(!_0x23fcbe[_0x535f('0x30')][_0x535f('0x38')]('nolimit')){_0x4fdc60[_0x535f('0x3a')]=qs[_0x535f('0x3a')](_0x23fcbe[_0x535f('0x30')][_0x535f('0x3a')]);_0x4fdc60[_0x535f('0x21')]=qs['offset'](_0x23fcbe['query']['offset']);}return _0xbae4e1[_0x535f('0x52')](_0x4fdc60);}})[_0x535f('0x13')](function(_0x31473f){if(_0x31473f){return _0x31473f?{'count':_0x5233cf,'rows':_0x31473f}:null;}})[_0x535f('0x13')](respondWithResult(_0x5df58,null))[_0x535f('0x1d')](handleError(_0x5df58,null));};exports[_0x535f('0x53')]=function(_0x3acf15,_0x270475,_0x4ca677){var _0x56a3d6={};var _0x546378={};var _0x2a5e64;var _0x12c6bc;return db[_0x535f('0x2e')][_0x535f('0x4d')]({'where':{'id':_0x3acf15[_0x535f('0x4b')]['id']}})[_0x535f('0x13')](handleEntityNotFound(_0x270475,null))[_0x535f('0x13')](function(_0xf7a94f){if(_0xf7a94f){_0x2a5e64=_0xf7a94f;_0x546378[_0x535f('0x2c')]=_[_0x535f('0x2d')](db[_0x535f('0x54')][_0x535f('0x2f')]);_0x546378[_0x535f('0x30')]=_[_0x535f('0x2d')](_0x3acf15[_0x535f('0x30')]);_0x546378[_0x535f('0x33')]=_[_0x535f('0x34')](_0x546378[_0x535f('0x2c')],_0x546378['query']);_0x56a3d6[_0x535f('0x35')]=_[_0x535f('0x34')](_0x546378[_0x535f('0x2c')],qs['fields'](_0x3acf15[_0x535f('0x30')]['fields']));_0x56a3d6[_0x535f('0x35')]=_0x56a3d6[_0x535f('0x35')]['length']?_0x56a3d6['attributes']:_0x546378[_0x535f('0x2c')];_0x56a3d6[_0x535f('0x51')]=qs[_0x535f('0x3b')](_0x3acf15[_0x535f('0x30')][_0x535f('0x3b')]);_0x56a3d6[_0x535f('0x3c')]=qs['filters'](_[_0x535f('0x4f')](_0x3acf15['query'],_0x546378[_0x535f('0x33')]));if(_0x3acf15['query'][_0x535f('0x40')]){_0x56a3d6['where']=_[_0x535f('0x3e')](_0x56a3d6[_0x535f('0x3c')],{'$or':_[_0x535f('0x3f')](_0x56a3d6[_0x535f('0x35')],function(_0x1da2d9){var _0x552481={};_0x552481[_0x1da2d9]={'$like':'%'+_0x3acf15[_0x535f('0x30')][_0x535f('0x40')]+'%'};return _0x552481;})});}_0x56a3d6=_[_0x535f('0x3e')]({},_0x56a3d6,_0x3acf15[_0x535f('0x41')]);return _0x2a5e64['getTags'](_0x56a3d6);}})[_0x535f('0x13')](function(_0x4200fa){if(_0x4200fa){_0x12c6bc=_0x4200fa[_0x535f('0x37')];if(!_0x3acf15['query'][_0x535f('0x38')]('nolimit')){_0x56a3d6[_0x535f('0x3a')]=qs[_0x535f('0x3a')](_0x3acf15[_0x535f('0x30')][_0x535f('0x3a')]);_0x56a3d6[_0x535f('0x21')]=qs['offset'](_0x3acf15['query'][_0x535f('0x21')]);}return _0x2a5e64[_0x535f('0x53')](_0x56a3d6);}})['then'](function(_0x9a99fd){if(_0x9a99fd){return _0x9a99fd?{'count':_0x12c6bc,'rows':_0x9a99fd}:null;}})[_0x535f('0x13')](respondWithResult(_0x270475,null))[_0x535f('0x1d')](handleError(_0x270475,null));};exports['setTags']=function(_0x1d6998,_0xa5e4,_0x353a82){if(_0x1d6998[_0x535f('0x4a')]['id']){delete _0x1d6998['body']['id'];}return db[_0x535f('0x2e')][_0x535f('0x4d')]({'where':{'id':_0x1d6998[_0x535f('0x4b')]['id']}})['then'](handleEntityNotFound(_0xa5e4,null))[_0x535f('0x13')](function(_0x416142){if(_0x416142){return _0x416142[_0x535f('0x55')](_0x1d6998['body'][_0x535f('0x56')]||[]);}return null;})[_0x535f('0x13')](respondWithResult(_0xa5e4,null))[_0x535f('0x1d')](handleError(_0xa5e4,null));};