35d8d61f4a8e603454255b9bf03ab98d8cd21ddd
[motion2.git] / server / api / faxTransferReport / faxTransferReport.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 _0x639f=['util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','json','reject','save','then','destroy','error','stack','name','send','index','map','rawAttributes','fieldName','keys','query','filters','model','attributes','fields','hasOwnProperty','nolimit','sort','where','pick','filter','merge','VIRTUAL','options','FaxTransferReport','includeAll','include','findAll','rows','show','params','intersection','length','find','catch','create','body','describe','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache'];(function(_0x6d6a66,_0x2924af){var _0x11eb6e=function(_0x52e55a){while(--_0x52e55a){_0x6d6a66['push'](_0x6d6a66['shift']());}};_0x11eb6e(++_0x2924af);}(_0x639f,0x139));var _0xf639=function(_0x429391,_0x4d7dcb){_0x429391=_0x429391-0x0;var _0x47fe61=_0x639f[_0x429391];return _0x47fe61;};'use strict';var emlformat=require(_0xf639('0x0'));var rimraf=require(_0xf639('0x1'));var zipdir=require(_0xf639('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf639('0x3'));var moment=require(_0xf639('0x4'));var BPromise=require(_0xf639('0x5'));var Mustache=require(_0xf639('0x6'));var util=require(_0xf639('0x7'));var path=require(_0xf639('0x8'));var sox=require(_0xf639('0x9'));var csv=require(_0xf639('0xa'));var ejs=require(_0xf639('0xb'));var fs=require('fs');var fs_extra=require(_0xf639('0xc'));var _=require(_0xf639('0xd'));var squel=require(_0xf639('0xe'));var crypto=require(_0xf639('0xf'));var jsforce=require(_0xf639('0x10'));var deskjs=require(_0xf639('0x11'));var toCsv=require('to-csv');var querystring=require(_0xf639('0x12'));var Papa=require(_0xf639('0x13'));var Redis=require(_0xf639('0x14'));var authService=require('../../components/auth/service');var qs=require(_0xf639('0x15'));var as=require(_0xf639('0x16'));var hardwareService=require(_0xf639('0x17'));var logger=require(_0xf639('0x18'))('api');var utils=require(_0xf639('0x19'));var config=require(_0xf639('0x1a'));var licenseUtil=require(_0xf639('0x1b'));var db=require(_0xf639('0x1c'))['db'];function respondWithStatusCode(_0x174fca,_0x224c75){_0x224c75=_0x224c75||0xcc;return function(_0x525278){if(_0x525278){return _0x174fca[_0xf639('0x1d')](_0x224c75);}return _0x174fca[_0xf639('0x1e')](_0x224c75)[_0xf639('0x1f')]();};}function respondWithResult(_0x2b653a,_0x4edce1){_0x4edce1=_0x4edce1||0xc8;return function(_0x133f17){if(_0x133f17){return _0x2b653a[_0xf639('0x1e')](_0x4edce1)['json'](_0x133f17);}};}function respondWithFilteredResult(_0x36e22c,_0x191ffa){return function(_0xfcb6d6){if(_0xfcb6d6){var _0x23cbc6=typeof _0x191ffa[_0xf639('0x20')]===_0xf639('0x21')&&typeof _0x191ffa[_0xf639('0x22')]===_0xf639('0x21');var _0x431b10=_0xfcb6d6[_0xf639('0x23')];var _0x455eb8=_0x23cbc6?0x0:_0x191ffa[_0xf639('0x20')];var _0x13f15=_0x23cbc6?_0xfcb6d6[_0xf639('0x23')]:_0x191ffa[_0xf639('0x20')]+_0x191ffa['limit'];var _0x5566f5;if(_0x13f15>=_0x431b10){_0x13f15=_0x431b10;_0x5566f5=0xc8;}else{_0x5566f5=0xce;}_0x36e22c[_0xf639('0x1e')](_0x5566f5);return _0x36e22c[_0xf639('0x24')](_0xf639('0x25'),_0x455eb8+'-'+_0x13f15+'/'+_0x431b10)[_0xf639('0x26')](_0xfcb6d6);}return null;};}function patchUpdates(_0x230b37){return function(_0xe0166a){try{jsonpatch['apply'](_0xe0166a,_0x230b37,!![]);}catch(_0x2e9704){return BPromise[_0xf639('0x27')](_0x2e9704);}return _0xe0166a[_0xf639('0x28')]();};}function saveUpdates(_0x2a3835,_0x5be0e6){return function(_0x47d82e){if(_0x47d82e){return _0x47d82e['update'](_0x2a3835)[_0xf639('0x29')](function(_0x51b9f2){return _0x51b9f2;});}return null;};}function removeEntity(_0x288e3a,_0x4399b3){return function(_0x362dbf){if(_0x362dbf){return _0x362dbf[_0xf639('0x2a')]()[_0xf639('0x29')](function(){_0x288e3a[_0xf639('0x1e')](0xcc)['end']();});}};}function handleEntityNotFound(_0x409aea,_0x573420){return function(_0x95015c){if(!_0x95015c){_0x409aea[_0xf639('0x1d')](0x194);}return _0x95015c;};}function handleError(_0x32d420,_0x48125c){_0x48125c=_0x48125c||0x1f4;return function(_0x3969f1){logger[_0xf639('0x2b')](_0x3969f1[_0xf639('0x2c')]);if(_0x3969f1[_0xf639('0x2d')]){delete _0x3969f1[_0xf639('0x2d')];}_0x32d420['status'](_0x48125c)[_0xf639('0x2e')](_0x3969f1);};}exports[_0xf639('0x2f')]=function(_0x2b1924,_0x3fdaf2){var _0x304960={},_0x481262={},_0x179067={'count':0x0,'rows':[]};var _0x3229fc=_[_0xf639('0x30')](db['FaxTransferReport'][_0xf639('0x31')],function(_0x43039d){return{'name':_0x43039d[_0xf639('0x32')],'type':_0x43039d['type']['key']};});_0x481262['model']=_['map'](_0x3229fc,_0xf639('0x2d'));_0x481262['query']=_[_0xf639('0x33')](_0x2b1924[_0xf639('0x34')]);_0x481262[_0xf639('0x35')]=_['intersection'](_0x481262[_0xf639('0x36')],_0x481262[_0xf639('0x34')]);_0x304960[_0xf639('0x37')]=_['intersection'](_0x481262['model'],qs[_0xf639('0x38')](_0x2b1924[_0xf639('0x34')][_0xf639('0x38')]));_0x304960[_0xf639('0x37')]=_0x304960[_0xf639('0x37')]['length']?_0x304960['attributes']:_0x481262[_0xf639('0x36')];if(!_0x2b1924[_0xf639('0x34')][_0xf639('0x39')](_0xf639('0x3a'))){_0x304960['limit']=qs[_0xf639('0x22')](_0x2b1924[_0xf639('0x34')][_0xf639('0x22')]);_0x304960[_0xf639('0x20')]=qs[_0xf639('0x20')](_0x2b1924[_0xf639('0x34')][_0xf639('0x20')]);}_0x304960['order']=qs['sort'](_0x2b1924[_0xf639('0x34')][_0xf639('0x3b')]);_0x304960[_0xf639('0x3c')]=qs[_0xf639('0x35')](_[_0xf639('0x3d')](_0x2b1924[_0xf639('0x34')],_0x481262[_0xf639('0x35')]),_0x3229fc);if(_0x2b1924[_0xf639('0x34')][_0xf639('0x3e')]){_0x304960[_0xf639('0x3c')]=_[_0xf639('0x3f')](_0x304960[_0xf639('0x3c')],{'$or':_[_0xf639('0x30')](_0x3229fc,function(_0x136374){if(_0x136374['type']!==_0xf639('0x40')){var _0x13d4ea={};_0x13d4ea[_0x136374[_0xf639('0x2d')]]={'$like':'%'+_0x2b1924[_0xf639('0x34')][_0xf639('0x3e')]+'%'};return _0x13d4ea;}})});}_0x304960=_['merge']({},_0x304960,_0x2b1924[_0xf639('0x41')]);var _0x2493e2={'where':_0x304960[_0xf639('0x3c')]};return db[_0xf639('0x42')][_0xf639('0x23')](_0x2493e2)[_0xf639('0x29')](function(_0x4ff77f){_0x179067[_0xf639('0x23')]=_0x4ff77f;if(_0x2b1924[_0xf639('0x34')][_0xf639('0x43')]){_0x304960[_0xf639('0x44')]=[{'all':!![]}];}return db[_0xf639('0x42')][_0xf639('0x45')](_0x304960);})['then'](function(_0x2d6274){_0x179067[_0xf639('0x46')]=_0x2d6274;return _0x179067;})['then'](respondWithFilteredResult(_0x3fdaf2,_0x304960))['catch'](handleError(_0x3fdaf2,null));};exports[_0xf639('0x47')]=function(_0x4c21dd,_0x4d410a){var _0x3069da={'raw':!![],'where':{'id':_0x4c21dd[_0xf639('0x48')]['id']}},_0x4fc496={};_0x4fc496[_0xf639('0x36')]=_[_0xf639('0x33')](db[_0xf639('0x42')][_0xf639('0x31')]);_0x4fc496[_0xf639('0x34')]=_[_0xf639('0x33')](_0x4c21dd[_0xf639('0x34')]);_0x4fc496[_0xf639('0x35')]=_[_0xf639('0x49')](_0x4fc496['model'],_0x4fc496[_0xf639('0x34')]);_0x3069da[_0xf639('0x37')]=_['intersection'](_0x4fc496[_0xf639('0x36')],qs[_0xf639('0x38')](_0x4c21dd[_0xf639('0x34')][_0xf639('0x38')]));_0x3069da[_0xf639('0x37')]=_0x3069da['attributes'][_0xf639('0x4a')]?_0x3069da['attributes']:_0x4fc496[_0xf639('0x36')];if(_0x4c21dd[_0xf639('0x34')]['includeAll']){_0x3069da[_0xf639('0x44')]=[{'all':!![]}];}_0x3069da=_[_0xf639('0x3f')]({},_0x3069da,_0x4c21dd[_0xf639('0x41')]);return db['FaxTransferReport'][_0xf639('0x4b')](_0x3069da)[_0xf639('0x29')](handleEntityNotFound(_0x4d410a,null))[_0xf639('0x29')](respondWithResult(_0x4d410a,null))[_0xf639('0x4c')](handleError(_0x4d410a,null));};exports['create']=function(_0x4da6e7,_0x1009f9){return db[_0xf639('0x42')][_0xf639('0x4d')](_0x4da6e7['body'],{})['then'](respondWithResult(_0x1009f9,0xc9))[_0xf639('0x4c')](handleError(_0x1009f9,null));};exports['update']=function(_0x3d280c,_0x468cb6){if(_0x3d280c[_0xf639('0x4e')]['id']){delete _0x3d280c[_0xf639('0x4e')]['id'];}return db[_0xf639('0x42')][_0xf639('0x4b')]({'where':{'id':_0x3d280c['params']['id']}})['then'](handleEntityNotFound(_0x468cb6,null))[_0xf639('0x29')](saveUpdates(_0x3d280c['body'],null))[_0xf639('0x29')](respondWithResult(_0x468cb6,null))[_0xf639('0x4c')](handleError(_0x468cb6,null));};exports[_0xf639('0x2a')]=function(_0xdf1eb2,_0x5771a2){return db[_0xf639('0x42')][_0xf639('0x4b')]({'where':{'id':_0xdf1eb2[_0xf639('0x48')]['id']}})['then'](handleEntityNotFound(_0x5771a2,null))[_0xf639('0x29')](removeEntity(_0x5771a2,null))[_0xf639('0x4c')](handleError(_0x5771a2,null));};exports['describe']=function(_0x3638ff,_0xede676){return db[_0xf639('0x42')][_0xf639('0x4f')]()[_0xf639('0x29')](respondWithResult(_0xede676,null))[_0xf639('0x4c')](handleError(_0xede676,null));};