Built motion from commit 85328c08.|2.5.50
[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 _0xf7db=['key','model','query','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','filters','pick','filter','where','VIRTUAL','merge','options','includeAll','include','findAll','rows','catch','params','keys','find','create','body','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','path','to-csv','ejs','crypto','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','undefined','count','set','apply','reject','save','update','then','destroy','stack','name','send','index','map','OpenchannelApplication','rawAttributes','type'];(function(_0x5f309e,_0x66e31){var _0x487b5e=function(_0x44f203){while(--_0x44f203){_0x5f309e['push'](_0x5f309e['shift']());}};_0x487b5e(++_0x66e31);}(_0xf7db,0xa5));var _0xbf7d=function(_0x192850,_0x4171b0){_0x192850=_0x192850-0x0;var _0x5001f7=_0xf7db[_0x192850];return _0x5001f7;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xbf7d('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0xbf7d('0x1'));var rp=require(_0xbf7d('0x2'));var moment=require(_0xbf7d('0x3'));var BPromise=require(_0xbf7d('0x4'));var Mustache=require(_0xbf7d('0x5'));var util=require('util');var path=require(_0xbf7d('0x6'));var sox=require('sox');var csv=require(_0xbf7d('0x7'));var ejs=require(_0xbf7d('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require('squel');var crypto=require(_0xbf7d('0x9'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xbf7d('0x7'));var querystring=require(_0xbf7d('0xa'));var Papa=require('papaparse');var Redis=require(_0xbf7d('0xb'));var authService=require(_0xbf7d('0xc'));var qs=require(_0xbf7d('0xd'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xbf7d('0xe'));var logger=require(_0xbf7d('0xf'))('api');var utils=require(_0xbf7d('0x10'));var config=require('../../config/environment');var licenseUtil=require(_0xbf7d('0x11'));var db=require(_0xbf7d('0x12'))['db'];function respondWithStatusCode(_0x307d54,_0x2b72c1){_0x2b72c1=_0x2b72c1||0xcc;return function(_0x15075f){if(_0x15075f){return _0x307d54[_0xbf7d('0x13')](_0x2b72c1);}return _0x307d54[_0xbf7d('0x14')](_0x2b72c1)[_0xbf7d('0x15')]();};}function respondWithResult(_0x1d63bf,_0x3e40cc){_0x3e40cc=_0x3e40cc||0xc8;return function(_0x1798bb){if(_0x1798bb){return _0x1d63bf[_0xbf7d('0x14')](_0x3e40cc)[_0xbf7d('0x16')](_0x1798bb);}};}function respondWithFilteredResult(_0x312fb5,_0x4f8021){return function(_0x3de921){if(_0x3de921){var _0x4611cb=typeof _0x4f8021[_0xbf7d('0x17')]==='undefined'&&typeof _0x4f8021[_0xbf7d('0x18')]===_0xbf7d('0x19');var _0x402c2e=_0x3de921[_0xbf7d('0x1a')];var _0x45847f=_0x4611cb?0x0:_0x4f8021[_0xbf7d('0x17')];var _0x5e207c=_0x4611cb?_0x3de921[_0xbf7d('0x1a')]:_0x4f8021[_0xbf7d('0x17')]+_0x4f8021[_0xbf7d('0x18')];var _0x54eae3;if(_0x5e207c>=_0x402c2e){_0x5e207c=_0x402c2e;_0x54eae3=0xc8;}else{_0x54eae3=0xce;}_0x312fb5[_0xbf7d('0x14')](_0x54eae3);return _0x312fb5[_0xbf7d('0x1b')]('Content-Range',_0x45847f+'-'+_0x5e207c+'/'+_0x402c2e)[_0xbf7d('0x16')](_0x3de921);}return null;};}function patchUpdates(_0xa8710c){return function(_0x110e34){try{jsonpatch[_0xbf7d('0x1c')](_0x110e34,_0xa8710c,!![]);}catch(_0x266511){return BPromise[_0xbf7d('0x1d')](_0x266511);}return _0x110e34[_0xbf7d('0x1e')]();};}function saveUpdates(_0xdf699f,_0x17add9){return function(_0x47f606){if(_0x47f606){return _0x47f606[_0xbf7d('0x1f')](_0xdf699f)[_0xbf7d('0x20')](function(_0x108fc1){return _0x108fc1;});}return null;};}function removeEntity(_0x44dab2,_0x1b948a){return function(_0x597d24){if(_0x597d24){return _0x597d24[_0xbf7d('0x21')]()[_0xbf7d('0x20')](function(){_0x44dab2[_0xbf7d('0x14')](0xcc)[_0xbf7d('0x15')]();});}};}function handleEntityNotFound(_0x4b47e2,_0x253ba8){return function(_0x38640a){if(!_0x38640a){_0x4b47e2[_0xbf7d('0x13')](0x194);}return _0x38640a;};}function handleError(_0x130c08,_0x5d8842){_0x5d8842=_0x5d8842||0x1f4;return function(_0x28c482){logger['error'](_0x28c482[_0xbf7d('0x22')]);if(_0x28c482[_0xbf7d('0x23')]){delete _0x28c482[_0xbf7d('0x23')];}_0x130c08['status'](_0x5d8842)[_0xbf7d('0x24')](_0x28c482);};}exports[_0xbf7d('0x25')]=function(_0x366c85,_0x3fe5bd){var _0x3057f6={},_0x58ff05={},_0x418ca3={'count':0x0,'rows':[]};var _0x1caed9=_[_0xbf7d('0x26')](db[_0xbf7d('0x27')][_0xbf7d('0x28')],function(_0x4686a6){return{'name':_0x4686a6['fieldName'],'type':_0x4686a6[_0xbf7d('0x29')][_0xbf7d('0x2a')]};});_0x58ff05[_0xbf7d('0x2b')]=_[_0xbf7d('0x26')](_0x1caed9,'name');_0x58ff05[_0xbf7d('0x2c')]=_['keys'](_0x366c85[_0xbf7d('0x2c')]);_0x58ff05['filters']=_[_0xbf7d('0x2d')](_0x58ff05['model'],_0x58ff05[_0xbf7d('0x2c')]);_0x3057f6[_0xbf7d('0x2e')]=_[_0xbf7d('0x2d')](_0x58ff05[_0xbf7d('0x2b')],qs[_0xbf7d('0x2f')](_0x366c85[_0xbf7d('0x2c')][_0xbf7d('0x2f')]));_0x3057f6[_0xbf7d('0x2e')]=_0x3057f6['attributes'][_0xbf7d('0x30')]?_0x3057f6[_0xbf7d('0x2e')]:_0x58ff05['model'];if(!_0x366c85[_0xbf7d('0x2c')][_0xbf7d('0x31')](_0xbf7d('0x32'))){_0x3057f6[_0xbf7d('0x18')]=qs[_0xbf7d('0x18')](_0x366c85[_0xbf7d('0x2c')]['limit']);_0x3057f6['offset']=qs[_0xbf7d('0x17')](_0x366c85[_0xbf7d('0x2c')][_0xbf7d('0x17')]);}_0x3057f6['order']=qs['sort'](_0x366c85[_0xbf7d('0x2c')][_0xbf7d('0x33')]);_0x3057f6['where']=qs[_0xbf7d('0x34')](_[_0xbf7d('0x35')](_0x366c85['query'],_0x58ff05[_0xbf7d('0x34')]),_0x1caed9);if(_0x366c85[_0xbf7d('0x2c')][_0xbf7d('0x36')]){_0x3057f6[_0xbf7d('0x37')]=_['merge'](_0x3057f6[_0xbf7d('0x37')],{'$or':_[_0xbf7d('0x26')](_0x1caed9,function(_0x4da796){if(_0x4da796[_0xbf7d('0x29')]!==_0xbf7d('0x38')){var _0x5e0f9a={};_0x5e0f9a[_0x4da796[_0xbf7d('0x23')]]={'$like':'%'+_0x366c85[_0xbf7d('0x2c')]['filter']+'%'};return _0x5e0f9a;}})});}_0x3057f6=_[_0xbf7d('0x39')]({},_0x3057f6,_0x366c85[_0xbf7d('0x3a')]);var _0x29f758={'where':_0x3057f6[_0xbf7d('0x37')]};return db[_0xbf7d('0x27')][_0xbf7d('0x1a')](_0x29f758)[_0xbf7d('0x20')](function(_0x19f1a1){_0x418ca3[_0xbf7d('0x1a')]=_0x19f1a1;if(_0x366c85['query'][_0xbf7d('0x3b')]){_0x3057f6[_0xbf7d('0x3c')]=[{'all':!![]}];}return db[_0xbf7d('0x27')][_0xbf7d('0x3d')](_0x3057f6);})[_0xbf7d('0x20')](function(_0x59832a){_0x418ca3[_0xbf7d('0x3e')]=_0x59832a;return _0x418ca3;})[_0xbf7d('0x20')](respondWithFilteredResult(_0x3fe5bd,_0x3057f6))[_0xbf7d('0x3f')](handleError(_0x3fe5bd,null));};exports['show']=function(_0x18b5f9,_0x24240c){var _0x1ea962={'raw':!![],'where':{'id':_0x18b5f9[_0xbf7d('0x40')]['id']}},_0x1e6a76={};_0x1e6a76[_0xbf7d('0x2b')]=_[_0xbf7d('0x41')](db[_0xbf7d('0x27')][_0xbf7d('0x28')]);_0x1e6a76['query']=_[_0xbf7d('0x41')](_0x18b5f9['query']);_0x1e6a76['filters']=_[_0xbf7d('0x2d')](_0x1e6a76['model'],_0x1e6a76[_0xbf7d('0x2c')]);_0x1ea962[_0xbf7d('0x2e')]=_['intersection'](_0x1e6a76[_0xbf7d('0x2b')],qs[_0xbf7d('0x2f')](_0x18b5f9[_0xbf7d('0x2c')][_0xbf7d('0x2f')]));_0x1ea962[_0xbf7d('0x2e')]=_0x1ea962[_0xbf7d('0x2e')][_0xbf7d('0x30')]?_0x1ea962[_0xbf7d('0x2e')]:_0x1e6a76[_0xbf7d('0x2b')];if(_0x18b5f9['query'][_0xbf7d('0x3b')]){_0x1ea962[_0xbf7d('0x3c')]=[{'all':!![]}];}_0x1ea962=_[_0xbf7d('0x39')]({},_0x1ea962,_0x18b5f9[_0xbf7d('0x3a')]);return db[_0xbf7d('0x27')][_0xbf7d('0x42')](_0x1ea962)[_0xbf7d('0x20')](handleEntityNotFound(_0x24240c,null))[_0xbf7d('0x20')](respondWithResult(_0x24240c,null))[_0xbf7d('0x3f')](handleError(_0x24240c,null));};exports['create']=function(_0x4b83f4,_0x16bbc1){return db[_0xbf7d('0x27')][_0xbf7d('0x43')](_0x4b83f4[_0xbf7d('0x44')],{})[_0xbf7d('0x20')](respondWithResult(_0x16bbc1,0xc9))['catch'](handleError(_0x16bbc1,null));};exports[_0xbf7d('0x1f')]=function(_0x1162ef,_0xc90e60){if(_0x1162ef[_0xbf7d('0x44')]['id']){delete _0x1162ef[_0xbf7d('0x44')]['id'];}return db[_0xbf7d('0x27')][_0xbf7d('0x42')]({'where':{'id':_0x1162ef[_0xbf7d('0x40')]['id']}})[_0xbf7d('0x20')](handleEntityNotFound(_0xc90e60,null))['then'](saveUpdates(_0x1162ef['body'],null))['then'](respondWithResult(_0xc90e60,null))[_0xbf7d('0x3f')](handleError(_0xc90e60,null));};exports[_0xbf7d('0x21')]=function(_0x573574,_0x18f566){return db[_0xbf7d('0x27')][_0xbf7d('0x42')]({'where':{'id':_0x573574[_0xbf7d('0x40')]['id']}})['then'](handleEntityNotFound(_0x18f566,null))[_0xbf7d('0x20')](removeEntity(_0x18f566,null))[_0xbf7d('0x3f')](handleError(_0x18f566,null));};