Built motion from commit (unavailable).|2.5.3
[motion2.git] / server / api / variable / variable.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 _0xf491=['moment','mustache','util','path','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../mysqldb','status','json','count','offset','limit','set','reject','destroy','then','UserProfileResource','end','sendStatus','error','name','send','index','rawAttributes','fieldName','type','key','map','query','filters','model','attributes','intersection','fields','length','hasOwnProperty','order','where','pick','merge','VIRTUAL','filter','options','include','Variable','findAll','show','params','keys','catch','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch'];(function(_0x16c2e0,_0x3dc335){var _0x49b690=function(_0x5bb015){while(--_0x5bb015){_0x16c2e0['push'](_0x16c2e0['shift']());}};_0x49b690(++_0x3dc335);}(_0xf491,0x137));var _0x1f49=function(_0x54458c,_0x51e89c){_0x54458c=_0x54458c-0x0;var _0x282ab6=_0xf491[_0x54458c];return _0x282ab6;};'use strict';var pdf=require(_0x1f49('0x0'));var emlformat=require(_0x1f49('0x1'));var rimraf=require(_0x1f49('0x2'));var zipdir=require(_0x1f49('0x3'));var jsonpatch=require(_0x1f49('0x4'));var rp=require('request-promise');var moment=require(_0x1f49('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x1f49('0x6'));var util=require(_0x1f49('0x7'));var path=require(_0x1f49('0x8'));var sox=require('sox');var csv=require(_0x1f49('0x9'));var ejs=require(_0x1f49('0xa'));var fs=require('fs');var _=require(_0x1f49('0xb'));var squel=require('squel');var crypto=require(_0x1f49('0xc'));var jsforce=require(_0x1f49('0xd'));var deskjs=require(_0x1f49('0xe'));var toCsv=require('to-csv');var querystring=require(_0x1f49('0xf'));var Papa=require(_0x1f49('0x10'));var Redis=require(_0x1f49('0x11'));var authService=require(_0x1f49('0x12'));var qs=require(_0x1f49('0x13'));var as=require(_0x1f49('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x1f49('0x15'));var utils=require(_0x1f49('0x16'));var config=require(_0x1f49('0x17'));var db=require(_0x1f49('0x18'))['db'];function respondWithStatusCode(_0x1ee496,_0xadf78b){_0xadf78b=_0xadf78b||0xcc;return function(_0x2ff701){if(_0x2ff701){return _0x1ee496['sendStatus'](_0xadf78b);}return _0x1ee496[_0x1f49('0x19')](_0xadf78b)['end']();};}function respondWithResult(_0x379e2c,_0xa759f2){_0xa759f2=_0xa759f2||0xc8;return function(_0x5bfcbb){if(_0x5bfcbb){return _0x379e2c[_0x1f49('0x19')](_0xa759f2)[_0x1f49('0x1a')](_0x5bfcbb);}};}function respondWithFilteredResult(_0x182d4a,_0x13ff81){return function(_0x4a5d03){if(_0x4a5d03){var _0x8636ac=_0x4a5d03[_0x1f49('0x1b')],_0x103e91=_0x13ff81[_0x1f49('0x1c')],_0x2ec014=_0x13ff81[_0x1f49('0x1c')]+_0x13ff81[_0x1f49('0x1d')],_0xb8a2ef;if(_0x2ec014>=_0x8636ac){_0x2ec014=_0x8636ac;_0xb8a2ef=0xc8;}else{_0xb8a2ef=0xce;}_0x182d4a[_0x1f49('0x19')](_0xb8a2ef);return _0x182d4a[_0x1f49('0x1e')]('Content-Range',_0x103e91+'-'+_0x2ec014+'/'+_0x8636ac)[_0x1f49('0x1a')](_0x4a5d03);}return null;};}function patchUpdates(_0x3c7852){return function(_0x5adb14){try{jsonpatch['apply'](_0x5adb14,_0x3c7852,!![]);}catch(_0xd4aeb6){return BPromise[_0x1f49('0x1f')](_0xd4aeb6);}return _0x5adb14['save']();};}function saveUpdates(_0x1fe1ed,_0x21b635){return function(_0x22988b){if(_0x22988b){return _0x22988b['update'](_0x1fe1ed)['then'](function(_0xed0021){return _0xed0021;});}return null;};}function removeEntity(_0x9f16cf,_0x19407d){return function(_0x246295){if(_0x246295){return _0x246295[_0x1f49('0x20')]()[_0x1f49('0x21')](function(){var _0x1debe8=_0x246295['get']({'plain':!![]});var _0x4238d9='Variables';return db[_0x1f49('0x22')][_0x1f49('0x20')]({'where':{'type':_0x4238d9,'resourceId':_0x1debe8['id']}})[_0x1f49('0x21')](function(){return _0x246295;});})[_0x1f49('0x21')](function(){_0x9f16cf[_0x1f49('0x19')](0xcc)[_0x1f49('0x23')]();});}};}function handleEntityNotFound(_0x28b76c,_0x1687a4){return function(_0x8448be){if(!_0x8448be){_0x28b76c[_0x1f49('0x24')](0x194);}return _0x8448be;};}function handleError(_0x4f6a61,_0x215897){_0x215897=_0x215897||0x1f4;return function(_0x3ac8a8){logger[_0x1f49('0x25')](_0x3ac8a8['stack']);if(_0x3ac8a8['name']){delete _0x3ac8a8[_0x1f49('0x26')];}_0x4f6a61[_0x1f49('0x19')](_0x215897)[_0x1f49('0x27')](_0x3ac8a8);};}exports[_0x1f49('0x28')]=function(_0x28b201,_0xbfc1dc){var _0x57d2ff={},_0x4f0c1e={},_0x455a62={'count':0x0,'rows':[]};var _0xeb01e9=_['map'](db['Variable'][_0x1f49('0x29')],function(_0x3f88d9){return{'name':_0x3f88d9[_0x1f49('0x2a')],'type':_0x3f88d9[_0x1f49('0x2b')][_0x1f49('0x2c')]};});_0x4f0c1e['model']=_[_0x1f49('0x2d')](_0xeb01e9,'name');_0x4f0c1e[_0x1f49('0x2e')]=_['keys'](_0x28b201[_0x1f49('0x2e')]);_0x4f0c1e[_0x1f49('0x2f')]=_['intersection'](_0x4f0c1e[_0x1f49('0x30')],_0x4f0c1e[_0x1f49('0x2e')]);_0x57d2ff[_0x1f49('0x31')]=_[_0x1f49('0x32')](_0x4f0c1e[_0x1f49('0x30')],qs[_0x1f49('0x33')](_0x28b201[_0x1f49('0x2e')][_0x1f49('0x33')]));_0x57d2ff[_0x1f49('0x31')]=_0x57d2ff[_0x1f49('0x31')][_0x1f49('0x34')]?_0x57d2ff[_0x1f49('0x31')]:_0x4f0c1e['model'];if(!_0x28b201[_0x1f49('0x2e')][_0x1f49('0x35')]('nolimit')){_0x57d2ff['limit']=qs[_0x1f49('0x1d')](_0x28b201[_0x1f49('0x2e')][_0x1f49('0x1d')]);_0x57d2ff[_0x1f49('0x1c')]=qs[_0x1f49('0x1c')](_0x28b201[_0x1f49('0x2e')][_0x1f49('0x1c')]);}_0x57d2ff[_0x1f49('0x36')]=qs['sort'](_0x28b201['query']['sort']);_0x57d2ff[_0x1f49('0x37')]=qs[_0x1f49('0x2f')](_[_0x1f49('0x38')](_0x28b201['query'],_0x4f0c1e[_0x1f49('0x2f')]),_0xeb01e9);if(_0x28b201['query']['filter']){_0x57d2ff[_0x1f49('0x37')]=_[_0x1f49('0x39')](_0x57d2ff[_0x1f49('0x37')],{'$or':_[_0x1f49('0x2d')](_0xeb01e9,function(_0x1503c1){if(_0x1503c1[_0x1f49('0x2b')]!==_0x1f49('0x3a')){var _0x1d03bf={};_0x1d03bf[_0x1503c1['name']]={'$like':'%'+_0x28b201['query'][_0x1f49('0x3b')]+'%'};return _0x1d03bf;}})});}_0x57d2ff=_[_0x1f49('0x39')]({},_0x57d2ff,_0x28b201[_0x1f49('0x3c')]);var _0x186c2a={'where':_0x57d2ff[_0x1f49('0x37')]};return db['Variable'][_0x1f49('0x1b')](_0x186c2a)[_0x1f49('0x21')](function(_0x232ef0){_0x455a62['count']=_0x232ef0;if(_0x28b201[_0x1f49('0x2e')]['includeAll']){_0x57d2ff[_0x1f49('0x3d')]=[{'all':!![]}];}return db[_0x1f49('0x3e')][_0x1f49('0x3f')](_0x57d2ff);})[_0x1f49('0x21')](function(_0x501af7){_0x455a62['rows']=_0x501af7;return _0x455a62;})[_0x1f49('0x21')](respondWithFilteredResult(_0xbfc1dc,_0x57d2ff))['catch'](handleError(_0xbfc1dc,null));};exports[_0x1f49('0x40')]=function(_0x1b2a57,_0x176191){var _0x58997c={'raw':!![],'where':{'id':_0x1b2a57[_0x1f49('0x41')]['id']}},_0x2d4b8e={};_0x2d4b8e[_0x1f49('0x30')]=_['keys'](db[_0x1f49('0x3e')]['rawAttributes']);_0x2d4b8e[_0x1f49('0x2e')]=_[_0x1f49('0x42')](_0x1b2a57[_0x1f49('0x2e')]);_0x2d4b8e[_0x1f49('0x2f')]=_[_0x1f49('0x32')](_0x2d4b8e[_0x1f49('0x30')],_0x2d4b8e[_0x1f49('0x2e')]);_0x58997c[_0x1f49('0x31')]=_[_0x1f49('0x32')](_0x2d4b8e[_0x1f49('0x30')],qs[_0x1f49('0x33')](_0x1b2a57[_0x1f49('0x2e')][_0x1f49('0x33')]));_0x58997c[_0x1f49('0x31')]=_0x58997c[_0x1f49('0x31')][_0x1f49('0x34')]?_0x58997c['attributes']:_0x2d4b8e[_0x1f49('0x30')];if(_0x1b2a57['query']['includeAll']){_0x58997c[_0x1f49('0x3d')]=[{'all':!![]}];}_0x58997c=_['merge']({},_0x58997c,_0x1b2a57[_0x1f49('0x3c')]);return db[_0x1f49('0x3e')]['find'](_0x58997c)[_0x1f49('0x21')](handleEntityNotFound(_0x176191,null))[_0x1f49('0x21')](respondWithResult(_0x176191,null))[_0x1f49('0x43')](handleError(_0x176191,null));};exports[_0x1f49('0x44')]=function(_0x5dafe3,_0x40eb90){return db['Variable'][_0x1f49('0x44')](_0x5dafe3[_0x1f49('0x45')],{})[_0x1f49('0x21')](function(_0x4d905b){var _0x22de55=_0x5dafe3[_0x1f49('0x46')][_0x1f49('0x47')]({'plain':!![]});if(!_0x22de55)throw new Error(_0x1f49('0x48'));if(_0x22de55[_0x1f49('0x49')]===_0x1f49('0x46')){var _0x39fcd8=_0x4d905b[_0x1f49('0x47')]({'plain':!![]});var _0x5add97='Variables';return db[_0x1f49('0x4a')][_0x1f49('0x4b')]({'where':{'name':_0x5add97,'userProfileId':_0x22de55['userProfileId']},'raw':!![]})[_0x1f49('0x21')](function(_0x49a229){if(_0x49a229&&_0x49a229[_0x1f49('0x4c')]===0x0){return db[_0x1f49('0x22')][_0x1f49('0x44')]({'name':_0x39fcd8[_0x1f49('0x26')],'resourceId':_0x39fcd8['id'],'type':_0x49a229['name'],'sectionId':_0x49a229['id']},{})[_0x1f49('0x21')](function(){return _0x4d905b;});}else{return _0x4d905b;}})[_0x1f49('0x43')](function(_0x44813c){logger[_0x1f49('0x25')](_0x1f49('0x4d'),_0x44813c);throw _0x44813c;});}return _0x4d905b;})[_0x1f49('0x21')](respondWithResult(_0x40eb90,0xc9))[_0x1f49('0x43')](handleError(_0x40eb90,null));};exports[_0x1f49('0x4e')]=function(_0x235b9f,_0x1f9cab){if(_0x235b9f[_0x1f49('0x45')]['id']){delete _0x235b9f[_0x1f49('0x45')]['id'];}return db[_0x1f49('0x3e')][_0x1f49('0x4b')]({'where':{'id':_0x235b9f['params']['id']}})['then'](handleEntityNotFound(_0x1f9cab,null))[_0x1f49('0x21')](saveUpdates(_0x235b9f[_0x1f49('0x45')],null))[_0x1f49('0x21')](respondWithResult(_0x1f9cab,null))[_0x1f49('0x43')](handleError(_0x1f9cab,null));};exports[_0x1f49('0x20')]=function(_0xde42f4,_0x39dd8b){return db['Variable'][_0x1f49('0x4b')]({'where':{'id':_0xde42f4[_0x1f49('0x41')]['id']}})[_0x1f49('0x21')](handleEntityNotFound(_0x39dd8b,null))[_0x1f49('0x21')](removeEntity(_0x39dd8b,null))[_0x1f49('0x43')](handleError(_0x39dd8b,null));};