Built motion from commit (unavailable).|2.5.4
[motion2.git] / server / api / openchannelTransferReport / openchannelTransferReport.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 _0xbc5e=['attributes','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','merge','options','count','includeAll','include','findAll','rows','catch','show','params','keys','create','body','find','describe','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','status','end','offset','set','Content-Range','json','apply','reject','update','then','destroy','sendStatus','error','stack','name','send','map','OpenchannelTransferReport','rawAttributes','key','model','query','filters','intersection','fields'];(function(_0x58d48c,_0x5c13f4){var _0x37e0ba=function(_0x221ef5){while(--_0x221ef5){_0x58d48c['push'](_0x58d48c['shift']());}};_0x37e0ba(++_0x5c13f4);}(_0xbc5e,0x65));var _0xebc5=function(_0x35e641,_0x4b5f7e){_0x35e641=_0x35e641-0x0;var _0x24c608=_0xbc5e[_0x35e641];return _0x24c608;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xebc5('0x0'));var rimraf=require(_0xebc5('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xebc5('0x2'));var rp=require(_0xebc5('0x3'));var moment=require(_0xebc5('0x4'));var BPromise=require(_0xebc5('0x5'));var Mustache=require(_0xebc5('0x6'));var util=require(_0xebc5('0x7'));var path=require(_0xebc5('0x8'));var sox=require(_0xebc5('0x9'));var csv=require(_0xebc5('0xa'));var ejs=require(_0xebc5('0xb'));var fs=require('fs');var _=require(_0xebc5('0xc'));var squel=require(_0xebc5('0xd'));var crypto=require(_0xebc5('0xe'));var jsforce=require(_0xebc5('0xf'));var deskjs=require(_0xebc5('0x10'));var toCsv=require('to-csv');var querystring=require(_0xebc5('0x11'));var Papa=require('papaparse');var Redis=require(_0xebc5('0x12'));var authService=require(_0xebc5('0x13'));var qs=require(_0xebc5('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xebc5('0x15'));var logger=require(_0xebc5('0x16'))('api');var utils=require(_0xebc5('0x17'));var config=require(_0xebc5('0x18'));var db=require(_0xebc5('0x19'))['db'];function respondWithStatusCode(_0x561c09,_0x489222){_0x489222=_0x489222||0xcc;return function(_0x146711){if(_0x146711){return _0x561c09['sendStatus'](_0x489222);}return _0x561c09[_0xebc5('0x1a')](_0x489222)[_0xebc5('0x1b')]();};}function respondWithResult(_0xf8c6bc,_0x2c2ee6){_0x2c2ee6=_0x2c2ee6||0xc8;return function(_0x1b8637){if(_0x1b8637){return _0xf8c6bc[_0xebc5('0x1a')](_0x2c2ee6)['json'](_0x1b8637);}};}function respondWithFilteredResult(_0x52d3da,_0x5be60b){return function(_0x2d2020){if(_0x2d2020){var _0x4aecad=_0x2d2020['count'],_0x5a9caf=_0x5be60b[_0xebc5('0x1c')],_0x24048e=_0x5be60b[_0xebc5('0x1c')]+_0x5be60b['limit'],_0x2f943f;if(_0x24048e>=_0x4aecad){_0x24048e=_0x4aecad;_0x2f943f=0xc8;}else{_0x2f943f=0xce;}_0x52d3da[_0xebc5('0x1a')](_0x2f943f);return _0x52d3da[_0xebc5('0x1d')](_0xebc5('0x1e'),_0x5a9caf+'-'+_0x24048e+'/'+_0x4aecad)[_0xebc5('0x1f')](_0x2d2020);}return null;};}function patchUpdates(_0xfe2874){return function(_0x458669){try{jsonpatch[_0xebc5('0x20')](_0x458669,_0xfe2874,!![]);}catch(_0x27f5c4){return BPromise[_0xebc5('0x21')](_0x27f5c4);}return _0x458669['save']();};}function saveUpdates(_0x1579e0,_0x5905d7){return function(_0x27918b){if(_0x27918b){return _0x27918b[_0xebc5('0x22')](_0x1579e0)[_0xebc5('0x23')](function(_0x3078f2){return _0x3078f2;});}return null;};}function removeEntity(_0x1394e1,_0x487f52){return function(_0x1522b0){if(_0x1522b0){return _0x1522b0[_0xebc5('0x24')]()[_0xebc5('0x23')](function(){_0x1394e1[_0xebc5('0x1a')](0xcc)[_0xebc5('0x1b')]();});}};}function handleEntityNotFound(_0x265ba9,_0xa05d87){return function(_0x560ac6){if(!_0x560ac6){_0x265ba9[_0xebc5('0x25')](0x194);}return _0x560ac6;};}function handleError(_0x38c781,_0x27b62a){_0x27b62a=_0x27b62a||0x1f4;return function(_0x5ec1cf){logger[_0xebc5('0x26')](_0x5ec1cf[_0xebc5('0x27')]);if(_0x5ec1cf[_0xebc5('0x28')]){delete _0x5ec1cf[_0xebc5('0x28')];}_0x38c781[_0xebc5('0x1a')](_0x27b62a)[_0xebc5('0x29')](_0x5ec1cf);};}exports['index']=function(_0x1808f2,_0x15b01b){var _0x327611={},_0x4cd9d9={},_0x74fa1f={'count':0x0,'rows':[]};var _0x56bae=_[_0xebc5('0x2a')](db[_0xebc5('0x2b')][_0xebc5('0x2c')],function(_0x132acf){return{'name':_0x132acf['fieldName'],'type':_0x132acf['type'][_0xebc5('0x2d')]};});_0x4cd9d9[_0xebc5('0x2e')]=_[_0xebc5('0x2a')](_0x56bae,'name');_0x4cd9d9[_0xebc5('0x2f')]=_['keys'](_0x1808f2[_0xebc5('0x2f')]);_0x4cd9d9[_0xebc5('0x30')]=_[_0xebc5('0x31')](_0x4cd9d9[_0xebc5('0x2e')],_0x4cd9d9[_0xebc5('0x2f')]);_0x327611['attributes']=_[_0xebc5('0x31')](_0x4cd9d9[_0xebc5('0x2e')],qs[_0xebc5('0x32')](_0x1808f2['query'][_0xebc5('0x32')]));_0x327611['attributes']=_0x327611[_0xebc5('0x33')][_0xebc5('0x34')]?_0x327611['attributes']:_0x4cd9d9[_0xebc5('0x2e')];if(!_0x1808f2[_0xebc5('0x2f')][_0xebc5('0x35')](_0xebc5('0x36'))){_0x327611['limit']=qs[_0xebc5('0x37')](_0x1808f2[_0xebc5('0x2f')][_0xebc5('0x37')]);_0x327611[_0xebc5('0x1c')]=qs[_0xebc5('0x1c')](_0x1808f2['query'][_0xebc5('0x1c')]);}_0x327611[_0xebc5('0x38')]=qs[_0xebc5('0x39')](_0x1808f2[_0xebc5('0x2f')]['sort']);_0x327611[_0xebc5('0x3a')]=qs[_0xebc5('0x30')](_[_0xebc5('0x3b')](_0x1808f2[_0xebc5('0x2f')],_0x4cd9d9['filters']),_0x56bae);if(_0x1808f2[_0xebc5('0x2f')][_0xebc5('0x3c')]){_0x327611[_0xebc5('0x3a')]=_[_0xebc5('0x3d')](_0x327611[_0xebc5('0x3a')],{'$or':_[_0xebc5('0x2a')](_0x56bae,function(_0x1610f6){if(_0x1610f6['type']!=='VIRTUAL'){var _0x2385a5={};_0x2385a5[_0x1610f6[_0xebc5('0x28')]]={'$like':'%'+_0x1808f2[_0xebc5('0x2f')][_0xebc5('0x3c')]+'%'};return _0x2385a5;}})});}_0x327611=_[_0xebc5('0x3d')]({},_0x327611,_0x1808f2[_0xebc5('0x3e')]);var _0xa7a9f8={'where':_0x327611[_0xebc5('0x3a')]};return db[_0xebc5('0x2b')][_0xebc5('0x3f')](_0xa7a9f8)[_0xebc5('0x23')](function(_0x594c3c){_0x74fa1f[_0xebc5('0x3f')]=_0x594c3c;if(_0x1808f2['query'][_0xebc5('0x40')]){_0x327611[_0xebc5('0x41')]=[{'all':!![]}];}return db[_0xebc5('0x2b')][_0xebc5('0x42')](_0x327611);})[_0xebc5('0x23')](function(_0xc1fdf7){_0x74fa1f[_0xebc5('0x43')]=_0xc1fdf7;return _0x74fa1f;})[_0xebc5('0x23')](respondWithFilteredResult(_0x15b01b,_0x327611))[_0xebc5('0x44')](handleError(_0x15b01b,null));};exports[_0xebc5('0x45')]=function(_0x82edd1,_0x413396){var _0x2b4c79={'raw':!![],'where':{'id':_0x82edd1[_0xebc5('0x46')]['id']}},_0x44c7b3={};_0x44c7b3[_0xebc5('0x2e')]=_['keys'](db[_0xebc5('0x2b')][_0xebc5('0x2c')]);_0x44c7b3[_0xebc5('0x2f')]=_[_0xebc5('0x47')](_0x82edd1[_0xebc5('0x2f')]);_0x44c7b3[_0xebc5('0x30')]=_[_0xebc5('0x31')](_0x44c7b3['model'],_0x44c7b3[_0xebc5('0x2f')]);_0x2b4c79[_0xebc5('0x33')]=_['intersection'](_0x44c7b3[_0xebc5('0x2e')],qs[_0xebc5('0x32')](_0x82edd1['query'][_0xebc5('0x32')]));_0x2b4c79[_0xebc5('0x33')]=_0x2b4c79[_0xebc5('0x33')][_0xebc5('0x34')]?_0x2b4c79[_0xebc5('0x33')]:_0x44c7b3[_0xebc5('0x2e')];if(_0x82edd1['query']['includeAll']){_0x2b4c79['include']=[{'all':!![]}];}_0x2b4c79=_[_0xebc5('0x3d')]({},_0x2b4c79,_0x82edd1[_0xebc5('0x3e')]);return db[_0xebc5('0x2b')]['find'](_0x2b4c79)[_0xebc5('0x23')](handleEntityNotFound(_0x413396,null))[_0xebc5('0x23')](respondWithResult(_0x413396,null))[_0xebc5('0x44')](handleError(_0x413396,null));};exports[_0xebc5('0x48')]=function(_0x2b2f5c,_0x383ebc){return db[_0xebc5('0x2b')][_0xebc5('0x48')](_0x2b2f5c[_0xebc5('0x49')],{})['then'](respondWithResult(_0x383ebc,0xc9))[_0xebc5('0x44')](handleError(_0x383ebc,null));};exports[_0xebc5('0x22')]=function(_0x545880,_0x3ce4fb){if(_0x545880['body']['id']){delete _0x545880['body']['id'];}return db['OpenchannelTransferReport'][_0xebc5('0x4a')]({'where':{'id':_0x545880[_0xebc5('0x46')]['id']}})[_0xebc5('0x23')](handleEntityNotFound(_0x3ce4fb,null))[_0xebc5('0x23')](saveUpdates(_0x545880[_0xebc5('0x49')],null))[_0xebc5('0x23')](respondWithResult(_0x3ce4fb,null))[_0xebc5('0x44')](handleError(_0x3ce4fb,null));};exports[_0xebc5('0x24')]=function(_0x119339,_0xd24be2){return db['OpenchannelTransferReport'][_0xebc5('0x4a')]({'where':{'id':_0x119339[_0xebc5('0x46')]['id']}})[_0xebc5('0x23')](handleEntityNotFound(_0xd24be2,null))['then'](removeEntity(_0xd24be2,null))[_0xebc5('0x44')](handleError(_0xd24be2,null));};exports[_0xebc5('0x4b')]=function(_0x1f05d0,_0x27ff06){return db[_0xebc5('0x2b')][_0xebc5('0x4b')]()[_0xebc5('0x23')](respondWithResult(_0x27ff06,null))[_0xebc5('0x44')](handleError(_0x27ff06,null));};