e4b2d5f36a9e566ca6fb597bb28f903128449ee7
[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 _0xac4f=['body','describe','eml-format','zip-dir','request-promise','mustache','util','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','Content-Range','reject','update','then','destroy','error','name','send','index','map','rawAttributes','type','model','keys','filters','intersection','query','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','filter','merge','VIRTUAL','options','OpenchannelTransferReport','includeAll','findAll','rows','catch','show','params','find','create'];(function(_0x4c7f8e,_0x202031){var _0x40f410=function(_0x39faa9){while(--_0x39faa9){_0x4c7f8e['push'](_0x4c7f8e['shift']());}};_0x40f410(++_0x202031);}(_0xac4f,0x122));var _0xfac4=function(_0x47a802,_0x424bf1){_0x47a802=_0x47a802-0x0;var _0xb3badc=_0xac4f[_0x47a802];return _0xb3badc;};'use strict';var emlformat=require(_0xfac4('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xfac4('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xfac4('0x2'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xfac4('0x3'));var util=require(_0xfac4('0x4'));var path=require('path');var sox=require(_0xfac4('0x5'));var csv=require(_0xfac4('0x6'));var ejs=require(_0xfac4('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xfac4('0x8'));var squel=require(_0xfac4('0x9'));var crypto=require(_0xfac4('0xa'));var jsforce=require(_0xfac4('0xb'));var deskjs=require(_0xfac4('0xc'));var toCsv=require(_0xfac4('0x6'));var querystring=require('querystring');var Papa=require(_0xfac4('0xd'));var Redis=require(_0xfac4('0xe'));var authService=require(_0xfac4('0xf'));var qs=require(_0xfac4('0x10'));var as=require(_0xfac4('0x11'));var hardwareService=require(_0xfac4('0x12'));var logger=require(_0xfac4('0x13'))(_0xfac4('0x14'));var utils=require(_0xfac4('0x15'));var config=require(_0xfac4('0x16'));var licenseUtil=require(_0xfac4('0x17'));var db=require(_0xfac4('0x18'))['db'];function respondWithStatusCode(_0x5e374a,_0x2f9c87){_0x2f9c87=_0x2f9c87||0xcc;return function(_0x5bcc16){if(_0x5bcc16){return _0x5e374a[_0xfac4('0x19')](_0x2f9c87);}return _0x5e374a[_0xfac4('0x1a')](_0x2f9c87)[_0xfac4('0x1b')]();};}function respondWithResult(_0x4599cc,_0x114653){_0x114653=_0x114653||0xc8;return function(_0xcde790){if(_0xcde790){return _0x4599cc[_0xfac4('0x1a')](_0x114653)[_0xfac4('0x1c')](_0xcde790);}};}function respondWithFilteredResult(_0x48a42b,_0x3d529f){return function(_0x40fe62){if(_0x40fe62){var _0x3be3c1=_0x40fe62[_0xfac4('0x1d')],_0xcf7e40=_0x3d529f[_0xfac4('0x1e')],_0x2c8c6f=_0x3d529f[_0xfac4('0x1e')]+_0x3d529f['limit'],_0x3ce345;if(_0x2c8c6f>=_0x3be3c1){_0x2c8c6f=_0x3be3c1;_0x3ce345=0xc8;}else{_0x3ce345=0xce;}_0x48a42b['status'](_0x3ce345);return _0x48a42b['set'](_0xfac4('0x1f'),_0xcf7e40+'-'+_0x2c8c6f+'/'+_0x3be3c1)[_0xfac4('0x1c')](_0x40fe62);}return null;};}function patchUpdates(_0x4aec9e){return function(_0x5d75c2){try{jsonpatch['apply'](_0x5d75c2,_0x4aec9e,!![]);}catch(_0x15fcc7){return BPromise[_0xfac4('0x20')](_0x15fcc7);}return _0x5d75c2['save']();};}function saveUpdates(_0x227f7e,_0xb69d66){return function(_0x347499){if(_0x347499){return _0x347499[_0xfac4('0x21')](_0x227f7e)[_0xfac4('0x22')](function(_0x3392d7){return _0x3392d7;});}return null;};}function removeEntity(_0x41ac63,_0x6b08a2){return function(_0x238895){if(_0x238895){return _0x238895[_0xfac4('0x23')]()[_0xfac4('0x22')](function(){_0x41ac63['status'](0xcc)[_0xfac4('0x1b')]();});}};}function handleEntityNotFound(_0x1b09d2,_0x56aab9){return function(_0x410602){if(!_0x410602){_0x1b09d2[_0xfac4('0x19')](0x194);}return _0x410602;};}function handleError(_0x27493f,_0x4e32d4){_0x4e32d4=_0x4e32d4||0x1f4;return function(_0x44d637){logger[_0xfac4('0x24')](_0x44d637['stack']);if(_0x44d637[_0xfac4('0x25')]){delete _0x44d637[_0xfac4('0x25')];}_0x27493f[_0xfac4('0x1a')](_0x4e32d4)[_0xfac4('0x26')](_0x44d637);};}exports[_0xfac4('0x27')]=function(_0x528844,_0x3cb605){var _0x544f82={},_0x299cca={},_0x254dfa={'count':0x0,'rows':[]};var _0x549306=_[_0xfac4('0x28')](db['OpenchannelTransferReport'][_0xfac4('0x29')],function(_0x59c386){return{'name':_0x59c386['fieldName'],'type':_0x59c386[_0xfac4('0x2a')]['key']};});_0x299cca[_0xfac4('0x2b')]=_[_0xfac4('0x28')](_0x549306,'name');_0x299cca['query']=_[_0xfac4('0x2c')](_0x528844['query']);_0x299cca[_0xfac4('0x2d')]=_[_0xfac4('0x2e')](_0x299cca[_0xfac4('0x2b')],_0x299cca[_0xfac4('0x2f')]);_0x544f82[_0xfac4('0x30')]=_[_0xfac4('0x2e')](_0x299cca['model'],qs['fields'](_0x528844[_0xfac4('0x2f')][_0xfac4('0x31')]));_0x544f82[_0xfac4('0x30')]=_0x544f82[_0xfac4('0x30')][_0xfac4('0x32')]?_0x544f82[_0xfac4('0x30')]:_0x299cca[_0xfac4('0x2b')];if(!_0x528844[_0xfac4('0x2f')][_0xfac4('0x33')](_0xfac4('0x34'))){_0x544f82['limit']=qs['limit'](_0x528844[_0xfac4('0x2f')][_0xfac4('0x35')]);_0x544f82[_0xfac4('0x1e')]=qs[_0xfac4('0x1e')](_0x528844[_0xfac4('0x2f')][_0xfac4('0x1e')]);}_0x544f82[_0xfac4('0x36')]=qs[_0xfac4('0x37')](_0x528844[_0xfac4('0x2f')][_0xfac4('0x37')]);_0x544f82[_0xfac4('0x38')]=qs[_0xfac4('0x2d')](_['pick'](_0x528844[_0xfac4('0x2f')],_0x299cca[_0xfac4('0x2d')]),_0x549306);if(_0x528844[_0xfac4('0x2f')][_0xfac4('0x39')]){_0x544f82[_0xfac4('0x38')]=_[_0xfac4('0x3a')](_0x544f82['where'],{'$or':_['map'](_0x549306,function(_0x3dfcfe){if(_0x3dfcfe[_0xfac4('0x2a')]!==_0xfac4('0x3b')){var _0x5b891c={};_0x5b891c[_0x3dfcfe[_0xfac4('0x25')]]={'$like':'%'+_0x528844[_0xfac4('0x2f')][_0xfac4('0x39')]+'%'};return _0x5b891c;}})});}_0x544f82=_[_0xfac4('0x3a')]({},_0x544f82,_0x528844[_0xfac4('0x3c')]);var _0x505cb4={'where':_0x544f82[_0xfac4('0x38')]};return db[_0xfac4('0x3d')][_0xfac4('0x1d')](_0x505cb4)[_0xfac4('0x22')](function(_0x136ef1){_0x254dfa[_0xfac4('0x1d')]=_0x136ef1;if(_0x528844[_0xfac4('0x2f')][_0xfac4('0x3e')]){_0x544f82['include']=[{'all':!![]}];}return db[_0xfac4('0x3d')][_0xfac4('0x3f')](_0x544f82);})[_0xfac4('0x22')](function(_0x2c0207){_0x254dfa[_0xfac4('0x40')]=_0x2c0207;return _0x254dfa;})[_0xfac4('0x22')](respondWithFilteredResult(_0x3cb605,_0x544f82))[_0xfac4('0x41')](handleError(_0x3cb605,null));};exports[_0xfac4('0x42')]=function(_0x1fc9d6,_0x1a9aee){var _0x4127c6={'raw':!![],'where':{'id':_0x1fc9d6[_0xfac4('0x43')]['id']}},_0x27847f={};_0x27847f[_0xfac4('0x2b')]=_[_0xfac4('0x2c')](db['OpenchannelTransferReport']['rawAttributes']);_0x27847f['query']=_[_0xfac4('0x2c')](_0x1fc9d6[_0xfac4('0x2f')]);_0x27847f[_0xfac4('0x2d')]=_[_0xfac4('0x2e')](_0x27847f[_0xfac4('0x2b')],_0x27847f[_0xfac4('0x2f')]);_0x4127c6['attributes']=_['intersection'](_0x27847f['model'],qs[_0xfac4('0x31')](_0x1fc9d6['query'][_0xfac4('0x31')]));_0x4127c6[_0xfac4('0x30')]=_0x4127c6[_0xfac4('0x30')][_0xfac4('0x32')]?_0x4127c6[_0xfac4('0x30')]:_0x27847f[_0xfac4('0x2b')];if(_0x1fc9d6[_0xfac4('0x2f')][_0xfac4('0x3e')]){_0x4127c6['include']=[{'all':!![]}];}_0x4127c6=_[_0xfac4('0x3a')]({},_0x4127c6,_0x1fc9d6[_0xfac4('0x3c')]);return db['OpenchannelTransferReport'][_0xfac4('0x44')](_0x4127c6)['then'](handleEntityNotFound(_0x1a9aee,null))[_0xfac4('0x22')](respondWithResult(_0x1a9aee,null))[_0xfac4('0x41')](handleError(_0x1a9aee,null));};exports[_0xfac4('0x45')]=function(_0x43e9a4,_0x3cfe87){return db[_0xfac4('0x3d')]['create'](_0x43e9a4[_0xfac4('0x46')],{})[_0xfac4('0x22')](respondWithResult(_0x3cfe87,0xc9))[_0xfac4('0x41')](handleError(_0x3cfe87,null));};exports[_0xfac4('0x21')]=function(_0x559cea,_0x274db6){if(_0x559cea[_0xfac4('0x46')]['id']){delete _0x559cea[_0xfac4('0x46')]['id'];}return db['OpenchannelTransferReport'][_0xfac4('0x44')]({'where':{'id':_0x559cea[_0xfac4('0x43')]['id']}})[_0xfac4('0x22')](handleEntityNotFound(_0x274db6,null))[_0xfac4('0x22')](saveUpdates(_0x559cea['body'],null))[_0xfac4('0x22')](respondWithResult(_0x274db6,null))['catch'](handleError(_0x274db6,null));};exports[_0xfac4('0x23')]=function(_0x54d735,_0x224a54){return db[_0xfac4('0x3d')][_0xfac4('0x44')]({'where':{'id':_0x54d735[_0xfac4('0x43')]['id']}})['then'](handleEntityNotFound(_0x224a54,null))[_0xfac4('0x22')](removeEntity(_0x224a54,null))['catch'](handleError(_0x224a54,null));};exports['describe']=function(_0x4e22a0,_0x30dc38){return db[_0xfac4('0x3d')][_0xfac4('0x47')]()[_0xfac4('0x22')](respondWithResult(_0x30dc38,null))[_0xfac4('0x41')](handleError(_0x30dc38,null));};