Built motion from commit (unavailable).|2.5.13
[motion2.git] / server / api / tag / tag.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 _0x16bb=['desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','sendStatus','status','json','offset','limit','set','Content-Range','apply','reject','update','destroy','then','get','Tags','UserProfileResource','end','error','stack','name','send','index','map','Tag','fieldName','query','keys','filters','intersection','model','attributes','fields','hasOwnProperty','nolimit','order','sort','filter','where','merge','type','VIRTUAL','count','includeAll','include','findAll','rows','catch','show','params','length','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','eml-format','rimraf','zip-dir','fast-json-patch','bluebird','mustache','util','path','to-csv','squel','crypto','jsforce'];(function(_0x552bee,_0xcba76b){var _0x20ecee=function(_0x5f28c8){while(--_0x5f28c8){_0x552bee['push'](_0x552bee['shift']());}};_0x20ecee(++_0xcba76b);}(_0x16bb,0x134));var _0xb16b=function(_0x4c9278,_0x324a88){_0x4c9278=_0x4c9278-0x0;var _0x7844a9=_0x16bb[_0x4c9278];return _0x7844a9;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xb16b('0x0'));var rimraf=require(_0xb16b('0x1'));var zipdir=require(_0xb16b('0x2'));var jsonpatch=require(_0xb16b('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xb16b('0x4'));var Mustache=require(_0xb16b('0x5'));var util=require(_0xb16b('0x6'));var path=require(_0xb16b('0x7'));var sox=require('sox');var csv=require(_0xb16b('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0xb16b('0x9'));var crypto=require(_0xb16b('0xa'));var jsforce=require(_0xb16b('0xb'));var deskjs=require(_0xb16b('0xc'));var toCsv=require(_0xb16b('0x8'));var querystring=require('querystring');var Papa=require(_0xb16b('0xd'));var Redis=require(_0xb16b('0xe'));var authService=require(_0xb16b('0xf'));var qs=require(_0xb16b('0x10'));var as=require(_0xb16b('0x11'));var hardwareService=require(_0xb16b('0x12'));var logger=require(_0xb16b('0x13'))(_0xb16b('0x14'));var utils=require('../../config/utils');var config=require(_0xb16b('0x15'));var licenseUtil=require(_0xb16b('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x45964d,_0x29ff3e){_0x29ff3e=_0x29ff3e||0xcc;return function(_0x307dd3){if(_0x307dd3){return _0x45964d[_0xb16b('0x17')](_0x29ff3e);}return _0x45964d[_0xb16b('0x18')](_0x29ff3e)['end']();};}function respondWithResult(_0x22df18,_0xdb1ed6){_0xdb1ed6=_0xdb1ed6||0xc8;return function(_0x239ca8){if(_0x239ca8){return _0x22df18[_0xb16b('0x18')](_0xdb1ed6)[_0xb16b('0x19')](_0x239ca8);}};}function respondWithFilteredResult(_0x20cb66,_0x422882){return function(_0x5aa1a1){if(_0x5aa1a1){var _0x4ce9de=_0x5aa1a1['count'],_0x155232=_0x422882[_0xb16b('0x1a')],_0xc83bca=_0x422882[_0xb16b('0x1a')]+_0x422882[_0xb16b('0x1b')],_0x582584;if(_0xc83bca>=_0x4ce9de){_0xc83bca=_0x4ce9de;_0x582584=0xc8;}else{_0x582584=0xce;}_0x20cb66[_0xb16b('0x18')](_0x582584);return _0x20cb66[_0xb16b('0x1c')](_0xb16b('0x1d'),_0x155232+'-'+_0xc83bca+'/'+_0x4ce9de)[_0xb16b('0x19')](_0x5aa1a1);}return null;};}function patchUpdates(_0x51e6fe){return function(_0x5247f2){try{jsonpatch[_0xb16b('0x1e')](_0x5247f2,_0x51e6fe,!![]);}catch(_0x1e3003){return BPromise[_0xb16b('0x1f')](_0x1e3003);}return _0x5247f2['save']();};}function saveUpdates(_0x3899b5,_0x32319d){return function(_0x1c6d58){if(_0x1c6d58){return _0x1c6d58[_0xb16b('0x20')](_0x3899b5)['then'](function(_0x1dde29){return _0x1dde29;});}return null;};}function removeEntity(_0xd8a805,_0x5006bc){return function(_0x3322c4){if(_0x3322c4){return _0x3322c4[_0xb16b('0x21')]()[_0xb16b('0x22')](function(){var _0x20518d=_0x3322c4[_0xb16b('0x23')]({'plain':!![]});var _0x969b54=_0xb16b('0x24');return db[_0xb16b('0x25')]['destroy']({'where':{'type':_0x969b54,'resourceId':_0x20518d['id']}})[_0xb16b('0x22')](function(){return _0x3322c4;});})[_0xb16b('0x22')](function(){_0xd8a805[_0xb16b('0x18')](0xcc)[_0xb16b('0x26')]();});}};}function handleEntityNotFound(_0x4f68a9,_0x28e923){return function(_0x2160e7){if(!_0x2160e7){_0x4f68a9[_0xb16b('0x17')](0x194);}return _0x2160e7;};}function handleError(_0x9bcb65,_0xdec126){_0xdec126=_0xdec126||0x1f4;return function(_0x5e9aaa){logger[_0xb16b('0x27')](_0x5e9aaa[_0xb16b('0x28')]);if(_0x5e9aaa[_0xb16b('0x29')]){delete _0x5e9aaa[_0xb16b('0x29')];}_0x9bcb65[_0xb16b('0x18')](_0xdec126)[_0xb16b('0x2a')](_0x5e9aaa);};}exports[_0xb16b('0x2b')]=function(_0xc07317,_0x1b985b){var _0x36c037={},_0x5b4530={},_0x205c04={'count':0x0,'rows':[]};var _0x4e049e=_[_0xb16b('0x2c')](db[_0xb16b('0x2d')]['rawAttributes'],function(_0x2f237f){return{'name':_0x2f237f[_0xb16b('0x2e')],'type':_0x2f237f['type']['key']};});_0x5b4530['model']=_[_0xb16b('0x2c')](_0x4e049e,_0xb16b('0x29'));_0x5b4530[_0xb16b('0x2f')]=_[_0xb16b('0x30')](_0xc07317['query']);_0x5b4530[_0xb16b('0x31')]=_[_0xb16b('0x32')](_0x5b4530[_0xb16b('0x33')],_0x5b4530['query']);_0x36c037[_0xb16b('0x34')]=_['intersection'](_0x5b4530[_0xb16b('0x33')],qs['fields'](_0xc07317[_0xb16b('0x2f')][_0xb16b('0x35')]));_0x36c037[_0xb16b('0x34')]=_0x36c037[_0xb16b('0x34')]['length']?_0x36c037[_0xb16b('0x34')]:_0x5b4530[_0xb16b('0x33')];if(!_0xc07317[_0xb16b('0x2f')][_0xb16b('0x36')](_0xb16b('0x37'))){_0x36c037['limit']=qs[_0xb16b('0x1b')](_0xc07317['query']['limit']);_0x36c037[_0xb16b('0x1a')]=qs['offset'](_0xc07317['query']['offset']);}_0x36c037[_0xb16b('0x38')]=qs[_0xb16b('0x39')](_0xc07317[_0xb16b('0x2f')]['sort']);_0x36c037['where']=qs['filters'](_['pick'](_0xc07317[_0xb16b('0x2f')],_0x5b4530[_0xb16b('0x31')]),_0x4e049e);if(_0xc07317['query'][_0xb16b('0x3a')]){_0x36c037[_0xb16b('0x3b')]=_[_0xb16b('0x3c')](_0x36c037[_0xb16b('0x3b')],{'$or':_[_0xb16b('0x2c')](_0x4e049e,function(_0x5c0827){if(_0x5c0827[_0xb16b('0x3d')]!==_0xb16b('0x3e')){var _0x4218a9={};_0x4218a9[_0x5c0827[_0xb16b('0x29')]]={'$like':'%'+_0xc07317['query'][_0xb16b('0x3a')]+'%'};return _0x4218a9;}})});}_0x36c037=_['merge']({},_0x36c037,_0xc07317['options']);var _0x34107d={'where':_0x36c037[_0xb16b('0x3b')]};return db['Tag'][_0xb16b('0x3f')](_0x34107d)[_0xb16b('0x22')](function(_0x2d11c8){_0x205c04['count']=_0x2d11c8;if(_0xc07317['query'][_0xb16b('0x40')]){_0x36c037[_0xb16b('0x41')]=[{'all':!![]}];}return db[_0xb16b('0x2d')][_0xb16b('0x42')](_0x36c037);})[_0xb16b('0x22')](function(_0x1ca08e){_0x205c04[_0xb16b('0x43')]=_0x1ca08e;return _0x205c04;})['then'](respondWithFilteredResult(_0x1b985b,_0x36c037))[_0xb16b('0x44')](handleError(_0x1b985b,null));};exports[_0xb16b('0x45')]=function(_0x2bf8c5,_0x2e542b){var _0x102cc6={'raw':!![],'where':{'id':_0x2bf8c5[_0xb16b('0x46')]['id']}},_0x533198={};_0x533198[_0xb16b('0x33')]=_[_0xb16b('0x30')](db[_0xb16b('0x2d')]['rawAttributes']);_0x533198[_0xb16b('0x2f')]=_[_0xb16b('0x30')](_0x2bf8c5['query']);_0x533198[_0xb16b('0x31')]=_[_0xb16b('0x32')](_0x533198[_0xb16b('0x33')],_0x533198[_0xb16b('0x2f')]);_0x102cc6[_0xb16b('0x34')]=_[_0xb16b('0x32')](_0x533198[_0xb16b('0x33')],qs[_0xb16b('0x35')](_0x2bf8c5[_0xb16b('0x2f')][_0xb16b('0x35')]));_0x102cc6[_0xb16b('0x34')]=_0x102cc6[_0xb16b('0x34')][_0xb16b('0x47')]?_0x102cc6[_0xb16b('0x34')]:_0x533198[_0xb16b('0x33')];if(_0x2bf8c5[_0xb16b('0x2f')][_0xb16b('0x40')]){_0x102cc6[_0xb16b('0x41')]=[{'all':!![]}];}_0x102cc6=_[_0xb16b('0x3c')]({},_0x102cc6,_0x2bf8c5[_0xb16b('0x48')]);return db[_0xb16b('0x2d')][_0xb16b('0x49')](_0x102cc6)[_0xb16b('0x22')](handleEntityNotFound(_0x2e542b,null))[_0xb16b('0x22')](respondWithResult(_0x2e542b,null))[_0xb16b('0x44')](handleError(_0x2e542b,null));};exports[_0xb16b('0x4a')]=function(_0x4cfcd1,_0x596701){return db[_0xb16b('0x2d')][_0xb16b('0x4a')](_0x4cfcd1[_0xb16b('0x4b')],{})[_0xb16b('0x22')](function(_0x443f14){var _0x411ea6=_0x4cfcd1[_0xb16b('0x4c')]['get']({'plain':!![]});if(!_0x411ea6)throw new Error(_0xb16b('0x4d'));if(_0x411ea6[_0xb16b('0x4e')]===_0xb16b('0x4c')){var _0x235ccf=_0x443f14[_0xb16b('0x23')]({'plain':!![]});var _0x18c0d3='Tags';return db['UserProfileSection']['find']({'where':{'name':_0x18c0d3,'userProfileId':_0x411ea6[_0xb16b('0x4f')]},'raw':!![]})['then'](function(_0x28e928){if(_0x28e928&&_0x28e928['autoAssociation']===0x0){return db[_0xb16b('0x25')]['create']({'name':_0x235ccf[_0xb16b('0x29')],'resourceId':_0x235ccf['id'],'type':_0x28e928['name'],'sectionId':_0x28e928['id']},{})[_0xb16b('0x22')](function(){return _0x443f14;});}else{return _0x443f14;}})[_0xb16b('0x44')](function(_0x3e5282){logger[_0xb16b('0x27')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x3e5282);throw _0x3e5282;});}return _0x443f14;})[_0xb16b('0x22')](respondWithResult(_0x596701,0xc9))[_0xb16b('0x44')](handleError(_0x596701,null));};exports[_0xb16b('0x20')]=function(_0x19c019,_0x296a5b){if(_0x19c019[_0xb16b('0x4b')]['id']){delete _0x19c019[_0xb16b('0x4b')]['id'];}return db['Tag']['find']({'where':{'id':_0x19c019['params']['id']}})[_0xb16b('0x22')](handleEntityNotFound(_0x296a5b,null))[_0xb16b('0x22')](saveUpdates(_0x19c019['body'],null))[_0xb16b('0x22')](respondWithResult(_0x296a5b,null))[_0xb16b('0x44')](handleError(_0x296a5b,null));};exports[_0xb16b('0x21')]=function(_0x5e2932,_0x366d1e){return db[_0xb16b('0x2d')]['find']({'where':{'id':_0x5e2932[_0xb16b('0x46')]['id']}})[_0xb16b('0x22')](handleEntityNotFound(_0x366d1e,null))[_0xb16b('0x22')](removeEntity(_0x366d1e,null))[_0xb16b('0x44')](handleError(_0x366d1e,null));};