790a3e897bed9c8e773edcc8c9a80cf15324f560
[motion2.git] / server / api / smsTransferReport / smsTransferReport.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 _0xbf30=['rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','map','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','find','create','body','describe','eml-format','rimraf','request-promise','moment','bluebird','mustache','util','ejs','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','end','json','offset','undefined','count','limit','status','set','Content-Range','apply','save','update','then','destroy','sendStatus','error','name','index','SmsTransferReport'];(function(_0x2e1c21,_0x3873fc){var _0x35cfc7=function(_0x43722e){while(--_0x43722e){_0x2e1c21['push'](_0x2e1c21['shift']());}};_0x35cfc7(++_0x3873fc);}(_0xbf30,0x1de));var _0x0bf3=function(_0x25210a,_0xfdda84){_0x25210a=_0x25210a-0x0;var _0x4c1bd9=_0xbf30[_0x25210a];return _0x4c1bd9;};'use strict';var emlformat=require(_0x0bf3('0x0'));var rimraf=require(_0x0bf3('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x0bf3('0x2'));var moment=require(_0x0bf3('0x3'));var BPromise=require(_0x0bf3('0x4'));var Mustache=require(_0x0bf3('0x5'));var util=require(_0x0bf3('0x6'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x0bf3('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x0bf3('0x8'));var crypto=require(_0x0bf3('0x9'));var jsforce=require('jsforce');var deskjs=require(_0x0bf3('0xa'));var toCsv=require('to-csv');var querystring=require(_0x0bf3('0xb'));var Papa=require(_0x0bf3('0xc'));var Redis=require(_0x0bf3('0xd'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x0bf3('0xe'));var hardwareService=require(_0x0bf3('0xf'));var logger=require(_0x0bf3('0x10'))(_0x0bf3('0x11'));var utils=require(_0x0bf3('0x12'));var config=require(_0x0bf3('0x13'));var licenseUtil=require(_0x0bf3('0x14'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1e7db3,_0x1af62a){_0x1af62a=_0x1af62a||0xcc;return function(_0x172e72){if(_0x172e72){return _0x1e7db3['sendStatus'](_0x1af62a);}return _0x1e7db3['status'](_0x1af62a)[_0x0bf3('0x15')]();};}function respondWithResult(_0x22ce05,_0x5d0cf3){_0x5d0cf3=_0x5d0cf3||0xc8;return function(_0xe723b4){if(_0xe723b4){return _0x22ce05['status'](_0x5d0cf3)[_0x0bf3('0x16')](_0xe723b4);}};}function respondWithFilteredResult(_0x1ca19c,_0x2e7a9b){return function(_0xce254d){if(_0xce254d){var _0x11e380=typeof _0x2e7a9b[_0x0bf3('0x17')]===_0x0bf3('0x18')&&typeof _0x2e7a9b['limit']===_0x0bf3('0x18');var _0xd5f018=_0xce254d[_0x0bf3('0x19')];var _0x25a1fb=_0x11e380?0x0:_0x2e7a9b['offset'];var _0x1e761d=_0x11e380?_0xce254d['count']:_0x2e7a9b[_0x0bf3('0x17')]+_0x2e7a9b[_0x0bf3('0x1a')];var _0x37e9b4;if(_0x1e761d>=_0xd5f018){_0x1e761d=_0xd5f018;_0x37e9b4=0xc8;}else{_0x37e9b4=0xce;}_0x1ca19c[_0x0bf3('0x1b')](_0x37e9b4);return _0x1ca19c[_0x0bf3('0x1c')](_0x0bf3('0x1d'),_0x25a1fb+'-'+_0x1e761d+'/'+_0xd5f018)[_0x0bf3('0x16')](_0xce254d);}return null;};}function patchUpdates(_0x4eaa04){return function(_0x4c4ff8){try{jsonpatch[_0x0bf3('0x1e')](_0x4c4ff8,_0x4eaa04,!![]);}catch(_0x3bc916){return BPromise['reject'](_0x3bc916);}return _0x4c4ff8[_0x0bf3('0x1f')]();};}function saveUpdates(_0x4d706d,_0x21cacf){return function(_0x28bfc6){if(_0x28bfc6){return _0x28bfc6[_0x0bf3('0x20')](_0x4d706d)[_0x0bf3('0x21')](function(_0x23a967){return _0x23a967;});}return null;};}function removeEntity(_0x2f89f7,_0x44fb1d){return function(_0x14c950){if(_0x14c950){return _0x14c950[_0x0bf3('0x22')]()[_0x0bf3('0x21')](function(){_0x2f89f7[_0x0bf3('0x1b')](0xcc)[_0x0bf3('0x15')]();});}};}function handleEntityNotFound(_0x5369a8,_0x4fe233){return function(_0x544920){if(!_0x544920){_0x5369a8[_0x0bf3('0x23')](0x194);}return _0x544920;};}function handleError(_0x161c5b,_0x3baa04){_0x3baa04=_0x3baa04||0x1f4;return function(_0x4d631f){logger[_0x0bf3('0x24')](_0x4d631f['stack']);if(_0x4d631f[_0x0bf3('0x25')]){delete _0x4d631f[_0x0bf3('0x25')];}_0x161c5b['status'](_0x3baa04)['send'](_0x4d631f);};}exports[_0x0bf3('0x26')]=function(_0x4f5793,_0x40706e){var _0x14b0ce={},_0x2a235c={},_0x1c7a7e={'count':0x0,'rows':[]};var _0x3881b9=_['map'](db[_0x0bf3('0x27')][_0x0bf3('0x28')],function(_0x2e04ff){return{'name':_0x2e04ff[_0x0bf3('0x29')],'type':_0x2e04ff[_0x0bf3('0x2a')][_0x0bf3('0x2b')]};});_0x2a235c[_0x0bf3('0x2c')]=_['map'](_0x3881b9,'name');_0x2a235c[_0x0bf3('0x2d')]=_[_0x0bf3('0x2e')](_0x4f5793[_0x0bf3('0x2d')]);_0x2a235c[_0x0bf3('0x2f')]=_[_0x0bf3('0x30')](_0x2a235c[_0x0bf3('0x2c')],_0x2a235c[_0x0bf3('0x2d')]);_0x14b0ce[_0x0bf3('0x31')]=_[_0x0bf3('0x30')](_0x2a235c[_0x0bf3('0x2c')],qs[_0x0bf3('0x32')](_0x4f5793[_0x0bf3('0x2d')][_0x0bf3('0x32')]));_0x14b0ce[_0x0bf3('0x31')]=_0x14b0ce['attributes'][_0x0bf3('0x33')]?_0x14b0ce['attributes']:_0x2a235c[_0x0bf3('0x2c')];if(!_0x4f5793[_0x0bf3('0x2d')][_0x0bf3('0x34')](_0x0bf3('0x35'))){_0x14b0ce[_0x0bf3('0x1a')]=qs[_0x0bf3('0x1a')](_0x4f5793[_0x0bf3('0x2d')]['limit']);_0x14b0ce['offset']=qs[_0x0bf3('0x17')](_0x4f5793[_0x0bf3('0x2d')][_0x0bf3('0x17')]);}_0x14b0ce[_0x0bf3('0x36')]=qs[_0x0bf3('0x37')](_0x4f5793[_0x0bf3('0x2d')][_0x0bf3('0x37')]);_0x14b0ce['where']=qs[_0x0bf3('0x2f')](_[_0x0bf3('0x38')](_0x4f5793[_0x0bf3('0x2d')],_0x2a235c[_0x0bf3('0x2f')]),_0x3881b9);if(_0x4f5793['query'][_0x0bf3('0x39')]){_0x14b0ce[_0x0bf3('0x3a')]=_[_0x0bf3('0x3b')](_0x14b0ce[_0x0bf3('0x3a')],{'$or':_[_0x0bf3('0x3c')](_0x3881b9,function(_0x2bf6d1){if(_0x2bf6d1[_0x0bf3('0x2a')]!==_0x0bf3('0x3d')){var _0x4a69ea={};_0x4a69ea[_0x2bf6d1[_0x0bf3('0x25')]]={'$like':'%'+_0x4f5793[_0x0bf3('0x2d')][_0x0bf3('0x39')]+'%'};return _0x4a69ea;}})});}_0x14b0ce=_[_0x0bf3('0x3b')]({},_0x14b0ce,_0x4f5793[_0x0bf3('0x3e')]);var _0x1c2f9b={'where':_0x14b0ce[_0x0bf3('0x3a')]};return db[_0x0bf3('0x27')][_0x0bf3('0x19')](_0x1c2f9b)[_0x0bf3('0x21')](function(_0x311082){_0x1c7a7e[_0x0bf3('0x19')]=_0x311082;if(_0x4f5793[_0x0bf3('0x2d')][_0x0bf3('0x3f')]){_0x14b0ce[_0x0bf3('0x40')]=[{'all':!![]}];}return db[_0x0bf3('0x27')][_0x0bf3('0x41')](_0x14b0ce);})['then'](function(_0x28c879){_0x1c7a7e[_0x0bf3('0x42')]=_0x28c879;return _0x1c7a7e;})[_0x0bf3('0x21')](respondWithFilteredResult(_0x40706e,_0x14b0ce))[_0x0bf3('0x43')](handleError(_0x40706e,null));};exports[_0x0bf3('0x44')]=function(_0x309798,_0x271aad){var _0x48d8bf={'raw':!![],'where':{'id':_0x309798[_0x0bf3('0x45')]['id']}},_0x424813={};_0x424813[_0x0bf3('0x2c')]=_['keys'](db[_0x0bf3('0x27')][_0x0bf3('0x28')]);_0x424813[_0x0bf3('0x2d')]=_['keys'](_0x309798[_0x0bf3('0x2d')]);_0x424813[_0x0bf3('0x2f')]=_['intersection'](_0x424813[_0x0bf3('0x2c')],_0x424813[_0x0bf3('0x2d')]);_0x48d8bf[_0x0bf3('0x31')]=_['intersection'](_0x424813[_0x0bf3('0x2c')],qs[_0x0bf3('0x32')](_0x309798[_0x0bf3('0x2d')]['fields']));_0x48d8bf[_0x0bf3('0x31')]=_0x48d8bf[_0x0bf3('0x31')][_0x0bf3('0x33')]?_0x48d8bf['attributes']:_0x424813[_0x0bf3('0x2c')];if(_0x309798['query'][_0x0bf3('0x3f')]){_0x48d8bf[_0x0bf3('0x40')]=[{'all':!![]}];}_0x48d8bf=_['merge']({},_0x48d8bf,_0x309798[_0x0bf3('0x3e')]);return db[_0x0bf3('0x27')][_0x0bf3('0x46')](_0x48d8bf)[_0x0bf3('0x21')](handleEntityNotFound(_0x271aad,null))[_0x0bf3('0x21')](respondWithResult(_0x271aad,null))[_0x0bf3('0x43')](handleError(_0x271aad,null));};exports[_0x0bf3('0x47')]=function(_0x5cb8c7,_0xdfd79c){return db[_0x0bf3('0x27')][_0x0bf3('0x47')](_0x5cb8c7[_0x0bf3('0x48')],{})[_0x0bf3('0x21')](respondWithResult(_0xdfd79c,0xc9))[_0x0bf3('0x43')](handleError(_0xdfd79c,null));};exports[_0x0bf3('0x20')]=function(_0x27d32e,_0x7fabaf){if(_0x27d32e['body']['id']){delete _0x27d32e[_0x0bf3('0x48')]['id'];}return db['SmsTransferReport'][_0x0bf3('0x46')]({'where':{'id':_0x27d32e[_0x0bf3('0x45')]['id']}})[_0x0bf3('0x21')](handleEntityNotFound(_0x7fabaf,null))[_0x0bf3('0x21')](saveUpdates(_0x27d32e[_0x0bf3('0x48')],null))[_0x0bf3('0x21')](respondWithResult(_0x7fabaf,null))[_0x0bf3('0x43')](handleError(_0x7fabaf,null));};exports[_0x0bf3('0x22')]=function(_0x15f34b,_0x241172){return db[_0x0bf3('0x27')]['find']({'where':{'id':_0x15f34b[_0x0bf3('0x45')]['id']}})[_0x0bf3('0x21')](handleEntityNotFound(_0x241172,null))[_0x0bf3('0x21')](removeEntity(_0x241172,null))[_0x0bf3('0x43')](handleError(_0x241172,null));};exports[_0x0bf3('0x49')]=function(_0x3dbb57,_0x12c840){return db[_0x0bf3('0x27')][_0x0bf3('0x49')]()[_0x0bf3('0x21')](respondWithResult(_0x12c840,null))[_0x0bf3('0x43')](handleError(_0x12c840,null));};