Built motion from commit (unavailable).|2.4.4
[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 _0x651a=['squel','crypto','jsforce','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','status','end','json','count','offset','set','Content-Range','apply','reject','update','destroy','then','error','stack','name','index','OpenchannelApplication','rawAttributes','model','keys','query','intersection','attributes','fields','length','nolimit','limit','sort','pick','filter','where','merge','map','type','key','field','includeAll','include','findAll','catch','show','params','filters','find','body','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','to-csv','ejs','lodash'];(function(_0x59d89e,_0x55edf5){var _0x554e93=function(_0x3d40bc){while(--_0x3d40bc){_0x59d89e['push'](_0x59d89e['shift']());}};_0x554e93(++_0x55edf5);}(_0x651a,0x151));var _0xa651=function(_0x252884,_0x117ddf){_0x252884=_0x252884-0x0;var _0x4de0e6=_0x651a[_0x252884];return _0x4de0e6;};'use strict';var pdf=require(_0xa651('0x0'));var emlformat=require(_0xa651('0x1'));var rimraf=require(_0xa651('0x2'));var zipdir=require(_0xa651('0x3'));var jsonpatch=require(_0xa651('0x4'));var rp=require(_0xa651('0x5'));var moment=require(_0xa651('0x6'));var BPromise=require(_0xa651('0x7'));var Mustache=require(_0xa651('0x8'));var util=require(_0xa651('0x9'));var path=require('path');var sox=require('sox');var csv=require(_0xa651('0xa'));var ejs=require(_0xa651('0xb'));var fs=require('fs');var _=require(_0xa651('0xc'));var squel=require(_0xa651('0xd'));var crypto=require(_0xa651('0xe'));var jsforce=require(_0xa651('0xf'));var deskjs=require('desk.js');var toCsv=require(_0xa651('0xa'));var querystring=require('querystring');var Papa=require(_0xa651('0x10'));var Redis=require(_0xa651('0x11'));var authService=require(_0xa651('0x12'));var qs=require('../../components/parsers/qs');var hardwareService=require(_0xa651('0x13'));var logger=require(_0xa651('0x14'))(_0xa651('0x15'));var utils=require(_0xa651('0x16'));var config=require(_0xa651('0x17'));var db=require(_0xa651('0x18'))['db'];function respondWithStatusCode(_0x46c3d7,_0x4af38f){_0x4af38f=_0x4af38f||0xcc;return function(_0x5a1fba){if(_0x5a1fba){return _0x46c3d7['sendStatus'](_0x4af38f);}return _0x46c3d7[_0xa651('0x19')](_0x4af38f)[_0xa651('0x1a')]();};}function respondWithResult(_0x3f8f76,_0x27a8c2){_0x27a8c2=_0x27a8c2||0xc8;return function(_0x561f9e){if(_0x561f9e){return _0x3f8f76[_0xa651('0x19')](_0x27a8c2)[_0xa651('0x1b')](_0x561f9e);}};}function respondWithFilteredResult(_0x25367d,_0x4ea80d){return function(_0x14452c){if(_0x14452c){var _0x2d029c=_0x14452c[_0xa651('0x1c')],_0x33f740=_0x4ea80d[_0xa651('0x1d')],_0x238088=_0x4ea80d[_0xa651('0x1d')]+_0x4ea80d['limit'],_0x1ec659;if(_0x238088>=_0x2d029c){_0x238088=_0x2d029c;_0x1ec659=0xc8;}else{_0x1ec659=0xce;}_0x25367d[_0xa651('0x19')](_0x1ec659);return _0x25367d[_0xa651('0x1e')](_0xa651('0x1f'),_0x33f740+'-'+_0x238088+'/'+_0x2d029c)['json'](_0x14452c);}return null;};}function patchUpdates(_0x472e53){return function(_0x343c53){try{jsonpatch[_0xa651('0x20')](_0x343c53,_0x472e53,!![]);}catch(_0x4b4919){return BPromise[_0xa651('0x21')](_0x4b4919);}return _0x343c53['save']();};}function saveUpdates(_0x1d55bc,_0x53d90d){return function(_0x5dfb85){if(_0x5dfb85){return _0x5dfb85[_0xa651('0x22')](_0x1d55bc)['then'](function(_0xb976e5){return _0xb976e5;});}return null;};}function removeEntity(_0x2bd693,_0x5db7ca){return function(_0x3d8b4c){if(_0x3d8b4c){return _0x3d8b4c[_0xa651('0x23')]()[_0xa651('0x24')](function(){_0x2bd693[_0xa651('0x19')](0xcc)[_0xa651('0x1a')]();});}};}function handleEntityNotFound(_0x273387,_0x40c4d8){return function(_0x32f702){if(!_0x32f702){_0x273387['sendStatus'](0x194);}return _0x32f702;};}function handleError(_0x5bc099,_0x4cb975){_0x4cb975=_0x4cb975||0x1f4;return function(_0x27e4fe){logger[_0xa651('0x25')](_0x27e4fe[_0xa651('0x26')]);if(_0x27e4fe[_0xa651('0x27')]){delete _0x27e4fe['name'];}_0x5bc099[_0xa651('0x19')](_0x4cb975)['send'](_0x27e4fe);};}exports[_0xa651('0x28')]=function(_0x1a0247,_0x314fa7){var _0x2231e0={},_0x1e4ae9={},_0xbe1854={'count':0x0,'rows':[]};var _0x6fd3eb=db[_0xa651('0x29')][_0xa651('0x2a')];_0x1e4ae9[_0xa651('0x2b')]=_[_0xa651('0x2c')](_0x6fd3eb);_0x1e4ae9[_0xa651('0x2d')]=_[_0xa651('0x2c')](_0x1a0247['query']);_0x1e4ae9['filters']=_[_0xa651('0x2e')](_0x1e4ae9[_0xa651('0x2b')],_0x1e4ae9['query']);_0x2231e0[_0xa651('0x2f')]=_[_0xa651('0x2e')](_0x1e4ae9[_0xa651('0x2b')],qs['fields'](_0x1a0247['query'][_0xa651('0x30')]));_0x2231e0['attributes']=_0x2231e0[_0xa651('0x2f')][_0xa651('0x31')]?_0x2231e0[_0xa651('0x2f')]:_0x1e4ae9[_0xa651('0x2b')];if(!_0x1a0247[_0xa651('0x2d')]['hasOwnProperty'](_0xa651('0x32'))){_0x2231e0[_0xa651('0x33')]=qs[_0xa651('0x33')](_0x1a0247['query']['limit']);_0x2231e0[_0xa651('0x1d')]=qs['offset'](_0x1a0247['query']['offset']);}_0x2231e0['order']=qs['sort'](_0x1a0247[_0xa651('0x2d')][_0xa651('0x34')]);_0x2231e0['where']=qs['filters'](_[_0xa651('0x35')](_0x1a0247[_0xa651('0x2d')],_0x1e4ae9['filters']));if(_0x1a0247[_0xa651('0x2d')][_0xa651('0x36')]){_0x2231e0[_0xa651('0x37')]=_[_0xa651('0x38')](_0x2231e0['where'],{'$or':_[_0xa651('0x39')](_0x6fd3eb,function(_0x36f671){if(_0x36f671[_0xa651('0x3a')][_0xa651('0x3b')]!=='VIRTUAL'){var _0x4e1b25={};_0x4e1b25[_0x36f671[_0xa651('0x3c')]]={'$like':'%'+_0x1a0247[_0xa651('0x2d')][_0xa651('0x36')]+'%'};return _0x4e1b25;}})});}_0x2231e0=_[_0xa651('0x38')]({},_0x2231e0,_0x1a0247['options']);var _0x102bf4={'where':_0x2231e0[_0xa651('0x37')]};return db['OpenchannelApplication']['count'](_0x102bf4)[_0xa651('0x24')](function(_0x395d3d){_0xbe1854[_0xa651('0x1c')]=_0x395d3d;if(_0x1a0247[_0xa651('0x2d')][_0xa651('0x3d')]){_0x2231e0[_0xa651('0x3e')]=[{'all':!![]}];}return db[_0xa651('0x29')][_0xa651('0x3f')](_0x2231e0);})['then'](function(_0x1118da){_0xbe1854['rows']=_0x1118da;return _0xbe1854;})['then'](respondWithFilteredResult(_0x314fa7,_0x2231e0))[_0xa651('0x40')](handleError(_0x314fa7,null));};exports[_0xa651('0x41')]=function(_0x1e48bd,_0x41f79f){var _0x4ab1af={'raw':!![],'where':{'id':_0x1e48bd[_0xa651('0x42')]['id']}},_0x25b5ec={};_0x25b5ec['model']=_['keys'](db[_0xa651('0x29')]['rawAttributes']);_0x25b5ec[_0xa651('0x2d')]=_[_0xa651('0x2c')](_0x1e48bd[_0xa651('0x2d')]);_0x25b5ec[_0xa651('0x43')]=_[_0xa651('0x2e')](_0x25b5ec[_0xa651('0x2b')],_0x25b5ec[_0xa651('0x2d')]);_0x4ab1af[_0xa651('0x2f')]=_[_0xa651('0x2e')](_0x25b5ec[_0xa651('0x2b')],qs[_0xa651('0x30')](_0x1e48bd['query']['fields']));_0x4ab1af[_0xa651('0x2f')]=_0x4ab1af[_0xa651('0x2f')][_0xa651('0x31')]?_0x4ab1af['attributes']:_0x25b5ec[_0xa651('0x2b')];if(_0x1e48bd[_0xa651('0x2d')][_0xa651('0x3d')]){_0x4ab1af[_0xa651('0x3e')]=[{'all':!![]}];}_0x4ab1af=_[_0xa651('0x38')]({},_0x4ab1af,_0x1e48bd['options']);return db[_0xa651('0x29')][_0xa651('0x44')](_0x4ab1af)[_0xa651('0x24')](handleEntityNotFound(_0x41f79f,null))[_0xa651('0x24')](respondWithResult(_0x41f79f,null))[_0xa651('0x40')](handleError(_0x41f79f,null));};exports['create']=function(_0x379443,_0x110066){return db[_0xa651('0x29')]['create'](_0x379443[_0xa651('0x45')],{})['then'](respondWithResult(_0x110066,0xc9))['catch'](handleError(_0x110066,null));};exports['update']=function(_0x4ec889,_0x47bc29){if(_0x4ec889['body']['id']){delete _0x4ec889[_0xa651('0x45')]['id'];}return db[_0xa651('0x29')]['find']({'where':{'id':_0x4ec889[_0xa651('0x42')]['id']}})[_0xa651('0x24')](handleEntityNotFound(_0x47bc29,null))[_0xa651('0x24')](saveUpdates(_0x4ec889[_0xa651('0x45')],null))[_0xa651('0x24')](respondWithResult(_0x47bc29,null))[_0xa651('0x40')](handleError(_0x47bc29,null));};exports[_0xa651('0x23')]=function(_0x200712,_0x2ee6ae){return db[_0xa651('0x29')]['find']({'where':{'id':_0x200712[_0xa651('0x42')]['id']}})[_0xa651('0x24')](handleEntityNotFound(_0x2ee6ae,null))[_0xa651('0x24')](removeEntity(_0x2ee6ae,null))['catch'](handleError(_0x2ee6ae,null));};