5b62ebecf891e1a1587a702a98322922153edae8
[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 _0x74ea=['type','merge','options','includeAll','include','findAll','rows','catch','params','rawAttributes','length','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','stack','name','send','index','map','OpenchannelTransferReport','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','sort','where','pick','filter'];(function(_0x3b4b1d,_0x15029e){var _0x488c36=function(_0x56c8b3){while(--_0x56c8b3){_0x3b4b1d['push'](_0x3b4b1d['shift']());}};_0x488c36(++_0x15029e);}(_0x74ea,0xf6));var _0xa74e=function(_0x40d058,_0x33bf7c){_0x40d058=_0x40d058-0x0;var _0x48464=_0x74ea[_0x40d058];return _0x48464;};'use strict';var emlformat=require(_0xa74e('0x0'));var rimraf=require(_0xa74e('0x1'));var zipdir=require(_0xa74e('0x2'));var jsonpatch=require(_0xa74e('0x3'));var rp=require(_0xa74e('0x4'));var moment=require(_0xa74e('0x5'));var BPromise=require(_0xa74e('0x6'));var Mustache=require(_0xa74e('0x7'));var util=require(_0xa74e('0x8'));var path=require('path');var sox=require(_0xa74e('0x9'));var csv=require(_0xa74e('0xa'));var ejs=require(_0xa74e('0xb'));var fs=require('fs');var fs_extra=require(_0xa74e('0xc'));var _=require(_0xa74e('0xd'));var squel=require('squel');var crypto=require(_0xa74e('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xa74e('0xf'));var toCsv=require('to-csv');var querystring=require(_0xa74e('0x10'));var Papa=require(_0xa74e('0x11'));var Redis=require(_0xa74e('0x12'));var authService=require(_0xa74e('0x13'));var qs=require(_0xa74e('0x14'));var as=require(_0xa74e('0x15'));var hardwareService=require(_0xa74e('0x16'));var logger=require('../../config/logger')(_0xa74e('0x17'));var utils=require('../../config/utils');var config=require(_0xa74e('0x18'));var licenseUtil=require(_0xa74e('0x19'));var db=require(_0xa74e('0x1a'))['db'];function respondWithStatusCode(_0x4db034,_0x15edfd){_0x15edfd=_0x15edfd||0xcc;return function(_0x33e191){if(_0x33e191){return _0x4db034[_0xa74e('0x1b')](_0x15edfd);}return _0x4db034[_0xa74e('0x1c')](_0x15edfd)[_0xa74e('0x1d')]();};}function respondWithResult(_0x415bef,_0x52fe5b){_0x52fe5b=_0x52fe5b||0xc8;return function(_0x50e7ff){if(_0x50e7ff){return _0x415bef[_0xa74e('0x1c')](_0x52fe5b)[_0xa74e('0x1e')](_0x50e7ff);}};}function respondWithFilteredResult(_0xb5ff08,_0x5733ca){return function(_0x2b88fc){if(_0x2b88fc){var _0x59d795=typeof _0x5733ca[_0xa74e('0x1f')]===_0xa74e('0x20')&&typeof _0x5733ca[_0xa74e('0x21')]===_0xa74e('0x20');var _0x34edc6=_0x2b88fc[_0xa74e('0x22')];var _0x307f2c=_0x59d795?0x0:_0x5733ca[_0xa74e('0x1f')];var _0x10f4b0=_0x59d795?_0x2b88fc[_0xa74e('0x22')]:_0x5733ca[_0xa74e('0x1f')]+_0x5733ca['limit'];var _0x3a6d05;if(_0x10f4b0>=_0x34edc6){_0x10f4b0=_0x34edc6;_0x3a6d05=0xc8;}else{_0x3a6d05=0xce;}_0xb5ff08['status'](_0x3a6d05);return _0xb5ff08[_0xa74e('0x23')](_0xa74e('0x24'),_0x307f2c+'-'+_0x10f4b0+'/'+_0x34edc6)[_0xa74e('0x1e')](_0x2b88fc);}return null;};}function patchUpdates(_0x39bf40){return function(_0x45e6b8){try{jsonpatch[_0xa74e('0x25')](_0x45e6b8,_0x39bf40,!![]);}catch(_0x43dd3b){return BPromise[_0xa74e('0x26')](_0x43dd3b);}return _0x45e6b8[_0xa74e('0x27')]();};}function saveUpdates(_0x4da8e8,_0x52a5a9){return function(_0x1d2587){if(_0x1d2587){return _0x1d2587[_0xa74e('0x28')](_0x4da8e8)[_0xa74e('0x29')](function(_0x4ed885){return _0x4ed885;});}return null;};}function removeEntity(_0x334cb1,_0xc9b060){return function(_0x1a50f9){if(_0x1a50f9){return _0x1a50f9['destroy']()['then'](function(){_0x334cb1['status'](0xcc)[_0xa74e('0x1d')]();});}};}function handleEntityNotFound(_0x1ce2d1,_0xe362f5){return function(_0x46c302){if(!_0x46c302){_0x1ce2d1['sendStatus'](0x194);}return _0x46c302;};}function handleError(_0xad8f56,_0x44045f){_0x44045f=_0x44045f||0x1f4;return function(_0xd16aa5){logger['error'](_0xd16aa5[_0xa74e('0x2a')]);if(_0xd16aa5[_0xa74e('0x2b')]){delete _0xd16aa5[_0xa74e('0x2b')];}_0xad8f56[_0xa74e('0x1c')](_0x44045f)[_0xa74e('0x2c')](_0xd16aa5);};}exports[_0xa74e('0x2d')]=function(_0x3a2411,_0x4967ea){var _0x389092={},_0x449654={},_0x1fe29f={'count':0x0,'rows':[]};var _0x3cc8f8=_[_0xa74e('0x2e')](db[_0xa74e('0x2f')]['rawAttributes'],function(_0xf0c7cf){return{'name':_0xf0c7cf['fieldName'],'type':_0xf0c7cf['type'][_0xa74e('0x30')]};});_0x449654[_0xa74e('0x31')]=_[_0xa74e('0x2e')](_0x3cc8f8,'name');_0x449654[_0xa74e('0x32')]=_[_0xa74e('0x33')](_0x3a2411[_0xa74e('0x32')]);_0x449654[_0xa74e('0x34')]=_[_0xa74e('0x35')](_0x449654[_0xa74e('0x31')],_0x449654[_0xa74e('0x32')]);_0x389092[_0xa74e('0x36')]=_[_0xa74e('0x35')](_0x449654[_0xa74e('0x31')],qs[_0xa74e('0x37')](_0x3a2411[_0xa74e('0x32')][_0xa74e('0x37')]));_0x389092[_0xa74e('0x36')]=_0x389092['attributes']['length']?_0x389092[_0xa74e('0x36')]:_0x449654[_0xa74e('0x31')];if(!_0x3a2411[_0xa74e('0x32')][_0xa74e('0x38')](_0xa74e('0x39'))){_0x389092[_0xa74e('0x21')]=qs[_0xa74e('0x21')](_0x3a2411['query'][_0xa74e('0x21')]);_0x389092['offset']=qs[_0xa74e('0x1f')](_0x3a2411['query']['offset']);}_0x389092['order']=qs[_0xa74e('0x3a')](_0x3a2411[_0xa74e('0x32')][_0xa74e('0x3a')]);_0x389092[_0xa74e('0x3b')]=qs[_0xa74e('0x34')](_[_0xa74e('0x3c')](_0x3a2411[_0xa74e('0x32')],_0x449654[_0xa74e('0x34')]),_0x3cc8f8);if(_0x3a2411[_0xa74e('0x32')][_0xa74e('0x3d')]){_0x389092[_0xa74e('0x3b')]=_['merge'](_0x389092[_0xa74e('0x3b')],{'$or':_['map'](_0x3cc8f8,function(_0x23d77e){if(_0x23d77e[_0xa74e('0x3e')]!=='VIRTUAL'){var _0x52b2b7={};_0x52b2b7[_0x23d77e['name']]={'$like':'%'+_0x3a2411['query'][_0xa74e('0x3d')]+'%'};return _0x52b2b7;}})});}_0x389092=_[_0xa74e('0x3f')]({},_0x389092,_0x3a2411[_0xa74e('0x40')]);var _0x5d1263={'where':_0x389092[_0xa74e('0x3b')]};return db[_0xa74e('0x2f')]['count'](_0x5d1263)[_0xa74e('0x29')](function(_0x5b8a55){_0x1fe29f[_0xa74e('0x22')]=_0x5b8a55;if(_0x3a2411[_0xa74e('0x32')][_0xa74e('0x41')]){_0x389092[_0xa74e('0x42')]=[{'all':!![]}];}return db['OpenchannelTransferReport'][_0xa74e('0x43')](_0x389092);})[_0xa74e('0x29')](function(_0x1bc722){_0x1fe29f[_0xa74e('0x44')]=_0x1bc722;return _0x1fe29f;})[_0xa74e('0x29')](respondWithFilteredResult(_0x4967ea,_0x389092))[_0xa74e('0x45')](handleError(_0x4967ea,null));};exports['show']=function(_0x5d2f8b,_0x48e096){var _0x3bfe08={'raw':!![],'where':{'id':_0x5d2f8b[_0xa74e('0x46')]['id']}},_0xb756fb={};_0xb756fb['model']=_[_0xa74e('0x33')](db[_0xa74e('0x2f')][_0xa74e('0x47')]);_0xb756fb[_0xa74e('0x32')]=_[_0xa74e('0x33')](_0x5d2f8b[_0xa74e('0x32')]);_0xb756fb[_0xa74e('0x34')]=_[_0xa74e('0x35')](_0xb756fb[_0xa74e('0x31')],_0xb756fb[_0xa74e('0x32')]);_0x3bfe08[_0xa74e('0x36')]=_[_0xa74e('0x35')](_0xb756fb[_0xa74e('0x31')],qs['fields'](_0x5d2f8b['query'][_0xa74e('0x37')]));_0x3bfe08[_0xa74e('0x36')]=_0x3bfe08[_0xa74e('0x36')][_0xa74e('0x48')]?_0x3bfe08[_0xa74e('0x36')]:_0xb756fb['model'];if(_0x5d2f8b[_0xa74e('0x32')][_0xa74e('0x41')]){_0x3bfe08[_0xa74e('0x42')]=[{'all':!![]}];}_0x3bfe08=_[_0xa74e('0x3f')]({},_0x3bfe08,_0x5d2f8b['options']);return db[_0xa74e('0x2f')][_0xa74e('0x49')](_0x3bfe08)[_0xa74e('0x29')](handleEntityNotFound(_0x48e096,null))[_0xa74e('0x29')](respondWithResult(_0x48e096,null))[_0xa74e('0x45')](handleError(_0x48e096,null));};exports['create']=function(_0x377b4a,_0x448824){return db[_0xa74e('0x2f')][_0xa74e('0x4a')](_0x377b4a[_0xa74e('0x4b')],{})[_0xa74e('0x29')](respondWithResult(_0x448824,0xc9))[_0xa74e('0x45')](handleError(_0x448824,null));};exports[_0xa74e('0x28')]=function(_0x36e9ff,_0x1d5b13){if(_0x36e9ff[_0xa74e('0x4b')]['id']){delete _0x36e9ff['body']['id'];}return db[_0xa74e('0x2f')][_0xa74e('0x49')]({'where':{'id':_0x36e9ff[_0xa74e('0x46')]['id']}})[_0xa74e('0x29')](handleEntityNotFound(_0x1d5b13,null))['then'](saveUpdates(_0x36e9ff[_0xa74e('0x4b')],null))[_0xa74e('0x29')](respondWithResult(_0x1d5b13,null))['catch'](handleError(_0x1d5b13,null));};exports['destroy']=function(_0xccecda,_0x5619ad){return db[_0xa74e('0x2f')]['find']({'where':{'id':_0xccecda[_0xa74e('0x46')]['id']}})[_0xa74e('0x29')](handleEntityNotFound(_0x5619ad,null))[_0xa74e('0x29')](removeEntity(_0x5619ad,null))[_0xa74e('0x45')](handleError(_0x5619ad,null));};exports[_0xa74e('0x4c')]=function(_0x16eaf2,_0x8ad717){return db[_0xa74e('0x2f')][_0xa74e('0x4c')]()[_0xa74e('0x29')](respondWithResult(_0x8ad717,null))[_0xa74e('0x45')](handleError(_0x8ad717,null));};