Built motion from commit (unavailable).|2.5.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 _0xf957=['querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../mysqldb','sendStatus','status','end','json','count','offset','set','Content-Range','apply','reject','save','then','error','stack','name','map','OpenchannelApplication','rawAttributes','fieldName','type','key','model','query','keys','filters','fields','attributes','nolimit','limit','sort','where','pick','merge','VIRTUAL','filter','includeAll','include','findAll','catch','show','params','intersection','length','options','find','create','body','update','html-pdf','rimraf','zip-dir','request-promise','mustache','path','sox','to-csv','ejs','crypto','jsforce','desk.js'];(function(_0x474ced,_0xb25add){var _0x550265=function(_0x3203e4){while(--_0x3203e4){_0x474ced['push'](_0x474ced['shift']());}};_0x550265(++_0xb25add);}(_0xf957,0xc0));var _0x7f95=function(_0x32a656,_0x36adfd){_0x32a656=_0x32a656-0x0;var _0x1713fd=_0xf957[_0x32a656];return _0x1713fd;};'use strict';var pdf=require(_0x7f95('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x7f95('0x1'));var zipdir=require(_0x7f95('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x7f95('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x7f95('0x4'));var util=require('util');var path=require(_0x7f95('0x5'));var sox=require(_0x7f95('0x6'));var csv=require(_0x7f95('0x7'));var ejs=require(_0x7f95('0x8'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0x7f95('0x9'));var jsforce=require(_0x7f95('0xa'));var deskjs=require(_0x7f95('0xb'));var toCsv=require(_0x7f95('0x7'));var querystring=require(_0x7f95('0xc'));var Papa=require(_0x7f95('0xd'));var Redis=require('ioredis');var authService=require(_0x7f95('0xe'));var qs=require(_0x7f95('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x7f95('0x10'))(_0x7f95('0x11'));var utils=require('../../config/utils');var config=require(_0x7f95('0x12'));var db=require(_0x7f95('0x13'))['db'];function respondWithStatusCode(_0x5e5ae6,_0x16da68){_0x16da68=_0x16da68||0xcc;return function(_0x504416){if(_0x504416){return _0x5e5ae6[_0x7f95('0x14')](_0x16da68);}return _0x5e5ae6[_0x7f95('0x15')](_0x16da68)[_0x7f95('0x16')]();};}function respondWithResult(_0x29c7d5,_0x527d9c){_0x527d9c=_0x527d9c||0xc8;return function(_0x30091a){if(_0x30091a){return _0x29c7d5[_0x7f95('0x15')](_0x527d9c)[_0x7f95('0x17')](_0x30091a);}};}function respondWithFilteredResult(_0x102c9d,_0x2ffe14){return function(_0x31384e){if(_0x31384e){var _0x22ed5d=_0x31384e[_0x7f95('0x18')],_0x2b1444=_0x2ffe14[_0x7f95('0x19')],_0x279d01=_0x2ffe14[_0x7f95('0x19')]+_0x2ffe14['limit'],_0x110909;if(_0x279d01>=_0x22ed5d){_0x279d01=_0x22ed5d;_0x110909=0xc8;}else{_0x110909=0xce;}_0x102c9d['status'](_0x110909);return _0x102c9d[_0x7f95('0x1a')](_0x7f95('0x1b'),_0x2b1444+'-'+_0x279d01+'/'+_0x22ed5d)[_0x7f95('0x17')](_0x31384e);}return null;};}function patchUpdates(_0x21a617){return function(_0x2ac1fb){try{jsonpatch[_0x7f95('0x1c')](_0x2ac1fb,_0x21a617,!![]);}catch(_0x1b153b){return BPromise[_0x7f95('0x1d')](_0x1b153b);}return _0x2ac1fb[_0x7f95('0x1e')]();};}function saveUpdates(_0x144cfc,_0x53f68f){return function(_0x10fcc0){if(_0x10fcc0){return _0x10fcc0['update'](_0x144cfc)[_0x7f95('0x1f')](function(_0x383784){return _0x383784;});}return null;};}function removeEntity(_0x455867,_0x12f726){return function(_0x3c36fb){if(_0x3c36fb){return _0x3c36fb['destroy']()[_0x7f95('0x1f')](function(){_0x455867[_0x7f95('0x15')](0xcc)[_0x7f95('0x16')]();});}};}function handleEntityNotFound(_0x159b43,_0x430f1c){return function(_0x5004ba){if(!_0x5004ba){_0x159b43[_0x7f95('0x14')](0x194);}return _0x5004ba;};}function handleError(_0x5b4064,_0xd5d193){_0xd5d193=_0xd5d193||0x1f4;return function(_0x474f36){logger[_0x7f95('0x20')](_0x474f36[_0x7f95('0x21')]);if(_0x474f36[_0x7f95('0x22')]){delete _0x474f36[_0x7f95('0x22')];}_0x5b4064[_0x7f95('0x15')](_0xd5d193)['send'](_0x474f36);};}exports['index']=function(_0x185641,_0x2043b7){var _0x59cf45={},_0x1131aa={},_0x87ed3f={'count':0x0,'rows':[]};var _0x425247=_[_0x7f95('0x23')](db[_0x7f95('0x24')][_0x7f95('0x25')],function(_0x151b52){return{'name':_0x151b52[_0x7f95('0x26')],'type':_0x151b52[_0x7f95('0x27')][_0x7f95('0x28')]};});_0x1131aa[_0x7f95('0x29')]=_[_0x7f95('0x23')](_0x425247,'name');_0x1131aa[_0x7f95('0x2a')]=_[_0x7f95('0x2b')](_0x185641[_0x7f95('0x2a')]);_0x1131aa[_0x7f95('0x2c')]=_['intersection'](_0x1131aa[_0x7f95('0x29')],_0x1131aa['query']);_0x59cf45['attributes']=_['intersection'](_0x1131aa[_0x7f95('0x29')],qs[_0x7f95('0x2d')](_0x185641['query'][_0x7f95('0x2d')]));_0x59cf45['attributes']=_0x59cf45[_0x7f95('0x2e')]['length']?_0x59cf45[_0x7f95('0x2e')]:_0x1131aa['model'];if(!_0x185641[_0x7f95('0x2a')]['hasOwnProperty'](_0x7f95('0x2f'))){_0x59cf45[_0x7f95('0x30')]=qs[_0x7f95('0x30')](_0x185641[_0x7f95('0x2a')][_0x7f95('0x30')]);_0x59cf45[_0x7f95('0x19')]=qs[_0x7f95('0x19')](_0x185641[_0x7f95('0x2a')][_0x7f95('0x19')]);}_0x59cf45['order']=qs[_0x7f95('0x31')](_0x185641[_0x7f95('0x2a')][_0x7f95('0x31')]);_0x59cf45[_0x7f95('0x32')]=qs[_0x7f95('0x2c')](_[_0x7f95('0x33')](_0x185641[_0x7f95('0x2a')],_0x1131aa['filters']),_0x425247);if(_0x185641[_0x7f95('0x2a')]['filter']){_0x59cf45[_0x7f95('0x32')]=_[_0x7f95('0x34')](_0x59cf45[_0x7f95('0x32')],{'$or':_[_0x7f95('0x23')](_0x425247,function(_0xee1d1e){if(_0xee1d1e['type']!==_0x7f95('0x35')){var _0x20ac57={};_0x20ac57[_0xee1d1e[_0x7f95('0x22')]]={'$like':'%'+_0x185641[_0x7f95('0x2a')][_0x7f95('0x36')]+'%'};return _0x20ac57;}})});}_0x59cf45=_['merge']({},_0x59cf45,_0x185641['options']);var _0x313902={'where':_0x59cf45[_0x7f95('0x32')]};return db[_0x7f95('0x24')][_0x7f95('0x18')](_0x313902)[_0x7f95('0x1f')](function(_0x4835d5){_0x87ed3f[_0x7f95('0x18')]=_0x4835d5;if(_0x185641['query'][_0x7f95('0x37')]){_0x59cf45[_0x7f95('0x38')]=[{'all':!![]}];}return db[_0x7f95('0x24')][_0x7f95('0x39')](_0x59cf45);})['then'](function(_0x3e63eb){_0x87ed3f['rows']=_0x3e63eb;return _0x87ed3f;})[_0x7f95('0x1f')](respondWithFilteredResult(_0x2043b7,_0x59cf45))[_0x7f95('0x3a')](handleError(_0x2043b7,null));};exports[_0x7f95('0x3b')]=function(_0xbc308d,_0xda5386){var _0x27645e={'raw':!![],'where':{'id':_0xbc308d[_0x7f95('0x3c')]['id']}},_0x12fbde={};_0x12fbde['model']=_[_0x7f95('0x2b')](db[_0x7f95('0x24')][_0x7f95('0x25')]);_0x12fbde[_0x7f95('0x2a')]=_[_0x7f95('0x2b')](_0xbc308d[_0x7f95('0x2a')]);_0x12fbde['filters']=_['intersection'](_0x12fbde[_0x7f95('0x29')],_0x12fbde[_0x7f95('0x2a')]);_0x27645e[_0x7f95('0x2e')]=_[_0x7f95('0x3d')](_0x12fbde[_0x7f95('0x29')],qs[_0x7f95('0x2d')](_0xbc308d[_0x7f95('0x2a')][_0x7f95('0x2d')]));_0x27645e[_0x7f95('0x2e')]=_0x27645e[_0x7f95('0x2e')][_0x7f95('0x3e')]?_0x27645e[_0x7f95('0x2e')]:_0x12fbde[_0x7f95('0x29')];if(_0xbc308d[_0x7f95('0x2a')][_0x7f95('0x37')]){_0x27645e['include']=[{'all':!![]}];}_0x27645e=_[_0x7f95('0x34')]({},_0x27645e,_0xbc308d[_0x7f95('0x3f')]);return db['OpenchannelApplication'][_0x7f95('0x40')](_0x27645e)['then'](handleEntityNotFound(_0xda5386,null))['then'](respondWithResult(_0xda5386,null))[_0x7f95('0x3a')](handleError(_0xda5386,null));};exports[_0x7f95('0x41')]=function(_0x7dc195,_0x1f660d){return db[_0x7f95('0x24')][_0x7f95('0x41')](_0x7dc195[_0x7f95('0x42')],{})['then'](respondWithResult(_0x1f660d,0xc9))['catch'](handleError(_0x1f660d,null));};exports[_0x7f95('0x43')]=function(_0x1c7c91,_0x1e93dd){if(_0x1c7c91[_0x7f95('0x42')]['id']){delete _0x1c7c91[_0x7f95('0x42')]['id'];}return db[_0x7f95('0x24')][_0x7f95('0x40')]({'where':{'id':_0x1c7c91['params']['id']}})[_0x7f95('0x1f')](handleEntityNotFound(_0x1e93dd,null))[_0x7f95('0x1f')](saveUpdates(_0x1c7c91[_0x7f95('0x42')],null))['then'](respondWithResult(_0x1e93dd,null))[_0x7f95('0x3a')](handleError(_0x1e93dd,null));};exports['destroy']=function(_0x1d4d9d,_0x3888c7){return db['OpenchannelApplication']['find']({'where':{'id':_0x1d4d9d[_0x7f95('0x3c')]['id']}})[_0x7f95('0x1f')](handleEntityNotFound(_0x3888c7,null))[_0x7f95('0x1f')](removeEntity(_0x3888c7,null))['catch'](handleError(_0x3888c7,null));};