60d9d8f4905fd19aa19babfe1f4ff0e593511fce
[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 _0x3f6f=['request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','sendStatus','end','status','offset','undefined','limit','count','set','json','apply','reject','update','then','destroy','error','stack','name','send','index','map','OpenchannelTransferReport','fieldName','key','model','query','keys','filters','intersection','attributes','fields','nolimit','pick','where','merge','type','VIRTUAL','filter','includeAll','findAll','catch','rawAttributes','length','include','find','create','body','params','describe','eml-format','rimraf','fast-json-patch'];(function(_0x133851,_0x4d6780){var _0x188215=function(_0x1aa541){while(--_0x1aa541){_0x133851['push'](_0x133851['shift']());}};_0x188215(++_0x4d6780);}(_0x3f6f,0x1cb));var _0xf3f6=function(_0x4ef6c4,_0x20c957){_0x4ef6c4=_0x4ef6c4-0x0;var _0x2073ab=_0x3f6f[_0x4ef6c4];return _0x2073ab;};'use strict';var emlformat=require(_0xf3f6('0x0'));var rimraf=require(_0xf3f6('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf3f6('0x2'));var rp=require(_0xf3f6('0x3'));var moment=require(_0xf3f6('0x4'));var BPromise=require(_0xf3f6('0x5'));var Mustache=require(_0xf3f6('0x6'));var util=require(_0xf3f6('0x7'));var path=require(_0xf3f6('0x8'));var sox=require(_0xf3f6('0x9'));var csv=require(_0xf3f6('0xa'));var ejs=require(_0xf3f6('0xb'));var fs=require('fs');var fs_extra=require(_0xf3f6('0xc'));var _=require(_0xf3f6('0xd'));var squel=require(_0xf3f6('0xe'));var crypto=require(_0xf3f6('0xf'));var jsforce=require(_0xf3f6('0x10'));var deskjs=require(_0xf3f6('0x11'));var toCsv=require(_0xf3f6('0xa'));var querystring=require(_0xf3f6('0x12'));var Papa=require(_0xf3f6('0x13'));var Redis=require(_0xf3f6('0x14'));var authService=require(_0xf3f6('0x15'));var qs=require(_0xf3f6('0x16'));var as=require(_0xf3f6('0x17'));var hardwareService=require(_0xf3f6('0x18'));var logger=require(_0xf3f6('0x19'))('api');var utils=require(_0xf3f6('0x1a'));var config=require(_0xf3f6('0x1b'));var licenseUtil=require(_0xf3f6('0x1c'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x2b5d1a,_0x453c64){_0x453c64=_0x453c64||0xcc;return function(_0xcdc519){if(_0xcdc519){return _0x2b5d1a[_0xf3f6('0x1d')](_0x453c64);}return _0x2b5d1a['status'](_0x453c64)[_0xf3f6('0x1e')]();};}function respondWithResult(_0x437e0d,_0x7b1b7f){_0x7b1b7f=_0x7b1b7f||0xc8;return function(_0x20db3d){if(_0x20db3d){return _0x437e0d[_0xf3f6('0x1f')](_0x7b1b7f)['json'](_0x20db3d);}};}function respondWithFilteredResult(_0x4e60fa,_0x3b3404){return function(_0xdffa2f){if(_0xdffa2f){var _0x558986=typeof _0x3b3404[_0xf3f6('0x20')]===_0xf3f6('0x21')&&typeof _0x3b3404[_0xf3f6('0x22')]===_0xf3f6('0x21');var _0x267040=_0xdffa2f[_0xf3f6('0x23')];var _0x12bea3=_0x558986?0x0:_0x3b3404[_0xf3f6('0x20')];var _0x37b8f1=_0x558986?_0xdffa2f['count']:_0x3b3404[_0xf3f6('0x20')]+_0x3b3404['limit'];var _0x364f5a;if(_0x37b8f1>=_0x267040){_0x37b8f1=_0x267040;_0x364f5a=0xc8;}else{_0x364f5a=0xce;}_0x4e60fa[_0xf3f6('0x1f')](_0x364f5a);return _0x4e60fa[_0xf3f6('0x24')]('Content-Range',_0x12bea3+'-'+_0x37b8f1+'/'+_0x267040)[_0xf3f6('0x25')](_0xdffa2f);}return null;};}function patchUpdates(_0x258228){return function(_0x44aa6f){try{jsonpatch[_0xf3f6('0x26')](_0x44aa6f,_0x258228,!![]);}catch(_0x3e6a71){return BPromise[_0xf3f6('0x27')](_0x3e6a71);}return _0x44aa6f['save']();};}function saveUpdates(_0x4c313a,_0x491f76){return function(_0x404a6d){if(_0x404a6d){return _0x404a6d[_0xf3f6('0x28')](_0x4c313a)[_0xf3f6('0x29')](function(_0x37f576){return _0x37f576;});}return null;};}function removeEntity(_0x4e54d2,_0x505844){return function(_0x45d76d){if(_0x45d76d){return _0x45d76d[_0xf3f6('0x2a')]()[_0xf3f6('0x29')](function(){_0x4e54d2[_0xf3f6('0x1f')](0xcc)[_0xf3f6('0x1e')]();});}};}function handleEntityNotFound(_0x3f5984,_0x32cbc7){return function(_0x4fe1eb){if(!_0x4fe1eb){_0x3f5984[_0xf3f6('0x1d')](0x194);}return _0x4fe1eb;};}function handleError(_0x3595c7,_0x4c6146){_0x4c6146=_0x4c6146||0x1f4;return function(_0x37c35d){logger[_0xf3f6('0x2b')](_0x37c35d[_0xf3f6('0x2c')]);if(_0x37c35d[_0xf3f6('0x2d')]){delete _0x37c35d[_0xf3f6('0x2d')];}_0x3595c7['status'](_0x4c6146)[_0xf3f6('0x2e')](_0x37c35d);};}exports[_0xf3f6('0x2f')]=function(_0x30accb,_0x966f9b){var _0x3a15d8={},_0x4f671e={},_0x1586e5={'count':0x0,'rows':[]};var _0x3a28de=_[_0xf3f6('0x30')](db[_0xf3f6('0x31')]['rawAttributes'],function(_0x159ea6){return{'name':_0x159ea6[_0xf3f6('0x32')],'type':_0x159ea6['type'][_0xf3f6('0x33')]};});_0x4f671e[_0xf3f6('0x34')]=_[_0xf3f6('0x30')](_0x3a28de,_0xf3f6('0x2d'));_0x4f671e[_0xf3f6('0x35')]=_[_0xf3f6('0x36')](_0x30accb[_0xf3f6('0x35')]);_0x4f671e[_0xf3f6('0x37')]=_[_0xf3f6('0x38')](_0x4f671e[_0xf3f6('0x34')],_0x4f671e[_0xf3f6('0x35')]);_0x3a15d8[_0xf3f6('0x39')]=_[_0xf3f6('0x38')](_0x4f671e[_0xf3f6('0x34')],qs[_0xf3f6('0x3a')](_0x30accb[_0xf3f6('0x35')][_0xf3f6('0x3a')]));_0x3a15d8[_0xf3f6('0x39')]=_0x3a15d8[_0xf3f6('0x39')]['length']?_0x3a15d8[_0xf3f6('0x39')]:_0x4f671e[_0xf3f6('0x34')];if(!_0x30accb[_0xf3f6('0x35')]['hasOwnProperty'](_0xf3f6('0x3b'))){_0x3a15d8[_0xf3f6('0x22')]=qs[_0xf3f6('0x22')](_0x30accb['query'][_0xf3f6('0x22')]);_0x3a15d8[_0xf3f6('0x20')]=qs[_0xf3f6('0x20')](_0x30accb[_0xf3f6('0x35')][_0xf3f6('0x20')]);}_0x3a15d8['order']=qs['sort'](_0x30accb['query']['sort']);_0x3a15d8['where']=qs['filters'](_[_0xf3f6('0x3c')](_0x30accb[_0xf3f6('0x35')],_0x4f671e[_0xf3f6('0x37')]),_0x3a28de);if(_0x30accb[_0xf3f6('0x35')]['filter']){_0x3a15d8[_0xf3f6('0x3d')]=_[_0xf3f6('0x3e')](_0x3a15d8[_0xf3f6('0x3d')],{'$or':_['map'](_0x3a28de,function(_0x547925){if(_0x547925[_0xf3f6('0x3f')]!==_0xf3f6('0x40')){var _0x5b8fb9={};_0x5b8fb9[_0x547925[_0xf3f6('0x2d')]]={'$like':'%'+_0x30accb[_0xf3f6('0x35')][_0xf3f6('0x41')]+'%'};return _0x5b8fb9;}})});}_0x3a15d8=_[_0xf3f6('0x3e')]({},_0x3a15d8,_0x30accb['options']);var _0x33b117={'where':_0x3a15d8['where']};return db[_0xf3f6('0x31')]['count'](_0x33b117)['then'](function(_0x21a6bf){_0x1586e5['count']=_0x21a6bf;if(_0x30accb[_0xf3f6('0x35')][_0xf3f6('0x42')]){_0x3a15d8['include']=[{'all':!![]}];}return db['OpenchannelTransferReport'][_0xf3f6('0x43')](_0x3a15d8);})[_0xf3f6('0x29')](function(_0x38a100){_0x1586e5['rows']=_0x38a100;return _0x1586e5;})[_0xf3f6('0x29')](respondWithFilteredResult(_0x966f9b,_0x3a15d8))[_0xf3f6('0x44')](handleError(_0x966f9b,null));};exports['show']=function(_0x150a1b,_0x507d6f){var _0x278252={'raw':!![],'where':{'id':_0x150a1b['params']['id']}},_0x20bca9={};_0x20bca9[_0xf3f6('0x34')]=_[_0xf3f6('0x36')](db[_0xf3f6('0x31')][_0xf3f6('0x45')]);_0x20bca9[_0xf3f6('0x35')]=_[_0xf3f6('0x36')](_0x150a1b[_0xf3f6('0x35')]);_0x20bca9[_0xf3f6('0x37')]=_[_0xf3f6('0x38')](_0x20bca9[_0xf3f6('0x34')],_0x20bca9[_0xf3f6('0x35')]);_0x278252[_0xf3f6('0x39')]=_[_0xf3f6('0x38')](_0x20bca9[_0xf3f6('0x34')],qs[_0xf3f6('0x3a')](_0x150a1b[_0xf3f6('0x35')][_0xf3f6('0x3a')]));_0x278252[_0xf3f6('0x39')]=_0x278252[_0xf3f6('0x39')][_0xf3f6('0x46')]?_0x278252[_0xf3f6('0x39')]:_0x20bca9[_0xf3f6('0x34')];if(_0x150a1b[_0xf3f6('0x35')]['includeAll']){_0x278252[_0xf3f6('0x47')]=[{'all':!![]}];}_0x278252=_[_0xf3f6('0x3e')]({},_0x278252,_0x150a1b['options']);return db[_0xf3f6('0x31')][_0xf3f6('0x48')](_0x278252)[_0xf3f6('0x29')](handleEntityNotFound(_0x507d6f,null))[_0xf3f6('0x29')](respondWithResult(_0x507d6f,null))['catch'](handleError(_0x507d6f,null));};exports['create']=function(_0x490ff3,_0x40eb3b){return db[_0xf3f6('0x31')][_0xf3f6('0x49')](_0x490ff3[_0xf3f6('0x4a')],{})[_0xf3f6('0x29')](respondWithResult(_0x40eb3b,0xc9))['catch'](handleError(_0x40eb3b,null));};exports[_0xf3f6('0x28')]=function(_0x544b29,_0xeadb1a){if(_0x544b29[_0xf3f6('0x4a')]['id']){delete _0x544b29[_0xf3f6('0x4a')]['id'];}return db[_0xf3f6('0x31')][_0xf3f6('0x48')]({'where':{'id':_0x544b29[_0xf3f6('0x4b')]['id']}})[_0xf3f6('0x29')](handleEntityNotFound(_0xeadb1a,null))[_0xf3f6('0x29')](saveUpdates(_0x544b29[_0xf3f6('0x4a')],null))['then'](respondWithResult(_0xeadb1a,null))[_0xf3f6('0x44')](handleError(_0xeadb1a,null));};exports['destroy']=function(_0x5c06ba,_0x5974af){return db['OpenchannelTransferReport']['find']({'where':{'id':_0x5c06ba['params']['id']}})[_0xf3f6('0x29')](handleEntityNotFound(_0x5974af,null))[_0xf3f6('0x29')](removeEntity(_0x5974af,null))['catch'](handleError(_0x5974af,null));};exports[_0xf3f6('0x4c')]=function(_0x2fbc93,_0x533760){return db['OpenchannelTransferReport'][_0xf3f6('0x4c')]()[_0xf3f6('0x29')](respondWithResult(_0x533760,null))['catch'](handleError(_0x533760,null));};