Built motion from commit (unavailable).|2.5.22
[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 _0x46cf=['error','stack','name','send','Variable','rawAttributes','fieldName','key','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','pick','merge','type','VIRTUAL','filter','where','count','includeAll','rows','catch','show','params','include','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','rimraf','zip-dir','fast-json-patch','mustache','path','sox','to-csv','ejs','lodash','jsforce','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/license/util','../../mysqldb','end','status','offset','limit','set','Content-Range','apply','reject','save','update','destroy','then','get','UserProfileResource'];(function(_0x428e6f,_0x265edf){var _0x4c6fa0=function(_0x17a4d1){while(--_0x17a4d1){_0x428e6f['push'](_0x428e6f['shift']());}};_0x4c6fa0(++_0x265edf);}(_0x46cf,0x14e));var _0xf46c=function(_0x1deb03,_0xd05ad8){_0x1deb03=_0x1deb03-0x0;var _0x189fe7=_0x46cf[_0x1deb03];return _0x189fe7;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0xf46c('0x0'));var zipdir=require(_0xf46c('0x1'));var jsonpatch=require(_0xf46c('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xf46c('0x3'));var util=require('util');var path=require(_0xf46c('0x4'));var sox=require(_0xf46c('0x5'));var csv=require(_0xf46c('0x6'));var ejs=require(_0xf46c('0x7'));var fs=require('fs');var _=require(_0xf46c('0x8'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xf46c('0x9'));var deskjs=require('desk.js');var toCsv=require(_0xf46c('0x6'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xf46c('0xa'));var qs=require(_0xf46c('0xb'));var as=require(_0xf46c('0xc'));var hardwareService=require(_0xf46c('0xd'));var logger=require('../../config/logger')(_0xf46c('0xe'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0xf46c('0xf'));var db=require(_0xf46c('0x10'))['db'];function respondWithStatusCode(_0x173ac4,_0x52cca2){_0x52cca2=_0x52cca2||0xcc;return function(_0x32a1ce){if(_0x32a1ce){return _0x173ac4['sendStatus'](_0x52cca2);}return _0x173ac4['status'](_0x52cca2)[_0xf46c('0x11')]();};}function respondWithResult(_0x237e36,_0x226e43){_0x226e43=_0x226e43||0xc8;return function(_0x19070a){if(_0x19070a){return _0x237e36[_0xf46c('0x12')](_0x226e43)['json'](_0x19070a);}};}function respondWithFilteredResult(_0x4450a5,_0x20b56f){return function(_0xf61863){if(_0xf61863){var _0x1e4ab6=_0xf61863['count'],_0x17f345=_0x20b56f[_0xf46c('0x13')],_0x4d1f6d=_0x20b56f[_0xf46c('0x13')]+_0x20b56f[_0xf46c('0x14')],_0x3da8d7;if(_0x4d1f6d>=_0x1e4ab6){_0x4d1f6d=_0x1e4ab6;_0x3da8d7=0xc8;}else{_0x3da8d7=0xce;}_0x4450a5[_0xf46c('0x12')](_0x3da8d7);return _0x4450a5[_0xf46c('0x15')](_0xf46c('0x16'),_0x17f345+'-'+_0x4d1f6d+'/'+_0x1e4ab6)['json'](_0xf61863);}return null;};}function patchUpdates(_0x4f01f7){return function(_0x5e9faf){try{jsonpatch[_0xf46c('0x17')](_0x5e9faf,_0x4f01f7,!![]);}catch(_0x5bcce6){return BPromise[_0xf46c('0x18')](_0x5bcce6);}return _0x5e9faf[_0xf46c('0x19')]();};}function saveUpdates(_0x4d9a31,_0x112fac){return function(_0x18cfce){if(_0x18cfce){return _0x18cfce[_0xf46c('0x1a')](_0x4d9a31)['then'](function(_0x269573){return _0x269573;});}return null;};}function removeEntity(_0x1e7764,_0x688109){return function(_0x9f71b7){if(_0x9f71b7){return _0x9f71b7[_0xf46c('0x1b')]()[_0xf46c('0x1c')](function(){var _0x32e285=_0x9f71b7[_0xf46c('0x1d')]({'plain':!![]});var _0x26ac3d='Variables';return db[_0xf46c('0x1e')][_0xf46c('0x1b')]({'where':{'type':_0x26ac3d,'resourceId':_0x32e285['id']}})[_0xf46c('0x1c')](function(){return _0x9f71b7;});})[_0xf46c('0x1c')](function(){_0x1e7764['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x365041,_0x5c987d){return function(_0x4d62d0){if(!_0x4d62d0){_0x365041['sendStatus'](0x194);}return _0x4d62d0;};}function handleError(_0xb283b5,_0x152621){_0x152621=_0x152621||0x1f4;return function(_0x1d42d3){logger[_0xf46c('0x1f')](_0x1d42d3[_0xf46c('0x20')]);if(_0x1d42d3[_0xf46c('0x21')]){delete _0x1d42d3[_0xf46c('0x21')];}_0xb283b5[_0xf46c('0x12')](_0x152621)[_0xf46c('0x22')](_0x1d42d3);};}exports['index']=function(_0x57421b,_0x3b4852){var _0x388628={},_0x3e6e22={},_0xedccda={'count':0x0,'rows':[]};var _0x559b81=_['map'](db[_0xf46c('0x23')][_0xf46c('0x24')],function(_0x32a13a){return{'name':_0x32a13a[_0xf46c('0x25')],'type':_0x32a13a['type'][_0xf46c('0x26')]};});_0x3e6e22[_0xf46c('0x27')]=_['map'](_0x559b81,'name');_0x3e6e22['query']=_[_0xf46c('0x28')](_0x57421b[_0xf46c('0x29')]);_0x3e6e22[_0xf46c('0x2a')]=_[_0xf46c('0x2b')](_0x3e6e22[_0xf46c('0x27')],_0x3e6e22[_0xf46c('0x29')]);_0x388628[_0xf46c('0x2c')]=_[_0xf46c('0x2b')](_0x3e6e22['model'],qs[_0xf46c('0x2d')](_0x57421b['query'][_0xf46c('0x2d')]));_0x388628[_0xf46c('0x2c')]=_0x388628['attributes'][_0xf46c('0x2e')]?_0x388628[_0xf46c('0x2c')]:_0x3e6e22[_0xf46c('0x27')];if(!_0x57421b[_0xf46c('0x29')][_0xf46c('0x2f')]('nolimit')){_0x388628[_0xf46c('0x14')]=qs['limit'](_0x57421b['query']['limit']);_0x388628[_0xf46c('0x13')]=qs['offset'](_0x57421b[_0xf46c('0x29')][_0xf46c('0x13')]);}_0x388628[_0xf46c('0x30')]=qs['sort'](_0x57421b['query'][_0xf46c('0x31')]);_0x388628['where']=qs[_0xf46c('0x2a')](_[_0xf46c('0x32')](_0x57421b[_0xf46c('0x29')],_0x3e6e22[_0xf46c('0x2a')]),_0x559b81);if(_0x57421b[_0xf46c('0x29')]['filter']){_0x388628['where']=_[_0xf46c('0x33')](_0x388628['where'],{'$or':_['map'](_0x559b81,function(_0x4478c9){if(_0x4478c9[_0xf46c('0x34')]!==_0xf46c('0x35')){var _0x5c63e9={};_0x5c63e9[_0x4478c9[_0xf46c('0x21')]]={'$like':'%'+_0x57421b[_0xf46c('0x29')][_0xf46c('0x36')]+'%'};return _0x5c63e9;}})});}_0x388628=_[_0xf46c('0x33')]({},_0x388628,_0x57421b['options']);var _0x8e16e1={'where':_0x388628[_0xf46c('0x37')]};return db['Variable'][_0xf46c('0x38')](_0x8e16e1)['then'](function(_0x200f84){_0xedccda['count']=_0x200f84;if(_0x57421b[_0xf46c('0x29')][_0xf46c('0x39')]){_0x388628['include']=[{'all':!![]}];}return db[_0xf46c('0x23')]['findAll'](_0x388628);})['then'](function(_0x3a7bb8){_0xedccda[_0xf46c('0x3a')]=_0x3a7bb8;return _0xedccda;})[_0xf46c('0x1c')](respondWithFilteredResult(_0x3b4852,_0x388628))[_0xf46c('0x3b')](handleError(_0x3b4852,null));};exports[_0xf46c('0x3c')]=function(_0x4f327e,_0x1892a8){var _0x5541d4={'raw':!![],'where':{'id':_0x4f327e[_0xf46c('0x3d')]['id']}},_0x175218={};_0x175218[_0xf46c('0x27')]=_[_0xf46c('0x28')](db[_0xf46c('0x23')][_0xf46c('0x24')]);_0x175218[_0xf46c('0x29')]=_[_0xf46c('0x28')](_0x4f327e[_0xf46c('0x29')]);_0x175218[_0xf46c('0x2a')]=_[_0xf46c('0x2b')](_0x175218['model'],_0x175218[_0xf46c('0x29')]);_0x5541d4[_0xf46c('0x2c')]=_[_0xf46c('0x2b')](_0x175218['model'],qs[_0xf46c('0x2d')](_0x4f327e[_0xf46c('0x29')][_0xf46c('0x2d')]));_0x5541d4[_0xf46c('0x2c')]=_0x5541d4[_0xf46c('0x2c')]['length']?_0x5541d4[_0xf46c('0x2c')]:_0x175218[_0xf46c('0x27')];if(_0x4f327e[_0xf46c('0x29')][_0xf46c('0x39')]){_0x5541d4[_0xf46c('0x3e')]=[{'all':!![]}];}_0x5541d4=_[_0xf46c('0x33')]({},_0x5541d4,_0x4f327e[_0xf46c('0x3f')]);return db[_0xf46c('0x23')][_0xf46c('0x40')](_0x5541d4)[_0xf46c('0x1c')](handleEntityNotFound(_0x1892a8,null))['then'](respondWithResult(_0x1892a8,null))['catch'](handleError(_0x1892a8,null));};exports['create']=function(_0x827687,_0x14233d){return db['Variable'][_0xf46c('0x41')](_0x827687[_0xf46c('0x42')],{})['then'](function(_0x5a9042){var _0x5894e5=_0x827687[_0xf46c('0x43')][_0xf46c('0x1d')]({'plain':!![]});if(!_0x5894e5)throw new Error(_0xf46c('0x44'));if(_0x5894e5[_0xf46c('0x45')]===_0xf46c('0x43')){var _0x158490=_0x5a9042[_0xf46c('0x1d')]({'plain':!![]});var _0x2f3e6e='Variables';return db[_0xf46c('0x46')][_0xf46c('0x40')]({'where':{'name':_0x2f3e6e,'userProfileId':_0x5894e5['userProfileId']},'raw':!![]})['then'](function(_0x4bb5ed){if(_0x4bb5ed&&_0x4bb5ed[_0xf46c('0x47')]===0x0){return db[_0xf46c('0x1e')][_0xf46c('0x41')]({'name':_0x158490[_0xf46c('0x21')],'resourceId':_0x158490['id'],'type':_0x4bb5ed[_0xf46c('0x21')],'sectionId':_0x4bb5ed['id']},{})[_0xf46c('0x1c')](function(){return _0x5a9042;});}else{return _0x5a9042;}})['catch'](function(_0x20ddc5){logger[_0xf46c('0x1f')](_0xf46c('0x48'),_0x20ddc5);throw _0x20ddc5;});}return _0x5a9042;})[_0xf46c('0x1c')](respondWithResult(_0x14233d,0xc9))['catch'](handleError(_0x14233d,null));};exports[_0xf46c('0x1a')]=function(_0x575aa8,_0x1b4210){if(_0x575aa8[_0xf46c('0x42')]['id']){delete _0x575aa8[_0xf46c('0x42')]['id'];}return db[_0xf46c('0x23')]['find']({'where':{'id':_0x575aa8[_0xf46c('0x3d')]['id']}})[_0xf46c('0x1c')](handleEntityNotFound(_0x1b4210,null))[_0xf46c('0x1c')](saveUpdates(_0x575aa8['body'],null))[_0xf46c('0x1c')](respondWithResult(_0x1b4210,null))[_0xf46c('0x3b')](handleError(_0x1b4210,null));};exports[_0xf46c('0x1b')]=function(_0x5d12d3,_0x5c97f6){return db[_0xf46c('0x23')][_0xf46c('0x40')]({'where':{'id':_0x5d12d3['params']['id']}})[_0xf46c('0x1c')](handleEntityNotFound(_0x5c97f6,null))[_0xf46c('0x1c')](removeEntity(_0x5c97f6,null))[_0xf46c('0x3b')](handleError(_0x5c97f6,null));};