be44a22d0d149f0c827014b80bc142255fafef3b
[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 _0xd97b=['rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','sendStatus','status','end','offset','limit','undefined','count','set','Content-Range','json','apply','reject','update','destroy','error','stack','name','send','index','map','FreshdeskConfiguration','fieldName','type','key','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','options','then','includeAll','rows','keys','rawAttributes','include','catch','create','body','find','params','getFields','findOne','order','getSubjects','FreshdeskField','getDescriptions','getTags','Tag','setTags','ids','eml-format'];(function(_0x27f8ab,_0x134841){var _0x508566=function(_0x3b819b){while(--_0x3b819b){_0x27f8ab['push'](_0x27f8ab['shift']());}};_0x508566(++_0x134841);}(_0xd97b,0x1ad));var _0xbd97=function(_0x12ad6b,_0x42b30f){_0x12ad6b=_0x12ad6b-0x0;var _0x287db6=_0xd97b[_0x12ad6b];return _0x287db6;};'use strict';var emlformat=require(_0xbd97('0x0'));var rimraf=require(_0xbd97('0x1'));var zipdir=require(_0xbd97('0x2'));var jsonpatch=require(_0xbd97('0x3'));var rp=require(_0xbd97('0x4'));var moment=require(_0xbd97('0x5'));var BPromise=require(_0xbd97('0x6'));var Mustache=require(_0xbd97('0x7'));var util=require(_0xbd97('0x8'));var path=require(_0xbd97('0x9'));var sox=require('sox');var csv=require(_0xbd97('0xa'));var ejs=require(_0xbd97('0xb'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xbd97('0xc'));var squel=require('squel');var crypto=require(_0xbd97('0xd'));var jsforce=require(_0xbd97('0xe'));var deskjs=require(_0xbd97('0xf'));var toCsv=require('to-csv');var querystring=require(_0xbd97('0x10'));var Papa=require(_0xbd97('0x11'));var Redis=require(_0xbd97('0x12'));var authService=require(_0xbd97('0x13'));var qs=require(_0xbd97('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xbd97('0x15'));var logger=require(_0xbd97('0x16'))(_0xbd97('0x17'));var utils=require('../../config/utils');var config=require(_0xbd97('0x18'));var licenseUtil=require('../../config/license/util');var db=require(_0xbd97('0x19'))['db'];function respondWithStatusCode(_0xb98d84,_0x1ed0bb){_0x1ed0bb=_0x1ed0bb||0xcc;return function(_0x3c658e){if(_0x3c658e){return _0xb98d84[_0xbd97('0x1a')](_0x1ed0bb);}return _0xb98d84[_0xbd97('0x1b')](_0x1ed0bb)[_0xbd97('0x1c')]();};}function respondWithResult(_0x3ef1c0,_0xc4b678){_0xc4b678=_0xc4b678||0xc8;return function(_0x1f1aa4){if(_0x1f1aa4){return _0x3ef1c0[_0xbd97('0x1b')](_0xc4b678)['json'](_0x1f1aa4);}};}function respondWithFilteredResult(_0x5ca70e,_0x608b6e){return function(_0xd83e7d){if(_0xd83e7d){var _0x180970=typeof _0x608b6e[_0xbd97('0x1d')]==='undefined'&&typeof _0x608b6e[_0xbd97('0x1e')]===_0xbd97('0x1f');var _0x5435c4=_0xd83e7d['count'];var _0x232e70=_0x180970?0x0:_0x608b6e['offset'];var _0x3b3211=_0x180970?_0xd83e7d[_0xbd97('0x20')]:_0x608b6e[_0xbd97('0x1d')]+_0x608b6e[_0xbd97('0x1e')];var _0x32f58c;if(_0x3b3211>=_0x5435c4){_0x3b3211=_0x5435c4;_0x32f58c=0xc8;}else{_0x32f58c=0xce;}_0x5ca70e[_0xbd97('0x1b')](_0x32f58c);return _0x5ca70e[_0xbd97('0x21')](_0xbd97('0x22'),_0x232e70+'-'+_0x3b3211+'/'+_0x5435c4)[_0xbd97('0x23')](_0xd83e7d);}return null;};}function patchUpdates(_0x3aaa0b){return function(_0x5efe18){try{jsonpatch[_0xbd97('0x24')](_0x5efe18,_0x3aaa0b,!![]);}catch(_0x3f5434){return BPromise[_0xbd97('0x25')](_0x3f5434);}return _0x5efe18['save']();};}function saveUpdates(_0x3c93da,_0x1e2919){return function(_0x293407){if(_0x293407){return _0x293407[_0xbd97('0x26')](_0x3c93da)['then'](function(_0x41870c){return _0x41870c;});}return null;};}function removeEntity(_0x4a9558,_0x23c2a8){return function(_0x2887ee){if(_0x2887ee){return _0x2887ee[_0xbd97('0x27')]()['then'](function(){_0x4a9558[_0xbd97('0x1b')](0xcc)[_0xbd97('0x1c')]();});}};}function handleEntityNotFound(_0x2ac5ca,_0x4dbe52){return function(_0x454161){if(!_0x454161){_0x2ac5ca[_0xbd97('0x1a')](0x194);}return _0x454161;};}function handleError(_0x22a3ff,_0x5d1255){_0x5d1255=_0x5d1255||0x1f4;return function(_0x1bc75f){logger[_0xbd97('0x28')](_0x1bc75f[_0xbd97('0x29')]);if(_0x1bc75f['name']){delete _0x1bc75f[_0xbd97('0x2a')];}_0x22a3ff[_0xbd97('0x1b')](_0x5d1255)[_0xbd97('0x2b')](_0x1bc75f);};}exports[_0xbd97('0x2c')]=function(_0x37de42,_0x16c6d0){var _0x4d9676={},_0x427d94={},_0x4f8534={'count':0x0,'rows':[]};var _0x391730=_[_0xbd97('0x2d')](db[_0xbd97('0x2e')]['rawAttributes'],function(_0xfd2128){return{'name':_0xfd2128[_0xbd97('0x2f')],'type':_0xfd2128[_0xbd97('0x30')][_0xbd97('0x31')]};});_0x427d94[_0xbd97('0x32')]=_[_0xbd97('0x2d')](_0x391730,_0xbd97('0x2a'));_0x427d94['query']=_['keys'](_0x37de42[_0xbd97('0x33')]);_0x427d94[_0xbd97('0x34')]=_[_0xbd97('0x35')](_0x427d94[_0xbd97('0x32')],_0x427d94['query']);_0x4d9676['attributes']=_[_0xbd97('0x35')](_0x427d94[_0xbd97('0x32')],qs[_0xbd97('0x36')](_0x37de42['query'][_0xbd97('0x36')]));_0x4d9676[_0xbd97('0x37')]=_0x4d9676[_0xbd97('0x37')][_0xbd97('0x38')]?_0x4d9676['attributes']:_0x427d94['model'];if(!_0x37de42[_0xbd97('0x33')][_0xbd97('0x39')](_0xbd97('0x3a'))){_0x4d9676[_0xbd97('0x1e')]=qs[_0xbd97('0x1e')](_0x37de42[_0xbd97('0x33')][_0xbd97('0x1e')]);_0x4d9676[_0xbd97('0x1d')]=qs[_0xbd97('0x1d')](_0x37de42[_0xbd97('0x33')][_0xbd97('0x1d')]);}_0x4d9676['order']=qs[_0xbd97('0x3b')](_0x37de42['query'][_0xbd97('0x3b')]);_0x4d9676[_0xbd97('0x3c')]=qs['filters'](_[_0xbd97('0x3d')](_0x37de42[_0xbd97('0x33')],_0x427d94[_0xbd97('0x34')]),_0x391730);if(_0x37de42[_0xbd97('0x33')][_0xbd97('0x3e')]){_0x4d9676[_0xbd97('0x3c')]=_['merge'](_0x4d9676['where'],{'$or':_[_0xbd97('0x2d')](_0x391730,function(_0x5b49f9){if(_0x5b49f9['type']!=='VIRTUAL'){var _0x3f94c9={};_0x3f94c9[_0x5b49f9[_0xbd97('0x2a')]]={'$like':'%'+_0x37de42['query'][_0xbd97('0x3e')]+'%'};return _0x3f94c9;}})});}_0x4d9676=_[_0xbd97('0x3f')]({},_0x4d9676,_0x37de42[_0xbd97('0x40')]);var _0xc76121={'where':_0x4d9676[_0xbd97('0x3c')]};return db[_0xbd97('0x2e')][_0xbd97('0x20')](_0xc76121)[_0xbd97('0x41')](function(_0x287824){_0x4f8534[_0xbd97('0x20')]=_0x287824;if(_0x37de42[_0xbd97('0x33')][_0xbd97('0x42')]){_0x4d9676['include']=[{'all':!![]}];}return db[_0xbd97('0x2e')]['findAll'](_0x4d9676);})['then'](function(_0x3f0ba5){_0x4f8534[_0xbd97('0x43')]=_0x3f0ba5;return _0x4f8534;})[_0xbd97('0x41')](respondWithFilteredResult(_0x16c6d0,_0x4d9676))['catch'](handleError(_0x16c6d0,null));};exports['show']=function(_0x49a091,_0x496012){var _0x500dd8={'raw':![],'where':{'id':_0x49a091['params']['id']}},_0x2b29e2={};_0x2b29e2[_0xbd97('0x32')]=_[_0xbd97('0x44')](db['FreshdeskConfiguration'][_0xbd97('0x45')]);_0x2b29e2[_0xbd97('0x33')]=_[_0xbd97('0x44')](_0x49a091[_0xbd97('0x33')]);_0x2b29e2[_0xbd97('0x34')]=_[_0xbd97('0x35')](_0x2b29e2['model'],_0x2b29e2[_0xbd97('0x33')]);_0x500dd8[_0xbd97('0x37')]=_['intersection'](_0x2b29e2[_0xbd97('0x32')],qs[_0xbd97('0x36')](_0x49a091['query']['fields']));_0x500dd8['attributes']=_0x500dd8[_0xbd97('0x37')][_0xbd97('0x38')]?_0x500dd8['attributes']:_0x2b29e2[_0xbd97('0x32')];if(_0x49a091[_0xbd97('0x33')][_0xbd97('0x42')]){_0x500dd8[_0xbd97('0x46')]=[{'all':!![]}];}_0x500dd8=_['merge']({},_0x500dd8,_0x49a091[_0xbd97('0x40')]);return db[_0xbd97('0x2e')]['find'](_0x500dd8)[_0xbd97('0x41')](handleEntityNotFound(_0x496012,null))[_0xbd97('0x41')](respondWithResult(_0x496012,null))[_0xbd97('0x47')](handleError(_0x496012,null));};exports[_0xbd97('0x48')]=function(_0x126ead,_0x1c5cc2){return db[_0xbd97('0x2e')][_0xbd97('0x48')](_0x126ead['body'],{})[_0xbd97('0x41')](respondWithResult(_0x1c5cc2,0xc9))['catch'](handleError(_0x1c5cc2,null));};exports['update']=function(_0x58192b,_0x22dcdc){if(_0x58192b[_0xbd97('0x49')]['id']){delete _0x58192b['body']['id'];}return db['FreshdeskConfiguration'][_0xbd97('0x4a')]({'where':{'id':_0x58192b[_0xbd97('0x4b')]['id']}})['then'](handleEntityNotFound(_0x22dcdc,null))[_0xbd97('0x41')](saveUpdates(_0x58192b['body'],null))[_0xbd97('0x41')](respondWithResult(_0x22dcdc,null))['catch'](handleError(_0x22dcdc,null));};exports[_0xbd97('0x27')]=function(_0xe7ed29,_0x57b170){return db[_0xbd97('0x2e')][_0xbd97('0x4a')]({'where':{'id':_0xe7ed29[_0xbd97('0x4b')]['id']}})[_0xbd97('0x41')](handleEntityNotFound(_0x57b170,null))['then'](removeEntity(_0x57b170,null))[_0xbd97('0x47')](handleError(_0x57b170,null));};exports[_0xbd97('0x4c')]=function(_0x40dea1,_0x58313a,_0x20961b){var _0x4996f4={};var _0x550672={};var _0x3e4a02;var _0x3c9ec8;return db[_0xbd97('0x2e')][_0xbd97('0x4d')]({'where':{'id':_0x40dea1[_0xbd97('0x4b')]['id']}})['then'](handleEntityNotFound(_0x58313a,null))[_0xbd97('0x41')](function(_0x42caa2){if(_0x42caa2){_0x3e4a02=_0x42caa2;_0x550672[_0xbd97('0x32')]=_[_0xbd97('0x44')](db['FreshdeskField'][_0xbd97('0x45')]);_0x550672[_0xbd97('0x33')]=_[_0xbd97('0x44')](_0x40dea1[_0xbd97('0x33')]);_0x550672[_0xbd97('0x34')]=_['intersection'](_0x550672[_0xbd97('0x32')],_0x550672['query']);_0x4996f4[_0xbd97('0x37')]=_[_0xbd97('0x35')](_0x550672['model'],qs[_0xbd97('0x36')](_0x40dea1['query'][_0xbd97('0x36')]));_0x4996f4[_0xbd97('0x37')]=_0x4996f4[_0xbd97('0x37')][_0xbd97('0x38')]?_0x4996f4[_0xbd97('0x37')]:_0x550672[_0xbd97('0x32')];_0x4996f4[_0xbd97('0x4e')]=qs[_0xbd97('0x3b')](_0x40dea1['query'][_0xbd97('0x3b')]);_0x4996f4['where']=qs[_0xbd97('0x34')](_[_0xbd97('0x3d')](_0x40dea1[_0xbd97('0x33')],_0x550672['filters']));if(_0x40dea1[_0xbd97('0x33')][_0xbd97('0x3e')]){_0x4996f4[_0xbd97('0x3c')]=_[_0xbd97('0x3f')](_0x4996f4[_0xbd97('0x3c')],{'$or':_[_0xbd97('0x2d')](_0x4996f4[_0xbd97('0x37')],function(_0x4cf671){var _0x425f91={};_0x425f91[_0x4cf671]={'$like':'%'+_0x40dea1[_0xbd97('0x33')][_0xbd97('0x3e')]+'%'};return _0x425f91;})});}_0x4996f4=_[_0xbd97('0x3f')]({},_0x4996f4,_0x40dea1[_0xbd97('0x40')]);return _0x3e4a02[_0xbd97('0x4c')](_0x4996f4);}})[_0xbd97('0x41')](function(_0x5762c5){if(_0x5762c5){_0x3c9ec8=_0x5762c5['length'];if(!_0x40dea1['query'][_0xbd97('0x39')](_0xbd97('0x3a'))){_0x4996f4[_0xbd97('0x1e')]=qs[_0xbd97('0x1e')](_0x40dea1[_0xbd97('0x33')][_0xbd97('0x1e')]);_0x4996f4[_0xbd97('0x1d')]=qs[_0xbd97('0x1d')](_0x40dea1[_0xbd97('0x33')][_0xbd97('0x1d')]);}return _0x3e4a02[_0xbd97('0x4c')](_0x4996f4);}})[_0xbd97('0x41')](function(_0x357221){if(_0x357221){return _0x357221?{'count':_0x3c9ec8,'rows':_0x357221}:null;}})[_0xbd97('0x41')](respondWithResult(_0x58313a,null))[_0xbd97('0x47')](handleError(_0x58313a,null));};exports[_0xbd97('0x4f')]=function(_0x2f54eb,_0x1cd26a,_0x2f898a){var _0x5906f6={};var _0x176de0={};var _0xdebc90;var _0xa0c13b;return db['FreshdeskConfiguration'][_0xbd97('0x4d')]({'where':{'id':_0x2f54eb[_0xbd97('0x4b')]['id']}})['then'](handleEntityNotFound(_0x1cd26a,null))[_0xbd97('0x41')](function(_0x270c84){if(_0x270c84){_0xdebc90=_0x270c84;_0x176de0[_0xbd97('0x32')]=_[_0xbd97('0x44')](db[_0xbd97('0x50')][_0xbd97('0x45')]);_0x176de0[_0xbd97('0x33')]=_[_0xbd97('0x44')](_0x2f54eb['query']);_0x176de0[_0xbd97('0x34')]=_['intersection'](_0x176de0['model'],_0x176de0['query']);_0x5906f6[_0xbd97('0x37')]=_[_0xbd97('0x35')](_0x176de0[_0xbd97('0x32')],qs[_0xbd97('0x36')](_0x2f54eb[_0xbd97('0x33')][_0xbd97('0x36')]));_0x5906f6[_0xbd97('0x37')]=_0x5906f6[_0xbd97('0x37')][_0xbd97('0x38')]?_0x5906f6[_0xbd97('0x37')]:_0x176de0[_0xbd97('0x32')];_0x5906f6['order']=qs[_0xbd97('0x3b')](_0x2f54eb[_0xbd97('0x33')][_0xbd97('0x3b')]);_0x5906f6[_0xbd97('0x3c')]=qs[_0xbd97('0x34')](_[_0xbd97('0x3d')](_0x2f54eb['query'],_0x176de0[_0xbd97('0x34')]));if(_0x2f54eb[_0xbd97('0x33')][_0xbd97('0x3e')]){_0x5906f6['where']=_['merge'](_0x5906f6[_0xbd97('0x3c')],{'$or':_['map'](_0x5906f6['attributes'],function(_0x16ab9e){var _0x196606={};_0x196606[_0x16ab9e]={'$like':'%'+_0x2f54eb[_0xbd97('0x33')][_0xbd97('0x3e')]+'%'};return _0x196606;})});}_0x5906f6=_[_0xbd97('0x3f')]({},_0x5906f6,_0x2f54eb['options']);return _0xdebc90['getSubjects'](_0x5906f6);}})[_0xbd97('0x41')](function(_0xca99c7){if(_0xca99c7){_0xa0c13b=_0xca99c7[_0xbd97('0x38')];if(!_0x2f54eb['query'][_0xbd97('0x39')]('nolimit')){_0x5906f6['limit']=qs[_0xbd97('0x1e')](_0x2f54eb[_0xbd97('0x33')][_0xbd97('0x1e')]);_0x5906f6['offset']=qs[_0xbd97('0x1d')](_0x2f54eb[_0xbd97('0x33')][_0xbd97('0x1d')]);}return _0xdebc90['getSubjects'](_0x5906f6);}})[_0xbd97('0x41')](function(_0x5aff27){if(_0x5aff27){return _0x5aff27?{'count':_0xa0c13b,'rows':_0x5aff27}:null;}})[_0xbd97('0x41')](respondWithResult(_0x1cd26a,null))['catch'](handleError(_0x1cd26a,null));};exports[_0xbd97('0x51')]=function(_0x38b21f,_0x127ffc,_0x1f0cea){var _0x57c629={};var _0x275de5={};var _0x3c5b43;var _0x37df70;return db[_0xbd97('0x2e')][_0xbd97('0x4d')]({'where':{'id':_0x38b21f[_0xbd97('0x4b')]['id']}})[_0xbd97('0x41')](handleEntityNotFound(_0x127ffc,null))[_0xbd97('0x41')](function(_0x31ce0d){if(_0x31ce0d){_0x3c5b43=_0x31ce0d;_0x275de5['model']=_[_0xbd97('0x44')](db[_0xbd97('0x50')][_0xbd97('0x45')]);_0x275de5['query']=_['keys'](_0x38b21f['query']);_0x275de5[_0xbd97('0x34')]=_[_0xbd97('0x35')](_0x275de5['model'],_0x275de5[_0xbd97('0x33')]);_0x57c629['attributes']=_[_0xbd97('0x35')](_0x275de5[_0xbd97('0x32')],qs[_0xbd97('0x36')](_0x38b21f[_0xbd97('0x33')][_0xbd97('0x36')]));_0x57c629[_0xbd97('0x37')]=_0x57c629[_0xbd97('0x37')][_0xbd97('0x38')]?_0x57c629[_0xbd97('0x37')]:_0x275de5[_0xbd97('0x32')];_0x57c629[_0xbd97('0x4e')]=qs[_0xbd97('0x3b')](_0x38b21f[_0xbd97('0x33')]['sort']);_0x57c629['where']=qs[_0xbd97('0x34')](_['pick'](_0x38b21f['query'],_0x275de5[_0xbd97('0x34')]));if(_0x38b21f[_0xbd97('0x33')][_0xbd97('0x3e')]){_0x57c629[_0xbd97('0x3c')]=_['merge'](_0x57c629[_0xbd97('0x3c')],{'$or':_['map'](_0x57c629[_0xbd97('0x37')],function(_0x4e2b95){var _0x7fade0={};_0x7fade0[_0x4e2b95]={'$like':'%'+_0x38b21f[_0xbd97('0x33')][_0xbd97('0x3e')]+'%'};return _0x7fade0;})});}_0x57c629=_[_0xbd97('0x3f')]({},_0x57c629,_0x38b21f[_0xbd97('0x40')]);return _0x3c5b43['getDescriptions'](_0x57c629);}})['then'](function(_0x70c7a5){if(_0x70c7a5){_0x37df70=_0x70c7a5['length'];if(!_0x38b21f[_0xbd97('0x33')][_0xbd97('0x39')](_0xbd97('0x3a'))){_0x57c629[_0xbd97('0x1e')]=qs[_0xbd97('0x1e')](_0x38b21f[_0xbd97('0x33')][_0xbd97('0x1e')]);_0x57c629['offset']=qs[_0xbd97('0x1d')](_0x38b21f[_0xbd97('0x33')][_0xbd97('0x1d')]);}return _0x3c5b43[_0xbd97('0x51')](_0x57c629);}})['then'](function(_0x289012){if(_0x289012){return _0x289012?{'count':_0x37df70,'rows':_0x289012}:null;}})[_0xbd97('0x41')](respondWithResult(_0x127ffc,null))[_0xbd97('0x47')](handleError(_0x127ffc,null));};exports[_0xbd97('0x52')]=function(_0x1d63ea,_0x2ff362,_0x22c1ee){var _0x2d189a={};var _0x4a41e8={};var _0x204e6d;var _0x216cc7;return db[_0xbd97('0x2e')][_0xbd97('0x4d')]({'where':{'id':_0x1d63ea[_0xbd97('0x4b')]['id']}})[_0xbd97('0x41')](handleEntityNotFound(_0x2ff362,null))[_0xbd97('0x41')](function(_0x12f803){if(_0x12f803){_0x204e6d=_0x12f803;_0x4a41e8[_0xbd97('0x32')]=_['keys'](db[_0xbd97('0x53')]['rawAttributes']);_0x4a41e8[_0xbd97('0x33')]=_[_0xbd97('0x44')](_0x1d63ea[_0xbd97('0x33')]);_0x4a41e8[_0xbd97('0x34')]=_[_0xbd97('0x35')](_0x4a41e8[_0xbd97('0x32')],_0x4a41e8['query']);_0x2d189a[_0xbd97('0x37')]=_[_0xbd97('0x35')](_0x4a41e8[_0xbd97('0x32')],qs[_0xbd97('0x36')](_0x1d63ea[_0xbd97('0x33')][_0xbd97('0x36')]));_0x2d189a[_0xbd97('0x37')]=_0x2d189a[_0xbd97('0x37')][_0xbd97('0x38')]?_0x2d189a[_0xbd97('0x37')]:_0x4a41e8[_0xbd97('0x32')];_0x2d189a[_0xbd97('0x4e')]=qs[_0xbd97('0x3b')](_0x1d63ea[_0xbd97('0x33')]['sort']);_0x2d189a['where']=qs[_0xbd97('0x34')](_[_0xbd97('0x3d')](_0x1d63ea[_0xbd97('0x33')],_0x4a41e8[_0xbd97('0x34')]));if(_0x1d63ea[_0xbd97('0x33')][_0xbd97('0x3e')]){_0x2d189a['where']=_[_0xbd97('0x3f')](_0x2d189a['where'],{'$or':_[_0xbd97('0x2d')](_0x2d189a[_0xbd97('0x37')],function(_0x53485c){var _0x154cc4={};_0x154cc4[_0x53485c]={'$like':'%'+_0x1d63ea['query']['filter']+'%'};return _0x154cc4;})});}_0x2d189a=_[_0xbd97('0x3f')]({},_0x2d189a,_0x1d63ea[_0xbd97('0x40')]);return _0x204e6d['getTags'](_0x2d189a);}})[_0xbd97('0x41')](function(_0x844f6c){if(_0x844f6c){_0x216cc7=_0x844f6c[_0xbd97('0x38')];if(!_0x1d63ea[_0xbd97('0x33')]['hasOwnProperty']('nolimit')){_0x2d189a[_0xbd97('0x1e')]=qs['limit'](_0x1d63ea[_0xbd97('0x33')][_0xbd97('0x1e')]);_0x2d189a[_0xbd97('0x1d')]=qs[_0xbd97('0x1d')](_0x1d63ea['query'][_0xbd97('0x1d')]);}return _0x204e6d['getTags'](_0x2d189a);}})[_0xbd97('0x41')](function(_0xa9e983){if(_0xa9e983){return _0xa9e983?{'count':_0x216cc7,'rows':_0xa9e983}:null;}})[_0xbd97('0x41')](respondWithResult(_0x2ff362,null))[_0xbd97('0x47')](handleError(_0x2ff362,null));};exports[_0xbd97('0x54')]=function(_0x437c89,_0x2cea8a,_0x39135c){if(_0x437c89[_0xbd97('0x49')]['id']){delete _0x437c89[_0xbd97('0x49')]['id'];}return db[_0xbd97('0x2e')][_0xbd97('0x4d')]({'where':{'id':_0x437c89[_0xbd97('0x4b')]['id']}})['then'](handleEntityNotFound(_0x2cea8a,null))[_0xbd97('0x41')](function(_0x16aacb){if(_0x16aacb){return _0x16aacb[_0xbd97('0x54')](_0x437c89['body'][_0xbd97('0x55')]||[]);}return null;})[_0xbd97('0x41')](respondWithResult(_0x2cea8a,null))['catch'](handleError(_0x2cea8a,null));};