Built motion from commit (unavailable).|2.4.21
[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 _0xd5fb=['merge','options','count','includeAll','include','findAll','show','params','find','catch','create','body','update','destroy','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','sox','to-csv','ejs','lodash','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../mysqldb','sendStatus','end','status','limit','Content-Range','json','apply','then','error','stack','name','map','OpenchannelApplication','rawAttributes','fieldName','key','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','offset','sort','where','type'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xd5fb,0x94));var _0xbd5f=function(_0x4e7fbe,_0x585460){_0x4e7fbe=_0x4e7fbe-0x0;var _0x2e2277=_0xd5fb[_0x4e7fbe];return _0x2e2277;};'use strict';var pdf=require(_0xbd5f('0x0'));var emlformat=require(_0xbd5f('0x1'));var rimraf=require(_0xbd5f('0x2'));var zipdir=require(_0xbd5f('0x3'));var jsonpatch=require(_0xbd5f('0x4'));var rp=require(_0xbd5f('0x5'));var moment=require(_0xbd5f('0x6'));var BPromise=require(_0xbd5f('0x7'));var Mustache=require(_0xbd5f('0x8'));var util=require('util');var path=require('path');var sox=require(_0xbd5f('0x9'));var csv=require(_0xbd5f('0xa'));var ejs=require(_0xbd5f('0xb'));var fs=require('fs');var _=require(_0xbd5f('0xc'));var squel=require('squel');var crypto=require(_0xbd5f('0xd'));var jsforce=require('jsforce');var deskjs=require(_0xbd5f('0xe'));var toCsv=require('to-csv');var querystring=require(_0xbd5f('0xf'));var Papa=require(_0xbd5f('0x10'));var Redis=require(_0xbd5f('0x11'));var authService=require(_0xbd5f('0x12'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xbd5f('0x13'));var logger=require(_0xbd5f('0x14'))(_0xbd5f('0x15'));var utils=require('../../config/utils');var config=require('../../config/environment');var db=require(_0xbd5f('0x16'))['db'];function respondWithStatusCode(_0x9c5e4f,_0x193a0b){_0x193a0b=_0x193a0b||0xcc;return function(_0x462f31){if(_0x462f31){return _0x9c5e4f[_0xbd5f('0x17')](_0x193a0b);}return _0x9c5e4f['status'](_0x193a0b)[_0xbd5f('0x18')]();};}function respondWithResult(_0x49ee47,_0x16aea5){_0x16aea5=_0x16aea5||0xc8;return function(_0x31699d){if(_0x31699d){return _0x49ee47[_0xbd5f('0x19')](_0x16aea5)['json'](_0x31699d);}};}function respondWithFilteredResult(_0x2d2875,_0x499e8f){return function(_0xc610b9){if(_0xc610b9){var _0x54d307=_0xc610b9['count'],_0x43e599=_0x499e8f['offset'],_0x26e398=_0x499e8f['offset']+_0x499e8f[_0xbd5f('0x1a')],_0x3e1570;if(_0x26e398>=_0x54d307){_0x26e398=_0x54d307;_0x3e1570=0xc8;}else{_0x3e1570=0xce;}_0x2d2875[_0xbd5f('0x19')](_0x3e1570);return _0x2d2875['set'](_0xbd5f('0x1b'),_0x43e599+'-'+_0x26e398+'/'+_0x54d307)[_0xbd5f('0x1c')](_0xc610b9);}return null;};}function patchUpdates(_0x58269c){return function(_0x64f35d){try{jsonpatch[_0xbd5f('0x1d')](_0x64f35d,_0x58269c,!![]);}catch(_0x29d26e){return BPromise['reject'](_0x29d26e);}return _0x64f35d['save']();};}function saveUpdates(_0x2812ac,_0x369ac2){return function(_0x3b2e76){if(_0x3b2e76){return _0x3b2e76['update'](_0x2812ac)[_0xbd5f('0x1e')](function(_0x3e2752){return _0x3e2752;});}return null;};}function removeEntity(_0x1c8194,_0x240253){return function(_0x2156bd){if(_0x2156bd){return _0x2156bd['destroy']()[_0xbd5f('0x1e')](function(){_0x1c8194[_0xbd5f('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x136708,_0x4e5f52){return function(_0x4a64b1){if(!_0x4a64b1){_0x136708[_0xbd5f('0x17')](0x194);}return _0x4a64b1;};}function handleError(_0x4f87ed,_0x14f8f7){_0x14f8f7=_0x14f8f7||0x1f4;return function(_0x310ae8){logger[_0xbd5f('0x1f')](_0x310ae8[_0xbd5f('0x20')]);if(_0x310ae8['name']){delete _0x310ae8[_0xbd5f('0x21')];}_0x4f87ed[_0xbd5f('0x19')](_0x14f8f7)['send'](_0x310ae8);};}exports['index']=function(_0x139d2f,_0x4c5aa9){var _0x1d2db2={},_0x1f8c0d={},_0x4d90ab={'count':0x0,'rows':[]};var _0x278a31=_[_0xbd5f('0x22')](db[_0xbd5f('0x23')][_0xbd5f('0x24')],function(_0x59ff97){return{'name':_0x59ff97[_0xbd5f('0x25')],'type':_0x59ff97['type'][_0xbd5f('0x26')]};});_0x1f8c0d['model']=_[_0xbd5f('0x22')](_0x278a31,_0xbd5f('0x21'));_0x1f8c0d[_0xbd5f('0x27')]=_[_0xbd5f('0x28')](_0x139d2f[_0xbd5f('0x27')]);_0x1f8c0d[_0xbd5f('0x29')]=_[_0xbd5f('0x2a')](_0x1f8c0d[_0xbd5f('0x2b')],_0x1f8c0d[_0xbd5f('0x27')]);_0x1d2db2[_0xbd5f('0x2c')]=_['intersection'](_0x1f8c0d[_0xbd5f('0x2b')],qs[_0xbd5f('0x2d')](_0x139d2f['query'][_0xbd5f('0x2d')]));_0x1d2db2[_0xbd5f('0x2c')]=_0x1d2db2[_0xbd5f('0x2c')][_0xbd5f('0x2e')]?_0x1d2db2[_0xbd5f('0x2c')]:_0x1f8c0d['model'];if(!_0x139d2f[_0xbd5f('0x27')][_0xbd5f('0x2f')](_0xbd5f('0x30'))){_0x1d2db2['limit']=qs[_0xbd5f('0x1a')](_0x139d2f[_0xbd5f('0x27')][_0xbd5f('0x1a')]);_0x1d2db2['offset']=qs['offset'](_0x139d2f[_0xbd5f('0x27')][_0xbd5f('0x31')]);}_0x1d2db2['order']=qs[_0xbd5f('0x32')](_0x139d2f[_0xbd5f('0x27')][_0xbd5f('0x32')]);_0x1d2db2['where']=qs[_0xbd5f('0x29')](_['pick'](_0x139d2f['query'],_0x1f8c0d['filters']));if(_0x139d2f[_0xbd5f('0x27')]['filter']){_0x1d2db2[_0xbd5f('0x33')]=_['merge'](_0x1d2db2[_0xbd5f('0x33')],{'$or':_[_0xbd5f('0x22')](_0x278a31,function(_0x3274b){if(_0x3274b[_0xbd5f('0x34')]!=='VIRTUAL'){var _0xfcc782={};_0xfcc782[_0x3274b[_0xbd5f('0x21')]]={'$like':'%'+_0x139d2f['query']['filter']+'%'};return _0xfcc782;}})});}_0x1d2db2=_[_0xbd5f('0x35')]({},_0x1d2db2,_0x139d2f[_0xbd5f('0x36')]);var _0x5e701e={'where':_0x1d2db2['where']};return db[_0xbd5f('0x23')][_0xbd5f('0x37')](_0x5e701e)['then'](function(_0x3b274b){_0x4d90ab[_0xbd5f('0x37')]=_0x3b274b;if(_0x139d2f['query'][_0xbd5f('0x38')]){_0x1d2db2[_0xbd5f('0x39')]=[{'all':!![]}];}return db[_0xbd5f('0x23')][_0xbd5f('0x3a')](_0x1d2db2);})[_0xbd5f('0x1e')](function(_0x5b2bbd){_0x4d90ab['rows']=_0x5b2bbd;return _0x4d90ab;})['then'](respondWithFilteredResult(_0x4c5aa9,_0x1d2db2))['catch'](handleError(_0x4c5aa9,null));};exports[_0xbd5f('0x3b')]=function(_0x49592d,_0x4e6ad8){var _0x575455={'raw':!![],'where':{'id':_0x49592d[_0xbd5f('0x3c')]['id']}},_0x2f1e01={};_0x2f1e01[_0xbd5f('0x2b')]=_[_0xbd5f('0x28')](db['OpenchannelApplication']['rawAttributes']);_0x2f1e01[_0xbd5f('0x27')]=_[_0xbd5f('0x28')](_0x49592d[_0xbd5f('0x27')]);_0x2f1e01[_0xbd5f('0x29')]=_[_0xbd5f('0x2a')](_0x2f1e01[_0xbd5f('0x2b')],_0x2f1e01['query']);_0x575455[_0xbd5f('0x2c')]=_[_0xbd5f('0x2a')](_0x2f1e01['model'],qs[_0xbd5f('0x2d')](_0x49592d[_0xbd5f('0x27')]['fields']));_0x575455['attributes']=_0x575455[_0xbd5f('0x2c')][_0xbd5f('0x2e')]?_0x575455[_0xbd5f('0x2c')]:_0x2f1e01['model'];if(_0x49592d['query'][_0xbd5f('0x38')]){_0x575455['include']=[{'all':!![]}];}_0x575455=_[_0xbd5f('0x35')]({},_0x575455,_0x49592d[_0xbd5f('0x36')]);return db[_0xbd5f('0x23')][_0xbd5f('0x3d')](_0x575455)[_0xbd5f('0x1e')](handleEntityNotFound(_0x4e6ad8,null))[_0xbd5f('0x1e')](respondWithResult(_0x4e6ad8,null))[_0xbd5f('0x3e')](handleError(_0x4e6ad8,null));};exports[_0xbd5f('0x3f')]=function(_0x3fdfa9,_0x3df853){return db[_0xbd5f('0x23')]['create'](_0x3fdfa9[_0xbd5f('0x40')],{})[_0xbd5f('0x1e')](respondWithResult(_0x3df853,0xc9))['catch'](handleError(_0x3df853,null));};exports[_0xbd5f('0x41')]=function(_0x316531,_0x48db75){if(_0x316531['body']['id']){delete _0x316531[_0xbd5f('0x40')]['id'];}return db[_0xbd5f('0x23')][_0xbd5f('0x3d')]({'where':{'id':_0x316531[_0xbd5f('0x3c')]['id']}})['then'](handleEntityNotFound(_0x48db75,null))[_0xbd5f('0x1e')](saveUpdates(_0x316531[_0xbd5f('0x40')],null))[_0xbd5f('0x1e')](respondWithResult(_0x48db75,null))[_0xbd5f('0x3e')](handleError(_0x48db75,null));};exports[_0xbd5f('0x42')]=function(_0x5bd1df,_0x52eb47){return db[_0xbd5f('0x23')]['find']({'where':{'id':_0x5bd1df[_0xbd5f('0x3c')]['id']}})['then'](handleEntityNotFound(_0x52eb47,null))['then'](removeEntity(_0x52eb47,null))[_0xbd5f('0x3e')](handleError(_0x52eb47,null));};