Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / smsApplication / smsApplication.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 _0x6e96=['send','SmsApplication','rawAttributes','fieldName','model','query','intersection','fields','attributes','length','nolimit','order','sort','where','filters','pick','filter','merge','map','type','VIRTUAL','options','includeAll','rows','catch','show','params','keys','include','find','create','body','update','destroy','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','undefined','limit','count','set','json','apply','reject','save','then','error','stack','name'];(function(_0x3a886b,_0x24db41){var _0x4c54f6=function(_0xe20f1a){while(--_0xe20f1a){_0x3a886b['push'](_0x3a886b['shift']());}};_0x4c54f6(++_0x24db41);}(_0x6e96,0x18f));var _0x66e9=function(_0x3e8332,_0x2faae2){_0x3e8332=_0x3e8332-0x0;var _0x1ec952=_0x6e96[_0x3e8332];return _0x1ec952;};'use strict';var emlformat=require(_0x66e9('0x0'));var rimraf=require(_0x66e9('0x1'));var zipdir=require(_0x66e9('0x2'));var jsonpatch=require(_0x66e9('0x3'));var rp=require(_0x66e9('0x4'));var moment=require(_0x66e9('0x5'));var BPromise=require(_0x66e9('0x6'));var Mustache=require('mustache');var util=require(_0x66e9('0x7'));var path=require(_0x66e9('0x8'));var sox=require(_0x66e9('0x9'));var csv=require(_0x66e9('0xa'));var ejs=require(_0x66e9('0xb'));var fs=require('fs');var fs_extra=require(_0x66e9('0xc'));var _=require(_0x66e9('0xd'));var squel=require('squel');var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x66e9('0xa'));var querystring=require(_0x66e9('0xe'));var Papa=require(_0x66e9('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x66e9('0x10'));var as=require(_0x66e9('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x66e9('0x12'));var utils=require(_0x66e9('0x13'));var config=require(_0x66e9('0x14'));var licenseUtil=require(_0x66e9('0x15'));var db=require(_0x66e9('0x16'))['db'];function respondWithStatusCode(_0x14821b,_0x282ded){_0x282ded=_0x282ded||0xcc;return function(_0xd1ef8b){if(_0xd1ef8b){return _0x14821b[_0x66e9('0x17')](_0x282ded);}return _0x14821b[_0x66e9('0x18')](_0x282ded)[_0x66e9('0x19')]();};}function respondWithResult(_0x3f109f,_0x3fc333){_0x3fc333=_0x3fc333||0xc8;return function(_0x5d701c){if(_0x5d701c){return _0x3f109f[_0x66e9('0x18')](_0x3fc333)['json'](_0x5d701c);}};}function respondWithFilteredResult(_0x53a5fc,_0x3a005b){return function(_0x105fea){if(_0x105fea){var _0xcf016a=typeof _0x3a005b[_0x66e9('0x1a')]===_0x66e9('0x1b')&&typeof _0x3a005b[_0x66e9('0x1c')]===_0x66e9('0x1b');var _0x12ae8a=_0x105fea['count'];var _0x2167d9=_0xcf016a?0x0:_0x3a005b['offset'];var _0x1f7f9b=_0xcf016a?_0x105fea[_0x66e9('0x1d')]:_0x3a005b['offset']+_0x3a005b[_0x66e9('0x1c')];var _0x1380eb;if(_0x1f7f9b>=_0x12ae8a){_0x1f7f9b=_0x12ae8a;_0x1380eb=0xc8;}else{_0x1380eb=0xce;}_0x53a5fc[_0x66e9('0x18')](_0x1380eb);return _0x53a5fc[_0x66e9('0x1e')]('Content-Range',_0x2167d9+'-'+_0x1f7f9b+'/'+_0x12ae8a)[_0x66e9('0x1f')](_0x105fea);}return null;};}function patchUpdates(_0x48e11c){return function(_0x1965c5){try{jsonpatch[_0x66e9('0x20')](_0x1965c5,_0x48e11c,!![]);}catch(_0xe400cc){return BPromise[_0x66e9('0x21')](_0xe400cc);}return _0x1965c5[_0x66e9('0x22')]();};}function saveUpdates(_0x3ddedd,_0x17e5a2){return function(_0x563adf){if(_0x563adf){return _0x563adf['update'](_0x3ddedd)[_0x66e9('0x23')](function(_0x347575){return _0x347575;});}return null;};}function removeEntity(_0x101e42,_0x4031ec){return function(_0x532d8b){if(_0x532d8b){return _0x532d8b['destroy']()[_0x66e9('0x23')](function(){_0x101e42[_0x66e9('0x18')](0xcc)[_0x66e9('0x19')]();});}};}function handleEntityNotFound(_0x114040,_0x39ec8a){return function(_0x43978f){if(!_0x43978f){_0x114040[_0x66e9('0x17')](0x194);}return _0x43978f;};}function handleError(_0x4e3c54,_0xf395d){_0xf395d=_0xf395d||0x1f4;return function(_0x55a055){logger[_0x66e9('0x24')](_0x55a055[_0x66e9('0x25')]);if(_0x55a055[_0x66e9('0x26')]){delete _0x55a055['name'];}_0x4e3c54[_0x66e9('0x18')](_0xf395d)[_0x66e9('0x27')](_0x55a055);};}exports['index']=function(_0x4339db,_0x165fba){var _0x4ae7e8={},_0x171704={},_0x5a4ab3={'count':0x0,'rows':[]};var _0x23343f=_['map'](db[_0x66e9('0x28')][_0x66e9('0x29')],function(_0x14dc78){return{'name':_0x14dc78[_0x66e9('0x2a')],'type':_0x14dc78['type']['key']};});_0x171704[_0x66e9('0x2b')]=_['map'](_0x23343f,_0x66e9('0x26'));_0x171704[_0x66e9('0x2c')]=_['keys'](_0x4339db[_0x66e9('0x2c')]);_0x171704['filters']=_[_0x66e9('0x2d')](_0x171704[_0x66e9('0x2b')],_0x171704[_0x66e9('0x2c')]);_0x4ae7e8['attributes']=_['intersection'](_0x171704[_0x66e9('0x2b')],qs[_0x66e9('0x2e')](_0x4339db[_0x66e9('0x2c')]['fields']));_0x4ae7e8[_0x66e9('0x2f')]=_0x4ae7e8[_0x66e9('0x2f')][_0x66e9('0x30')]?_0x4ae7e8[_0x66e9('0x2f')]:_0x171704[_0x66e9('0x2b')];if(!_0x4339db[_0x66e9('0x2c')]['hasOwnProperty'](_0x66e9('0x31'))){_0x4ae7e8[_0x66e9('0x1c')]=qs[_0x66e9('0x1c')](_0x4339db['query'][_0x66e9('0x1c')]);_0x4ae7e8['offset']=qs[_0x66e9('0x1a')](_0x4339db[_0x66e9('0x2c')][_0x66e9('0x1a')]);}_0x4ae7e8[_0x66e9('0x32')]=qs[_0x66e9('0x33')](_0x4339db[_0x66e9('0x2c')][_0x66e9('0x33')]);_0x4ae7e8[_0x66e9('0x34')]=qs[_0x66e9('0x35')](_[_0x66e9('0x36')](_0x4339db[_0x66e9('0x2c')],_0x171704[_0x66e9('0x35')]),_0x23343f);if(_0x4339db[_0x66e9('0x2c')][_0x66e9('0x37')]){_0x4ae7e8[_0x66e9('0x34')]=_[_0x66e9('0x38')](_0x4ae7e8[_0x66e9('0x34')],{'$or':_[_0x66e9('0x39')](_0x23343f,function(_0x205912){if(_0x205912[_0x66e9('0x3a')]!==_0x66e9('0x3b')){var _0x1d99db={};_0x1d99db[_0x205912[_0x66e9('0x26')]]={'$like':'%'+_0x4339db[_0x66e9('0x2c')][_0x66e9('0x37')]+'%'};return _0x1d99db;}})});}_0x4ae7e8=_[_0x66e9('0x38')]({},_0x4ae7e8,_0x4339db[_0x66e9('0x3c')]);var _0x368c69={'where':_0x4ae7e8[_0x66e9('0x34')]};return db[_0x66e9('0x28')]['count'](_0x368c69)[_0x66e9('0x23')](function(_0x32b3bb){_0x5a4ab3[_0x66e9('0x1d')]=_0x32b3bb;if(_0x4339db[_0x66e9('0x2c')][_0x66e9('0x3d')]){_0x4ae7e8['include']=[{'all':!![]}];}return db[_0x66e9('0x28')]['findAll'](_0x4ae7e8);})['then'](function(_0x580c34){_0x5a4ab3[_0x66e9('0x3e')]=_0x580c34;return _0x5a4ab3;})[_0x66e9('0x23')](respondWithFilteredResult(_0x165fba,_0x4ae7e8))[_0x66e9('0x3f')](handleError(_0x165fba,null));};exports[_0x66e9('0x40')]=function(_0x37c605,_0xf7cfae){var _0x591b92={'raw':!![],'where':{'id':_0x37c605[_0x66e9('0x41')]['id']}},_0x275aab={};_0x275aab[_0x66e9('0x2b')]=_[_0x66e9('0x42')](db[_0x66e9('0x28')]['rawAttributes']);_0x275aab[_0x66e9('0x2c')]=_[_0x66e9('0x42')](_0x37c605['query']);_0x275aab['filters']=_[_0x66e9('0x2d')](_0x275aab[_0x66e9('0x2b')],_0x275aab['query']);_0x591b92[_0x66e9('0x2f')]=_[_0x66e9('0x2d')](_0x275aab[_0x66e9('0x2b')],qs['fields'](_0x37c605[_0x66e9('0x2c')][_0x66e9('0x2e')]));_0x591b92['attributes']=_0x591b92[_0x66e9('0x2f')][_0x66e9('0x30')]?_0x591b92[_0x66e9('0x2f')]:_0x275aab['model'];if(_0x37c605[_0x66e9('0x2c')][_0x66e9('0x3d')]){_0x591b92[_0x66e9('0x43')]=[{'all':!![]}];}_0x591b92=_[_0x66e9('0x38')]({},_0x591b92,_0x37c605['options']);return db[_0x66e9('0x28')][_0x66e9('0x44')](_0x591b92)['then'](handleEntityNotFound(_0xf7cfae,null))[_0x66e9('0x23')](respondWithResult(_0xf7cfae,null))[_0x66e9('0x3f')](handleError(_0xf7cfae,null));};exports[_0x66e9('0x45')]=function(_0x682244,_0x3de1f6){return db[_0x66e9('0x28')][_0x66e9('0x45')](_0x682244[_0x66e9('0x46')],{})[_0x66e9('0x23')](respondWithResult(_0x3de1f6,0xc9))['catch'](handleError(_0x3de1f6,null));};exports[_0x66e9('0x47')]=function(_0x450038,_0x3c46c7){if(_0x450038[_0x66e9('0x46')]['id']){delete _0x450038['body']['id'];}return db[_0x66e9('0x28')][_0x66e9('0x44')]({'where':{'id':_0x450038[_0x66e9('0x41')]['id']}})['then'](handleEntityNotFound(_0x3c46c7,null))[_0x66e9('0x23')](saveUpdates(_0x450038['body'],null))[_0x66e9('0x23')](respondWithResult(_0x3c46c7,null))['catch'](handleError(_0x3c46c7,null));};exports[_0x66e9('0x48')]=function(_0x57ae64,_0xca74d0){return db[_0x66e9('0x28')]['find']({'where':{'id':_0x57ae64['params']['id']}})['then'](handleEntityNotFound(_0xca74d0,null))[_0x66e9('0x23')](removeEntity(_0xca74d0,null))['catch'](handleError(_0xca74d0,null));};