Built motion from commit 43538d75.|2.5.35
[motion2.git] / server / api / openchannelApplication / openchannelApplication.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 _0xdbfa=['model','query','keys','intersection','attributes','fields','hasOwnProperty','order','sort','filters','pick','filter','where','type','VIRTUAL','merge','options','includeAll','include','OpenchannelApplication','findAll','rows','then','catch','show','params','length','find','create','body','destroy','eml-format','rimraf','request-promise','moment','mustache','util','path','to-csv','fs-extra','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','status','end','json','offset','limit','undefined','count','set','Content-Range','reject','save','update','sendStatus','error','stack','name','send','index','map','fieldName','key'];(function(_0x5e9fad,_0x50d184){var _0x8f10f1=function(_0x226b4e){while(--_0x226b4e){_0x5e9fad['push'](_0x5e9fad['shift']());}};_0x8f10f1(++_0x50d184);}(_0xdbfa,0xb1));var _0xadbf=function(_0x600de5,_0x346a53){_0x600de5=_0x600de5-0x0;var _0x20af76=_0xdbfa[_0x600de5];return _0x20af76;};'use strict';var emlformat=require(_0xadbf('0x0'));var rimraf=require(_0xadbf('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xadbf('0x2'));var moment=require(_0xadbf('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xadbf('0x4'));var util=require(_0xadbf('0x5'));var path=require(_0xadbf('0x6'));var sox=require('sox');var csv=require(_0xadbf('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xadbf('0x8'));var _=require('lodash');var squel=require(_0xadbf('0x9'));var crypto=require(_0xadbf('0xa'));var jsforce=require('jsforce');var deskjs=require(_0xadbf('0xb'));var toCsv=require(_0xadbf('0x7'));var querystring=require(_0xadbf('0xc'));var Papa=require(_0xadbf('0xd'));var Redis=require(_0xadbf('0xe'));var authService=require(_0xadbf('0xf'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xadbf('0x10'));var logger=require(_0xadbf('0x11'))('api');var utils=require(_0xadbf('0x12'));var config=require('../../config/environment');var licenseUtil=require(_0xadbf('0x13'));var db=require(_0xadbf('0x14'))['db'];function respondWithStatusCode(_0x591db5,_0x1ec502){_0x1ec502=_0x1ec502||0xcc;return function(_0x2065a3){if(_0x2065a3){return _0x591db5['sendStatus'](_0x1ec502);}return _0x591db5[_0xadbf('0x15')](_0x1ec502)[_0xadbf('0x16')]();};}function respondWithResult(_0x2f11a0,_0x11933f){_0x11933f=_0x11933f||0xc8;return function(_0xe29827){if(_0xe29827){return _0x2f11a0['status'](_0x11933f)[_0xadbf('0x17')](_0xe29827);}};}function respondWithFilteredResult(_0x562071,_0x381749){return function(_0x45ce29){if(_0x45ce29){var _0x1087d7=typeof _0x381749[_0xadbf('0x18')]==='undefined'&&typeof _0x381749[_0xadbf('0x19')]===_0xadbf('0x1a');var _0x5e2b5c=_0x45ce29[_0xadbf('0x1b')];var _0x54b94a=_0x1087d7?0x0:_0x381749[_0xadbf('0x18')];var _0x1cb783=_0x1087d7?_0x45ce29[_0xadbf('0x1b')]:_0x381749[_0xadbf('0x18')]+_0x381749[_0xadbf('0x19')];var _0x3a4546;if(_0x1cb783>=_0x5e2b5c){_0x1cb783=_0x5e2b5c;_0x3a4546=0xc8;}else{_0x3a4546=0xce;}_0x562071[_0xadbf('0x15')](_0x3a4546);return _0x562071[_0xadbf('0x1c')](_0xadbf('0x1d'),_0x54b94a+'-'+_0x1cb783+'/'+_0x5e2b5c)['json'](_0x45ce29);}return null;};}function patchUpdates(_0x586213){return function(_0x4245db){try{jsonpatch['apply'](_0x4245db,_0x586213,!![]);}catch(_0x461a47){return BPromise[_0xadbf('0x1e')](_0x461a47);}return _0x4245db[_0xadbf('0x1f')]();};}function saveUpdates(_0x195056,_0xb639e9){return function(_0x3aa4c0){if(_0x3aa4c0){return _0x3aa4c0[_0xadbf('0x20')](_0x195056)['then'](function(_0x44165e){return _0x44165e;});}return null;};}function removeEntity(_0x1051fb,_0x303d92){return function(_0x455921){if(_0x455921){return _0x455921['destroy']()['then'](function(){_0x1051fb[_0xadbf('0x15')](0xcc)[_0xadbf('0x16')]();});}};}function handleEntityNotFound(_0x57dd07,_0x4e2274){return function(_0xbf9ddb){if(!_0xbf9ddb){_0x57dd07[_0xadbf('0x21')](0x194);}return _0xbf9ddb;};}function handleError(_0x3756b4,_0x30d8ca){_0x30d8ca=_0x30d8ca||0x1f4;return function(_0x580f23){logger[_0xadbf('0x22')](_0x580f23[_0xadbf('0x23')]);if(_0x580f23[_0xadbf('0x24')]){delete _0x580f23[_0xadbf('0x24')];}_0x3756b4[_0xadbf('0x15')](_0x30d8ca)[_0xadbf('0x25')](_0x580f23);};}exports[_0xadbf('0x26')]=function(_0x37958a,_0x5362f2){var _0x555e3d={},_0x35dbe9={},_0x16cb97={'count':0x0,'rows':[]};var _0x509290=_[_0xadbf('0x27')](db['OpenchannelApplication']['rawAttributes'],function(_0xa87d6c){return{'name':_0xa87d6c[_0xadbf('0x28')],'type':_0xa87d6c['type'][_0xadbf('0x29')]};});_0x35dbe9[_0xadbf('0x2a')]=_[_0xadbf('0x27')](_0x509290,'name');_0x35dbe9[_0xadbf('0x2b')]=_[_0xadbf('0x2c')](_0x37958a[_0xadbf('0x2b')]);_0x35dbe9['filters']=_[_0xadbf('0x2d')](_0x35dbe9['model'],_0x35dbe9['query']);_0x555e3d[_0xadbf('0x2e')]=_['intersection'](_0x35dbe9[_0xadbf('0x2a')],qs[_0xadbf('0x2f')](_0x37958a['query'][_0xadbf('0x2f')]));_0x555e3d[_0xadbf('0x2e')]=_0x555e3d[_0xadbf('0x2e')]['length']?_0x555e3d[_0xadbf('0x2e')]:_0x35dbe9['model'];if(!_0x37958a[_0xadbf('0x2b')][_0xadbf('0x30')]('nolimit')){_0x555e3d[_0xadbf('0x19')]=qs[_0xadbf('0x19')](_0x37958a[_0xadbf('0x2b')][_0xadbf('0x19')]);_0x555e3d[_0xadbf('0x18')]=qs['offset'](_0x37958a['query'][_0xadbf('0x18')]);}_0x555e3d[_0xadbf('0x31')]=qs[_0xadbf('0x32')](_0x37958a[_0xadbf('0x2b')][_0xadbf('0x32')]);_0x555e3d['where']=qs[_0xadbf('0x33')](_[_0xadbf('0x34')](_0x37958a[_0xadbf('0x2b')],_0x35dbe9['filters']),_0x509290);if(_0x37958a[_0xadbf('0x2b')][_0xadbf('0x35')]){_0x555e3d[_0xadbf('0x36')]=_['merge'](_0x555e3d['where'],{'$or':_['map'](_0x509290,function(_0x293ce7){if(_0x293ce7[_0xadbf('0x37')]!==_0xadbf('0x38')){var _0x5f4def={};_0x5f4def[_0x293ce7['name']]={'$like':'%'+_0x37958a['query'][_0xadbf('0x35')]+'%'};return _0x5f4def;}})});}_0x555e3d=_[_0xadbf('0x39')]({},_0x555e3d,_0x37958a[_0xadbf('0x3a')]);var _0x449273={'where':_0x555e3d[_0xadbf('0x36')]};return db['OpenchannelApplication'][_0xadbf('0x1b')](_0x449273)['then'](function(_0x3938df){_0x16cb97[_0xadbf('0x1b')]=_0x3938df;if(_0x37958a['query'][_0xadbf('0x3b')]){_0x555e3d[_0xadbf('0x3c')]=[{'all':!![]}];}return db[_0xadbf('0x3d')][_0xadbf('0x3e')](_0x555e3d);})['then'](function(_0x4d95e1){_0x16cb97[_0xadbf('0x3f')]=_0x4d95e1;return _0x16cb97;})[_0xadbf('0x40')](respondWithFilteredResult(_0x5362f2,_0x555e3d))[_0xadbf('0x41')](handleError(_0x5362f2,null));};exports[_0xadbf('0x42')]=function(_0x320ee3,_0x298c33){var _0x3633da={'raw':!![],'where':{'id':_0x320ee3[_0xadbf('0x43')]['id']}},_0x13152a={};_0x13152a[_0xadbf('0x2a')]=_[_0xadbf('0x2c')](db[_0xadbf('0x3d')]['rawAttributes']);_0x13152a[_0xadbf('0x2b')]=_['keys'](_0x320ee3[_0xadbf('0x2b')]);_0x13152a[_0xadbf('0x33')]=_[_0xadbf('0x2d')](_0x13152a[_0xadbf('0x2a')],_0x13152a[_0xadbf('0x2b')]);_0x3633da['attributes']=_[_0xadbf('0x2d')](_0x13152a[_0xadbf('0x2a')],qs[_0xadbf('0x2f')](_0x320ee3[_0xadbf('0x2b')][_0xadbf('0x2f')]));_0x3633da[_0xadbf('0x2e')]=_0x3633da[_0xadbf('0x2e')][_0xadbf('0x44')]?_0x3633da[_0xadbf('0x2e')]:_0x13152a[_0xadbf('0x2a')];if(_0x320ee3[_0xadbf('0x2b')][_0xadbf('0x3b')]){_0x3633da[_0xadbf('0x3c')]=[{'all':!![]}];}_0x3633da=_['merge']({},_0x3633da,_0x320ee3[_0xadbf('0x3a')]);return db[_0xadbf('0x3d')][_0xadbf('0x45')](_0x3633da)[_0xadbf('0x40')](handleEntityNotFound(_0x298c33,null))[_0xadbf('0x40')](respondWithResult(_0x298c33,null))[_0xadbf('0x41')](handleError(_0x298c33,null));};exports[_0xadbf('0x46')]=function(_0x597c36,_0x59b16f){return db[_0xadbf('0x3d')][_0xadbf('0x46')](_0x597c36[_0xadbf('0x47')],{})[_0xadbf('0x40')](respondWithResult(_0x59b16f,0xc9))[_0xadbf('0x41')](handleError(_0x59b16f,null));};exports['update']=function(_0x11cc84,_0xb4683c){if(_0x11cc84['body']['id']){delete _0x11cc84[_0xadbf('0x47')]['id'];}return db[_0xadbf('0x3d')][_0xadbf('0x45')]({'where':{'id':_0x11cc84['params']['id']}})[_0xadbf('0x40')](handleEntityNotFound(_0xb4683c,null))[_0xadbf('0x40')](saveUpdates(_0x11cc84[_0xadbf('0x47')],null))[_0xadbf('0x40')](respondWithResult(_0xb4683c,null))[_0xadbf('0x41')](handleError(_0xb4683c,null));};exports[_0xadbf('0x48')]=function(_0x56921d,_0x6ee12b){return db[_0xadbf('0x3d')][_0xadbf('0x45')]({'where':{'id':_0x56921d[_0xadbf('0x43')]['id']}})[_0xadbf('0x40')](handleEntityNotFound(_0x6ee12b,null))[_0xadbf('0x40')](removeEntity(_0x6ee12b,null))[_0xadbf('0x41')](handleError(_0x6ee12b,null));};