Built motion from commit (unavailable).|2.4.20
[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 _0xf9c6=['sort','where','merge','filter','options','includeAll','include','findAll','rows','show','rawAttributes','find','body','params','destroy','findOne','DeskField','order','pick','getFields','getSubjects','hasOwnProperty','getDescriptions','Tag','getTags','setTags','ids','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','jayson/promise','client','http','test','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','info','request\x20sent','debug','DeskConfiguration,\x20%s,\x20%s,\x20%s','error','code','DeskConfiguration,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','count','offset','limit','json','apply','save','update','then','stack','name','send','index','map','DeskConfiguration','type','key','model','query','keys','filters','intersection','attributes','fields','length','nolimit'];(function(_0x7d56bc,_0x6be057){var _0x48bb64=function(_0x1b5e0e){while(--_0x1b5e0e){_0x7d56bc['push'](_0x7d56bc['shift']());}};_0x48bb64(++_0x6be057);}(_0xf9c6,0x19b));var _0x6f9c=function(_0x3d535c,_0x139ddf){_0x3d535c=_0x3d535c-0x0;var _0x3d6418=_0xf9c6[_0x3d535c];return _0x3d6418;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x6f9c('0x0'));var rimraf=require(_0x6f9c('0x1'));var zipdir=require(_0x6f9c('0x2'));var jsonpatch=require(_0x6f9c('0x3'));var rp=require(_0x6f9c('0x4'));var moment=require(_0x6f9c('0x5'));var BPromise=require(_0x6f9c('0x6'));var Mustache=require(_0x6f9c('0x7'));var util=require('util');var path=require(_0x6f9c('0x8'));var sox=require(_0x6f9c('0x9'));var csv=require(_0x6f9c('0xa'));var ejs=require(_0x6f9c('0xb'));var fs=require('fs');var _=require(_0x6f9c('0xc'));var squel=require(_0x6f9c('0xd'));var crypto=require(_0x6f9c('0xe'));var jsforce=require(_0x6f9c('0xf'));var deskjs=require(_0x6f9c('0x10'));var toCsv=require('to-csv');var querystring=require(_0x6f9c('0x11'));var Papa=require(_0x6f9c('0x12'));var Redis=require(_0x6f9c('0x13'));var authService=require(_0x6f9c('0x14'));var qs=require(_0x6f9c('0x15'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x6f9c('0x16'))('api');var utils=require(_0x6f9c('0x17'));var config=require(_0x6f9c('0x18'));var db=require(_0x6f9c('0x19'))['db'];var jayson=require(_0x6f9c('0x1a'));var client=jayson[_0x6f9c('0x1b')][_0x6f9c('0x1c')]({'port':0x232a});function checkPasswordPattern(_0x42f505,_0x20bbda,_0x52bebe){if(_0x52bebe){var _0x4329b2=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x4329b2[_0x6f9c('0x1d')](_0x20bbda)){return _0x42f505;}else{throw new db['Sequelize']['ValidationError'](_0x6f9c('0x1e'));}}else{return _0x42f505;}}function respondWithRpcPromise(_0x481aa1,_0x10395a,_0x4ff25c,_0x4686e9){return new BPromise(function(_0x47e327,_0x2eb57b){var _0x6017ef=_0x4686e9||client;return _0x6017ef['request'](_0x481aa1,_0x4ff25c)['then'](function(_0xa79c50){logger[_0x6f9c('0x1f')]('DeskConfiguration,\x20%s,\x20%s',_0x10395a,_0x6f9c('0x20'));logger[_0x6f9c('0x21')](_0x6f9c('0x22'),_0x10395a,_0x6f9c('0x20'),JSON['stringify'](_0xa79c50));if(_0xa79c50[_0x6f9c('0x23')]){if(_0xa79c50[_0x6f9c('0x23')][_0x6f9c('0x24')]===0x1f4){logger['error'](_0x6f9c('0x25'),_0x10395a,_0xa79c50[_0x6f9c('0x23')][_0x6f9c('0x26')]);return _0x2eb57b(_0xa79c50[_0x6f9c('0x23')]['message']);}logger['error'](_0x6f9c('0x25'),_0x10395a,_0xa79c50[_0x6f9c('0x23')]['message']);return _0x47e327(_0xa79c50['error'][_0x6f9c('0x26')]);}else{logger[_0x6f9c('0x1f')]('DeskConfiguration,\x20%s,\x20%s',_0x10395a,'request\x20sent');_0x47e327(_0xa79c50[_0x6f9c('0x27')]['message']);}})[_0x6f9c('0x28')](function(_0x14e1e9){logger[_0x6f9c('0x23')](_0x6f9c('0x25'),_0x10395a,_0x14e1e9);_0x2eb57b(_0x14e1e9);});});}function respondWithStatusCode(_0x4daede,_0x25634d){_0x25634d=_0x25634d||0xcc;return function(_0x7454c3){if(_0x7454c3){return _0x4daede[_0x6f9c('0x29')](_0x25634d);}return _0x4daede[_0x6f9c('0x2a')](_0x25634d)[_0x6f9c('0x2b')]();};}function respondWithResult(_0x82f218,_0x107333){_0x107333=_0x107333||0xc8;return function(_0x90f8c4){if(_0x90f8c4){return _0x82f218[_0x6f9c('0x2a')](_0x107333)['json'](_0x90f8c4);}};}function respondWithFilteredResult(_0x18500e,_0x45bed7){return function(_0x5d946b){if(_0x5d946b){var _0x281a43=_0x5d946b[_0x6f9c('0x2c')],_0x28f4fc=_0x45bed7['offset'],_0x4f6e8f=_0x45bed7[_0x6f9c('0x2d')]+_0x45bed7[_0x6f9c('0x2e')],_0x4fda2c;if(_0x4f6e8f>=_0x281a43){_0x4f6e8f=_0x281a43;_0x4fda2c=0xc8;}else{_0x4fda2c=0xce;}_0x18500e[_0x6f9c('0x2a')](_0x4fda2c);return _0x18500e['set']('Content-Range',_0x28f4fc+'-'+_0x4f6e8f+'/'+_0x281a43)[_0x6f9c('0x2f')](_0x5d946b);}return null;};}function patchUpdates(_0x31a632){return function(_0x4d39ee){try{jsonpatch[_0x6f9c('0x30')](_0x4d39ee,_0x31a632,!![]);}catch(_0x45792f){return BPromise['reject'](_0x45792f);}return _0x4d39ee[_0x6f9c('0x31')]();};}function saveUpdates(_0x10ffaa,_0x6d2d12){return function(_0x4e8012){if(_0x4e8012){return _0x4e8012[_0x6f9c('0x32')](_0x10ffaa)[_0x6f9c('0x33')](function(_0x4a3557){return _0x4a3557;});}return null;};}function removeEntity(_0x5dd20a,_0x1f7050){return function(_0x40ff2d){if(_0x40ff2d){return _0x40ff2d['destroy']()['then'](function(){_0x5dd20a[_0x6f9c('0x2a')](0xcc)[_0x6f9c('0x2b')]();});}};}function handleEntityNotFound(_0xabed4e,_0x5eac0b){return function(_0x3aac22){if(!_0x3aac22){_0xabed4e[_0x6f9c('0x29')](0x194);}return _0x3aac22;};}function handleError(_0x871b36,_0x20c881){_0x20c881=_0x20c881||0x1f4;return function(_0x269fc6){logger[_0x6f9c('0x23')](_0x269fc6[_0x6f9c('0x34')]);if(_0x269fc6[_0x6f9c('0x35')]){delete _0x269fc6[_0x6f9c('0x35')];}_0x871b36[_0x6f9c('0x2a')](_0x20c881)[_0x6f9c('0x36')](_0x269fc6);};}exports[_0x6f9c('0x37')]=function(_0x4f5cdd,_0x36453e){var _0x22b9b7={},_0x19ccf6={},_0x287914={'count':0x0,'rows':[]};var _0x55d8a8=_[_0x6f9c('0x38')](db[_0x6f9c('0x39')]['rawAttributes'],function(_0xe071f8){return{'name':_0xe071f8['fieldName'],'type':_0xe071f8[_0x6f9c('0x3a')][_0x6f9c('0x3b')]};});_0x19ccf6[_0x6f9c('0x3c')]=_[_0x6f9c('0x38')](_0x55d8a8,_0x6f9c('0x35'));_0x19ccf6[_0x6f9c('0x3d')]=_[_0x6f9c('0x3e')](_0x4f5cdd['query']);_0x19ccf6[_0x6f9c('0x3f')]=_[_0x6f9c('0x40')](_0x19ccf6[_0x6f9c('0x3c')],_0x19ccf6['query']);_0x22b9b7[_0x6f9c('0x41')]=_[_0x6f9c('0x40')](_0x19ccf6[_0x6f9c('0x3c')],qs[_0x6f9c('0x42')](_0x4f5cdd['query'][_0x6f9c('0x42')]));_0x22b9b7[_0x6f9c('0x41')]=_0x22b9b7[_0x6f9c('0x41')][_0x6f9c('0x43')]?_0x22b9b7[_0x6f9c('0x41')]:_0x19ccf6[_0x6f9c('0x3c')];if(!_0x4f5cdd[_0x6f9c('0x3d')]['hasOwnProperty'](_0x6f9c('0x44'))){_0x22b9b7[_0x6f9c('0x2e')]=qs[_0x6f9c('0x2e')](_0x4f5cdd[_0x6f9c('0x3d')]['limit']);_0x22b9b7[_0x6f9c('0x2d')]=qs[_0x6f9c('0x2d')](_0x4f5cdd[_0x6f9c('0x3d')][_0x6f9c('0x2d')]);}_0x22b9b7['order']=qs[_0x6f9c('0x45')](_0x4f5cdd['query'][_0x6f9c('0x45')]);_0x22b9b7[_0x6f9c('0x46')]=qs[_0x6f9c('0x3f')](_['pick'](_0x4f5cdd['query'],_0x19ccf6['filters']));if(_0x4f5cdd[_0x6f9c('0x3d')]['filter']){_0x22b9b7[_0x6f9c('0x46')]=_[_0x6f9c('0x47')](_0x22b9b7[_0x6f9c('0x46')],{'$or':_[_0x6f9c('0x38')](_0x55d8a8,function(_0x1f509f){if(_0x1f509f[_0x6f9c('0x3a')]!=='VIRTUAL'){var _0x376c2f={};_0x376c2f[_0x1f509f[_0x6f9c('0x35')]]={'$like':'%'+_0x4f5cdd[_0x6f9c('0x3d')][_0x6f9c('0x48')]+'%'};return _0x376c2f;}})});}_0x22b9b7=_[_0x6f9c('0x47')]({},_0x22b9b7,_0x4f5cdd[_0x6f9c('0x49')]);var _0x2fb896={'where':_0x22b9b7[_0x6f9c('0x46')]};return db[_0x6f9c('0x39')][_0x6f9c('0x2c')](_0x2fb896)[_0x6f9c('0x33')](function(_0x3cb66b){_0x287914['count']=_0x3cb66b;if(_0x4f5cdd[_0x6f9c('0x3d')][_0x6f9c('0x4a')]){_0x22b9b7[_0x6f9c('0x4b')]=[{'all':!![]}];}return db[_0x6f9c('0x39')][_0x6f9c('0x4c')](_0x22b9b7);})[_0x6f9c('0x33')](function(_0x3f0f02){_0x287914[_0x6f9c('0x4d')]=_0x3f0f02;return _0x287914;})['then'](respondWithFilteredResult(_0x36453e,_0x22b9b7))[_0x6f9c('0x28')](handleError(_0x36453e,null));};exports[_0x6f9c('0x4e')]=function(_0x17403b,_0x1fffee){var _0x33e909={'raw':![],'where':{'id':_0x17403b['params']['id']}},_0x213a53={};_0x213a53[_0x6f9c('0x3c')]=_[_0x6f9c('0x3e')](db[_0x6f9c('0x39')][_0x6f9c('0x4f')]);_0x213a53['query']=_['keys'](_0x17403b[_0x6f9c('0x3d')]);_0x213a53['filters']=_['intersection'](_0x213a53[_0x6f9c('0x3c')],_0x213a53[_0x6f9c('0x3d')]);_0x33e909[_0x6f9c('0x41')]=_[_0x6f9c('0x40')](_0x213a53[_0x6f9c('0x3c')],qs[_0x6f9c('0x42')](_0x17403b[_0x6f9c('0x3d')][_0x6f9c('0x42')]));_0x33e909[_0x6f9c('0x41')]=_0x33e909[_0x6f9c('0x41')][_0x6f9c('0x43')]?_0x33e909[_0x6f9c('0x41')]:_0x213a53[_0x6f9c('0x3c')];if(_0x17403b[_0x6f9c('0x3d')]['includeAll']){_0x33e909['include']=[{'all':!![]}];}_0x33e909=_[_0x6f9c('0x47')]({},_0x33e909,_0x17403b['options']);return db[_0x6f9c('0x39')][_0x6f9c('0x50')](_0x33e909)[_0x6f9c('0x33')](handleEntityNotFound(_0x1fffee,null))['then'](respondWithResult(_0x1fffee,null))['catch'](handleError(_0x1fffee,null));};exports['create']=function(_0x748db8,_0x48ae6a){return db[_0x6f9c('0x39')]['create'](_0x748db8[_0x6f9c('0x51')],{})[_0x6f9c('0x33')](respondWithResult(_0x48ae6a,0xc9))[_0x6f9c('0x28')](handleError(_0x48ae6a,null));};exports[_0x6f9c('0x32')]=function(_0x20f1a7,_0x3460a9){if(_0x20f1a7['body']['id']){delete _0x20f1a7[_0x6f9c('0x51')]['id'];}return db[_0x6f9c('0x39')][_0x6f9c('0x50')]({'where':{'id':_0x20f1a7[_0x6f9c('0x52')]['id']}})[_0x6f9c('0x33')](handleEntityNotFound(_0x3460a9,null))[_0x6f9c('0x33')](saveUpdates(_0x20f1a7[_0x6f9c('0x51')],null))['then'](respondWithResult(_0x3460a9,null))[_0x6f9c('0x28')](handleError(_0x3460a9,null));};exports[_0x6f9c('0x53')]=function(_0x163b22,_0x11389c){return db[_0x6f9c('0x39')][_0x6f9c('0x50')]({'where':{'id':_0x163b22[_0x6f9c('0x52')]['id']}})[_0x6f9c('0x33')](handleEntityNotFound(_0x11389c,null))['then'](removeEntity(_0x11389c,null))['catch'](handleError(_0x11389c,null));};exports['getFields']=function(_0x548124,_0x3107ef,_0x14b409){var _0x13de70={};var _0x9e8a83={};var _0x34e04c;var _0x31da06;return db[_0x6f9c('0x39')][_0x6f9c('0x54')]({'where':{'id':_0x548124['params']['id']}})[_0x6f9c('0x33')](handleEntityNotFound(_0x3107ef,null))[_0x6f9c('0x33')](function(_0x2d7f7d){if(_0x2d7f7d){_0x34e04c=_0x2d7f7d;_0x9e8a83[_0x6f9c('0x3c')]=_[_0x6f9c('0x3e')](db[_0x6f9c('0x55')]['rawAttributes']);_0x9e8a83[_0x6f9c('0x3d')]=_['keys'](_0x548124['query']);_0x9e8a83[_0x6f9c('0x3f')]=_[_0x6f9c('0x40')](_0x9e8a83['model'],_0x9e8a83[_0x6f9c('0x3d')]);_0x13de70['attributes']=_['intersection'](_0x9e8a83[_0x6f9c('0x3c')],qs[_0x6f9c('0x42')](_0x548124[_0x6f9c('0x3d')][_0x6f9c('0x42')]));_0x13de70[_0x6f9c('0x41')]=_0x13de70[_0x6f9c('0x41')][_0x6f9c('0x43')]?_0x13de70[_0x6f9c('0x41')]:_0x9e8a83[_0x6f9c('0x3c')];_0x13de70[_0x6f9c('0x56')]=qs[_0x6f9c('0x45')](_0x548124[_0x6f9c('0x3d')]['sort']);_0x13de70['where']=qs[_0x6f9c('0x3f')](_[_0x6f9c('0x57')](_0x548124[_0x6f9c('0x3d')],_0x9e8a83[_0x6f9c('0x3f')]));if(_0x548124['query'][_0x6f9c('0x48')]){_0x13de70[_0x6f9c('0x46')]=_[_0x6f9c('0x47')](_0x13de70[_0x6f9c('0x46')],{'$or':_[_0x6f9c('0x38')](_0x13de70['attributes'],function(_0x254231){var _0x2e348a={};_0x2e348a[_0x254231]={'$like':'%'+_0x548124['query']['filter']+'%'};return _0x2e348a;})});}_0x13de70=_[_0x6f9c('0x47')]({},_0x13de70,_0x548124[_0x6f9c('0x49')]);return _0x34e04c[_0x6f9c('0x58')](_0x13de70);}})[_0x6f9c('0x33')](function(_0x405688){if(_0x405688){_0x31da06=_0x405688[_0x6f9c('0x43')];if(!_0x548124['query']['hasOwnProperty']('nolimit')){_0x13de70['limit']=qs[_0x6f9c('0x2e')](_0x548124['query'][_0x6f9c('0x2e')]);_0x13de70[_0x6f9c('0x2d')]=qs[_0x6f9c('0x2d')](_0x548124[_0x6f9c('0x3d')]['offset']);}return _0x34e04c[_0x6f9c('0x58')](_0x13de70);}})['then'](function(_0x4a8842){if(_0x4a8842){return _0x4a8842?{'count':_0x31da06,'rows':_0x4a8842}:null;}})[_0x6f9c('0x33')](respondWithResult(_0x3107ef,null))['catch'](handleError(_0x3107ef,null));};exports[_0x6f9c('0x59')]=function(_0x497fab,_0x5be5c1,_0x1e1efd){var _0x3f2cef={};var _0x57482f={};var _0x3a749a;var _0x3a9218;return db[_0x6f9c('0x39')][_0x6f9c('0x54')]({'where':{'id':_0x497fab[_0x6f9c('0x52')]['id']}})[_0x6f9c('0x33')](handleEntityNotFound(_0x5be5c1,null))['then'](function(_0x53bac2){if(_0x53bac2){_0x3a749a=_0x53bac2;_0x57482f[_0x6f9c('0x3c')]=_[_0x6f9c('0x3e')](db[_0x6f9c('0x55')][_0x6f9c('0x4f')]);_0x57482f[_0x6f9c('0x3d')]=_[_0x6f9c('0x3e')](_0x497fab[_0x6f9c('0x3d')]);_0x57482f[_0x6f9c('0x3f')]=_[_0x6f9c('0x40')](_0x57482f[_0x6f9c('0x3c')],_0x57482f[_0x6f9c('0x3d')]);_0x3f2cef[_0x6f9c('0x41')]=_[_0x6f9c('0x40')](_0x57482f[_0x6f9c('0x3c')],qs[_0x6f9c('0x42')](_0x497fab[_0x6f9c('0x3d')][_0x6f9c('0x42')]));_0x3f2cef['attributes']=_0x3f2cef['attributes'][_0x6f9c('0x43')]?_0x3f2cef[_0x6f9c('0x41')]:_0x57482f['model'];_0x3f2cef['order']=qs[_0x6f9c('0x45')](_0x497fab[_0x6f9c('0x3d')][_0x6f9c('0x45')]);_0x3f2cef[_0x6f9c('0x46')]=qs[_0x6f9c('0x3f')](_[_0x6f9c('0x57')](_0x497fab[_0x6f9c('0x3d')],_0x57482f['filters']));if(_0x497fab['query'][_0x6f9c('0x48')]){_0x3f2cef['where']=_[_0x6f9c('0x47')](_0x3f2cef['where'],{'$or':_[_0x6f9c('0x38')](_0x3f2cef[_0x6f9c('0x41')],function(_0x3cbc87){var _0x1133b4={};_0x1133b4[_0x3cbc87]={'$like':'%'+_0x497fab[_0x6f9c('0x3d')][_0x6f9c('0x48')]+'%'};return _0x1133b4;})});}_0x3f2cef=_[_0x6f9c('0x47')]({},_0x3f2cef,_0x497fab[_0x6f9c('0x49')]);return _0x3a749a[_0x6f9c('0x59')](_0x3f2cef);}})[_0x6f9c('0x33')](function(_0x396b23){if(_0x396b23){_0x3a9218=_0x396b23[_0x6f9c('0x43')];if(!_0x497fab[_0x6f9c('0x3d')][_0x6f9c('0x5a')](_0x6f9c('0x44'))){_0x3f2cef[_0x6f9c('0x2e')]=qs['limit'](_0x497fab[_0x6f9c('0x3d')]['limit']);_0x3f2cef[_0x6f9c('0x2d')]=qs[_0x6f9c('0x2d')](_0x497fab[_0x6f9c('0x3d')][_0x6f9c('0x2d')]);}return _0x3a749a['getSubjects'](_0x3f2cef);}})[_0x6f9c('0x33')](function(_0x5102fa){if(_0x5102fa){return _0x5102fa?{'count':_0x3a9218,'rows':_0x5102fa}:null;}})['then'](respondWithResult(_0x5be5c1,null))[_0x6f9c('0x28')](handleError(_0x5be5c1,null));};exports[_0x6f9c('0x5b')]=function(_0x1e229f,_0xccf364,_0x3c8dd2){var _0x1f9844={};var _0x4ad4a8={};var _0x1d987e;var _0xada7fb;return db[_0x6f9c('0x39')][_0x6f9c('0x54')]({'where':{'id':_0x1e229f[_0x6f9c('0x52')]['id']}})[_0x6f9c('0x33')](handleEntityNotFound(_0xccf364,null))[_0x6f9c('0x33')](function(_0x18c86a){if(_0x18c86a){_0x1d987e=_0x18c86a;_0x4ad4a8[_0x6f9c('0x3c')]=_[_0x6f9c('0x3e')](db[_0x6f9c('0x55')]['rawAttributes']);_0x4ad4a8[_0x6f9c('0x3d')]=_['keys'](_0x1e229f[_0x6f9c('0x3d')]);_0x4ad4a8['filters']=_[_0x6f9c('0x40')](_0x4ad4a8[_0x6f9c('0x3c')],_0x4ad4a8['query']);_0x1f9844[_0x6f9c('0x41')]=_['intersection'](_0x4ad4a8[_0x6f9c('0x3c')],qs['fields'](_0x1e229f[_0x6f9c('0x3d')][_0x6f9c('0x42')]));_0x1f9844[_0x6f9c('0x41')]=_0x1f9844[_0x6f9c('0x41')][_0x6f9c('0x43')]?_0x1f9844[_0x6f9c('0x41')]:_0x4ad4a8['model'];_0x1f9844['order']=qs[_0x6f9c('0x45')](_0x1e229f[_0x6f9c('0x3d')][_0x6f9c('0x45')]);_0x1f9844[_0x6f9c('0x46')]=qs[_0x6f9c('0x3f')](_[_0x6f9c('0x57')](_0x1e229f['query'],_0x4ad4a8[_0x6f9c('0x3f')]));if(_0x1e229f[_0x6f9c('0x3d')][_0x6f9c('0x48')]){_0x1f9844[_0x6f9c('0x46')]=_[_0x6f9c('0x47')](_0x1f9844[_0x6f9c('0x46')],{'$or':_[_0x6f9c('0x38')](_0x1f9844[_0x6f9c('0x41')],function(_0x733896){var _0xb75501={};_0xb75501[_0x733896]={'$like':'%'+_0x1e229f[_0x6f9c('0x3d')][_0x6f9c('0x48')]+'%'};return _0xb75501;})});}_0x1f9844=_[_0x6f9c('0x47')]({},_0x1f9844,_0x1e229f['options']);return _0x1d987e[_0x6f9c('0x5b')](_0x1f9844);}})[_0x6f9c('0x33')](function(_0x251629){if(_0x251629){_0xada7fb=_0x251629[_0x6f9c('0x43')];if(!_0x1e229f['query']['hasOwnProperty'](_0x6f9c('0x44'))){_0x1f9844[_0x6f9c('0x2e')]=qs[_0x6f9c('0x2e')](_0x1e229f['query'][_0x6f9c('0x2e')]);_0x1f9844[_0x6f9c('0x2d')]=qs[_0x6f9c('0x2d')](_0x1e229f[_0x6f9c('0x3d')][_0x6f9c('0x2d')]);}return _0x1d987e[_0x6f9c('0x5b')](_0x1f9844);}})['then'](function(_0x1c6553){if(_0x1c6553){return _0x1c6553?{'count':_0xada7fb,'rows':_0x1c6553}:null;}})[_0x6f9c('0x33')](respondWithResult(_0xccf364,null))['catch'](handleError(_0xccf364,null));};exports['getTags']=function(_0x981bf1,_0x6b7e66,_0x19e2cb){var _0x51f598={};var _0x40e690={};var _0x1cd177;var _0x26b92d;return db[_0x6f9c('0x39')][_0x6f9c('0x54')]({'where':{'id':_0x981bf1['params']['id']}})['then'](handleEntityNotFound(_0x6b7e66,null))[_0x6f9c('0x33')](function(_0x47727d){if(_0x47727d){_0x1cd177=_0x47727d;_0x40e690[_0x6f9c('0x3c')]=_['keys'](db[_0x6f9c('0x5c')][_0x6f9c('0x4f')]);_0x40e690[_0x6f9c('0x3d')]=_[_0x6f9c('0x3e')](_0x981bf1['query']);_0x40e690[_0x6f9c('0x3f')]=_['intersection'](_0x40e690[_0x6f9c('0x3c')],_0x40e690[_0x6f9c('0x3d')]);_0x51f598[_0x6f9c('0x41')]=_['intersection'](_0x40e690[_0x6f9c('0x3c')],qs[_0x6f9c('0x42')](_0x981bf1[_0x6f9c('0x3d')]['fields']));_0x51f598[_0x6f9c('0x41')]=_0x51f598[_0x6f9c('0x41')]['length']?_0x51f598[_0x6f9c('0x41')]:_0x40e690['model'];_0x51f598['order']=qs[_0x6f9c('0x45')](_0x981bf1['query'][_0x6f9c('0x45')]);_0x51f598[_0x6f9c('0x46')]=qs[_0x6f9c('0x3f')](_[_0x6f9c('0x57')](_0x981bf1[_0x6f9c('0x3d')],_0x40e690[_0x6f9c('0x3f')]));if(_0x981bf1[_0x6f9c('0x3d')]['filter']){_0x51f598['where']=_[_0x6f9c('0x47')](_0x51f598[_0x6f9c('0x46')],{'$or':_[_0x6f9c('0x38')](_0x51f598[_0x6f9c('0x41')],function(_0x4ab05e){var _0x1844b3={};_0x1844b3[_0x4ab05e]={'$like':'%'+_0x981bf1['query'][_0x6f9c('0x48')]+'%'};return _0x1844b3;})});}_0x51f598=_[_0x6f9c('0x47')]({},_0x51f598,_0x981bf1[_0x6f9c('0x49')]);return _0x1cd177[_0x6f9c('0x5d')](_0x51f598);}})[_0x6f9c('0x33')](function(_0x572e1c){if(_0x572e1c){_0x26b92d=_0x572e1c[_0x6f9c('0x43')];if(!_0x981bf1[_0x6f9c('0x3d')]['hasOwnProperty'](_0x6f9c('0x44'))){_0x51f598[_0x6f9c('0x2e')]=qs[_0x6f9c('0x2e')](_0x981bf1[_0x6f9c('0x3d')]['limit']);_0x51f598['offset']=qs[_0x6f9c('0x2d')](_0x981bf1[_0x6f9c('0x3d')][_0x6f9c('0x2d')]);}return _0x1cd177[_0x6f9c('0x5d')](_0x51f598);}})[_0x6f9c('0x33')](function(_0x1ff181){if(_0x1ff181){return _0x1ff181?{'count':_0x26b92d,'rows':_0x1ff181}:null;}})[_0x6f9c('0x33')](respondWithResult(_0x6b7e66,null))[_0x6f9c('0x28')](handleError(_0x6b7e66,null));};exports['setTags']=function(_0x12bfef,_0x46f573,_0x2caf64){if(_0x12bfef['body']['id']){delete _0x12bfef[_0x6f9c('0x51')]['id'];}return db[_0x6f9c('0x39')][_0x6f9c('0x54')]({'where':{'id':_0x12bfef[_0x6f9c('0x52')]['id']}})[_0x6f9c('0x33')](handleEntityNotFound(_0x46f573,null))[_0x6f9c('0x33')](function(_0x1bdb39){if(_0x1bdb39){return _0x1bdb39[_0x6f9c('0x5e')](_0x12bfef[_0x6f9c('0x51')][_0x6f9c('0x5f')]||[]);}return null;})['then'](respondWithResult(_0x46f573,null))[_0x6f9c('0x28')](handleError(_0x46f573,null));};