Built motion from commit 092f8824.|2.5.49
[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 _0x38fb=['fields','length','hasOwnProperty','nolimit','sort','pick','where','merge','VIRTUAL','filter','options','includeAll','include','findAll','rows','catch','create','body','find','params','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','end','status','json','offset','undefined','limit','count','set','reject','then','destroy','stack','name','map','OpenchannelApplication','rawAttributes','type','key','model','keys','query','filters','intersection','attributes'];(function(_0x5f09c5,_0x2bfca0){var _0x426ad9=function(_0x18fe5f){while(--_0x18fe5f){_0x5f09c5['push'](_0x5f09c5['shift']());}};_0x426ad9(++_0x2bfca0);}(_0x38fb,0xa0));var _0xb38f=function(_0x4de877,_0x340170){_0x4de877=_0x4de877-0x0;var _0xb2cfeb=_0x38fb[_0x4de877];return _0xb2cfeb;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xb38f('0x0'));var zipdir=require(_0xb38f('0x1'));var jsonpatch=require(_0xb38f('0x2'));var rp=require(_0xb38f('0x3'));var moment=require(_0xb38f('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xb38f('0x5'));var util=require(_0xb38f('0x6'));var path=require(_0xb38f('0x7'));var sox=require(_0xb38f('0x8'));var csv=require(_0xb38f('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xb38f('0xa'));var _=require(_0xb38f('0xb'));var squel=require('squel');var crypto=require(_0xb38f('0xc'));var jsforce=require(_0xb38f('0xd'));var deskjs=require(_0xb38f('0xe'));var toCsv=require(_0xb38f('0x9'));var querystring=require(_0xb38f('0xf'));var Papa=require(_0xb38f('0x10'));var Redis=require(_0xb38f('0x11'));var authService=require(_0xb38f('0x12'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xb38f('0x13'));var logger=require(_0xb38f('0x14'))(_0xb38f('0x15'));var utils=require(_0xb38f('0x16'));var config=require(_0xb38f('0x17'));var licenseUtil=require(_0xb38f('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x27e003,_0x3a187d){_0x3a187d=_0x3a187d||0xcc;return function(_0xc5330){if(_0xc5330){return _0x27e003[_0xb38f('0x19')](_0x3a187d);}return _0x27e003['status'](_0x3a187d)[_0xb38f('0x1a')]();};}function respondWithResult(_0x49bfcb,_0x4ca090){_0x4ca090=_0x4ca090||0xc8;return function(_0x2d185e){if(_0x2d185e){return _0x49bfcb[_0xb38f('0x1b')](_0x4ca090)[_0xb38f('0x1c')](_0x2d185e);}};}function respondWithFilteredResult(_0x15e97f,_0x2f25da){return function(_0x176f57){if(_0x176f57){var _0x18d145=typeof _0x2f25da[_0xb38f('0x1d')]===_0xb38f('0x1e')&&typeof _0x2f25da[_0xb38f('0x1f')]===_0xb38f('0x1e');var _0x1aa959=_0x176f57[_0xb38f('0x20')];var _0x104d3c=_0x18d145?0x0:_0x2f25da['offset'];var _0x1524fc=_0x18d145?_0x176f57[_0xb38f('0x20')]:_0x2f25da[_0xb38f('0x1d')]+_0x2f25da[_0xb38f('0x1f')];var _0x513724;if(_0x1524fc>=_0x1aa959){_0x1524fc=_0x1aa959;_0x513724=0xc8;}else{_0x513724=0xce;}_0x15e97f[_0xb38f('0x1b')](_0x513724);return _0x15e97f[_0xb38f('0x21')]('Content-Range',_0x104d3c+'-'+_0x1524fc+'/'+_0x1aa959)['json'](_0x176f57);}return null;};}function patchUpdates(_0x136295){return function(_0x1b72bd){try{jsonpatch['apply'](_0x1b72bd,_0x136295,!![]);}catch(_0x53651e){return BPromise[_0xb38f('0x22')](_0x53651e);}return _0x1b72bd['save']();};}function saveUpdates(_0x2f2ca3,_0x322684){return function(_0x29022d){if(_0x29022d){return _0x29022d['update'](_0x2f2ca3)[_0xb38f('0x23')](function(_0x33f391){return _0x33f391;});}return null;};}function removeEntity(_0x253ba7,_0x554020){return function(_0x49657a){if(_0x49657a){return _0x49657a[_0xb38f('0x24')]()[_0xb38f('0x23')](function(){_0x253ba7[_0xb38f('0x1b')](0xcc)[_0xb38f('0x1a')]();});}};}function handleEntityNotFound(_0xc9da5c,_0x9fbe32){return function(_0xbf0d23){if(!_0xbf0d23){_0xc9da5c['sendStatus'](0x194);}return _0xbf0d23;};}function handleError(_0x2325f2,_0xdd586d){_0xdd586d=_0xdd586d||0x1f4;return function(_0x38a0e1){logger['error'](_0x38a0e1[_0xb38f('0x25')]);if(_0x38a0e1['name']){delete _0x38a0e1[_0xb38f('0x26')];}_0x2325f2[_0xb38f('0x1b')](_0xdd586d)['send'](_0x38a0e1);};}exports['index']=function(_0x387808,_0x2b0923){var _0x564a5f={},_0x451b57={},_0xe15550={'count':0x0,'rows':[]};var _0x37dec8=_[_0xb38f('0x27')](db[_0xb38f('0x28')][_0xb38f('0x29')],function(_0x5d033b){return{'name':_0x5d033b['fieldName'],'type':_0x5d033b[_0xb38f('0x2a')][_0xb38f('0x2b')]};});_0x451b57[_0xb38f('0x2c')]=_[_0xb38f('0x27')](_0x37dec8,'name');_0x451b57['query']=_[_0xb38f('0x2d')](_0x387808[_0xb38f('0x2e')]);_0x451b57[_0xb38f('0x2f')]=_[_0xb38f('0x30')](_0x451b57['model'],_0x451b57[_0xb38f('0x2e')]);_0x564a5f[_0xb38f('0x31')]=_[_0xb38f('0x30')](_0x451b57['model'],qs[_0xb38f('0x32')](_0x387808[_0xb38f('0x2e')]['fields']));_0x564a5f[_0xb38f('0x31')]=_0x564a5f[_0xb38f('0x31')][_0xb38f('0x33')]?_0x564a5f[_0xb38f('0x31')]:_0x451b57[_0xb38f('0x2c')];if(!_0x387808[_0xb38f('0x2e')][_0xb38f('0x34')](_0xb38f('0x35'))){_0x564a5f[_0xb38f('0x1f')]=qs[_0xb38f('0x1f')](_0x387808['query']['limit']);_0x564a5f[_0xb38f('0x1d')]=qs[_0xb38f('0x1d')](_0x387808[_0xb38f('0x2e')][_0xb38f('0x1d')]);}_0x564a5f['order']=qs['sort'](_0x387808['query'][_0xb38f('0x36')]);_0x564a5f['where']=qs[_0xb38f('0x2f')](_[_0xb38f('0x37')](_0x387808[_0xb38f('0x2e')],_0x451b57[_0xb38f('0x2f')]),_0x37dec8);if(_0x387808[_0xb38f('0x2e')]['filter']){_0x564a5f[_0xb38f('0x38')]=_[_0xb38f('0x39')](_0x564a5f[_0xb38f('0x38')],{'$or':_[_0xb38f('0x27')](_0x37dec8,function(_0x6c4f36){if(_0x6c4f36[_0xb38f('0x2a')]!==_0xb38f('0x3a')){var _0x1c3c24={};_0x1c3c24[_0x6c4f36[_0xb38f('0x26')]]={'$like':'%'+_0x387808[_0xb38f('0x2e')][_0xb38f('0x3b')]+'%'};return _0x1c3c24;}})});}_0x564a5f=_[_0xb38f('0x39')]({},_0x564a5f,_0x387808[_0xb38f('0x3c')]);var _0x36be65={'where':_0x564a5f['where']};return db['OpenchannelApplication'][_0xb38f('0x20')](_0x36be65)[_0xb38f('0x23')](function(_0x5b97e6){_0xe15550[_0xb38f('0x20')]=_0x5b97e6;if(_0x387808[_0xb38f('0x2e')][_0xb38f('0x3d')]){_0x564a5f[_0xb38f('0x3e')]=[{'all':!![]}];}return db[_0xb38f('0x28')][_0xb38f('0x3f')](_0x564a5f);})[_0xb38f('0x23')](function(_0x310457){_0xe15550[_0xb38f('0x40')]=_0x310457;return _0xe15550;})[_0xb38f('0x23')](respondWithFilteredResult(_0x2b0923,_0x564a5f))[_0xb38f('0x41')](handleError(_0x2b0923,null));};exports['show']=function(_0x5efc7b,_0x1cbd12){var _0x2070a9={'raw':!![],'where':{'id':_0x5efc7b['params']['id']}},_0x20a643={};_0x20a643['model']=_[_0xb38f('0x2d')](db[_0xb38f('0x28')][_0xb38f('0x29')]);_0x20a643[_0xb38f('0x2e')]=_[_0xb38f('0x2d')](_0x5efc7b[_0xb38f('0x2e')]);_0x20a643['filters']=_['intersection'](_0x20a643[_0xb38f('0x2c')],_0x20a643[_0xb38f('0x2e')]);_0x2070a9[_0xb38f('0x31')]=_[_0xb38f('0x30')](_0x20a643[_0xb38f('0x2c')],qs[_0xb38f('0x32')](_0x5efc7b[_0xb38f('0x2e')][_0xb38f('0x32')]));_0x2070a9[_0xb38f('0x31')]=_0x2070a9['attributes'][_0xb38f('0x33')]?_0x2070a9['attributes']:_0x20a643['model'];if(_0x5efc7b[_0xb38f('0x2e')]['includeAll']){_0x2070a9[_0xb38f('0x3e')]=[{'all':!![]}];}_0x2070a9=_[_0xb38f('0x39')]({},_0x2070a9,_0x5efc7b[_0xb38f('0x3c')]);return db[_0xb38f('0x28')]['find'](_0x2070a9)['then'](handleEntityNotFound(_0x1cbd12,null))[_0xb38f('0x23')](respondWithResult(_0x1cbd12,null))[_0xb38f('0x41')](handleError(_0x1cbd12,null));};exports[_0xb38f('0x42')]=function(_0xd60118,_0x577843){return db[_0xb38f('0x28')][_0xb38f('0x42')](_0xd60118['body'],{})[_0xb38f('0x23')](respondWithResult(_0x577843,0xc9))[_0xb38f('0x41')](handleError(_0x577843,null));};exports['update']=function(_0xb739d4,_0x1f7403){if(_0xb739d4[_0xb38f('0x43')]['id']){delete _0xb739d4['body']['id'];}return db[_0xb38f('0x28')][_0xb38f('0x44')]({'where':{'id':_0xb739d4[_0xb38f('0x45')]['id']}})[_0xb38f('0x23')](handleEntityNotFound(_0x1f7403,null))['then'](saveUpdates(_0xb739d4[_0xb38f('0x43')],null))['then'](respondWithResult(_0x1f7403,null))['catch'](handleError(_0x1f7403,null));};exports[_0xb38f('0x24')]=function(_0xbd81b7,_0x14c794){return db['OpenchannelApplication'][_0xb38f('0x44')]({'where':{'id':_0xbd81b7[_0xb38f('0x45')]['id']}})['then'](handleEntityNotFound(_0x14c794,null))[_0xb38f('0x23')](removeEntity(_0x14c794,null))[_0xb38f('0x41')](handleError(_0x14c794,null));};