dee7d01c0a0186f1846f49ed7ae98b9846011f06
[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 _0x955f=['set','Content-Range','apply','reject','save','update','destroy','then','sendStatus','stack','name','send','index','map','SmsApplication','fieldName','key','model','keys','filters','intersection','query','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','pick','where','merge','type','VIRTUAL','filter','options','includeAll','include','rows','catch','show','params','rawAttributes','find','create','body','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','util','sox','to-csv','ejs','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','status','end','json','count','offset'];(function(_0x4d2bb8,_0x41c106){var _0x105516=function(_0x165027){while(--_0x165027){_0x4d2bb8['push'](_0x4d2bb8['shift']());}};_0x105516(++_0x41c106);}(_0x955f,0x1eb));var _0xf955=function(_0x3d36e2,_0x53a129){_0x3d36e2=_0x3d36e2-0x0;var _0x1a9b40=_0x955f[_0x3d36e2];return _0x1a9b40;};'use strict';var pdf=require(_0xf955('0x0'));var emlformat=require(_0xf955('0x1'));var rimraf=require(_0xf955('0x2'));var zipdir=require(_0xf955('0x3'));var jsonpatch=require(_0xf955('0x4'));var rp=require('request-promise');var moment=require(_0xf955('0x5'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xf955('0x6'));var path=require('path');var sox=require(_0xf955('0x7'));var csv=require(_0xf955('0x8'));var ejs=require(_0xf955('0x9'));var fs=require('fs');var _=require('lodash');var squel=require(_0xf955('0xa'));var crypto=require(_0xf955('0xb'));var jsforce=require('jsforce');var deskjs=require(_0xf955('0xc'));var toCsv=require(_0xf955('0x8'));var querystring=require(_0xf955('0xd'));var Papa=require(_0xf955('0xe'));var Redis=require(_0xf955('0xf'));var authService=require(_0xf955('0x10'));var qs=require(_0xf955('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf955('0x12'));var logger=require('../../config/logger')(_0xf955('0x13'));var utils=require(_0xf955('0x14'));var config=require(_0xf955('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x2f61b8,_0x542347){_0x542347=_0x542347||0xcc;return function(_0x23e0c6){if(_0x23e0c6){return _0x2f61b8['sendStatus'](_0x542347);}return _0x2f61b8[_0xf955('0x16')](_0x542347)[_0xf955('0x17')]();};}function respondWithResult(_0x22507a,_0x109bc5){_0x109bc5=_0x109bc5||0xc8;return function(_0x2080c4){if(_0x2080c4){return _0x22507a[_0xf955('0x16')](_0x109bc5)[_0xf955('0x18')](_0x2080c4);}};}function respondWithFilteredResult(_0x2783f2,_0x3c6af7){return function(_0x24e75c){if(_0x24e75c){var _0x5350e4=_0x24e75c[_0xf955('0x19')],_0xc29b35=_0x3c6af7[_0xf955('0x1a')],_0x54e60b=_0x3c6af7[_0xf955('0x1a')]+_0x3c6af7['limit'],_0x3139d5;if(_0x54e60b>=_0x5350e4){_0x54e60b=_0x5350e4;_0x3139d5=0xc8;}else{_0x3139d5=0xce;}_0x2783f2['status'](_0x3139d5);return _0x2783f2[_0xf955('0x1b')](_0xf955('0x1c'),_0xc29b35+'-'+_0x54e60b+'/'+_0x5350e4)[_0xf955('0x18')](_0x24e75c);}return null;};}function patchUpdates(_0x4d7b5b){return function(_0xb71daf){try{jsonpatch[_0xf955('0x1d')](_0xb71daf,_0x4d7b5b,!![]);}catch(_0x423824){return BPromise[_0xf955('0x1e')](_0x423824);}return _0xb71daf[_0xf955('0x1f')]();};}function saveUpdates(_0x5f4d9a,_0x17d86a){return function(_0x3dbbe8){if(_0x3dbbe8){return _0x3dbbe8[_0xf955('0x20')](_0x5f4d9a)['then'](function(_0x43a5f2){return _0x43a5f2;});}return null;};}function removeEntity(_0x5daa73,_0x21ae24){return function(_0x43b078){if(_0x43b078){return _0x43b078[_0xf955('0x21')]()[_0xf955('0x22')](function(){_0x5daa73[_0xf955('0x16')](0xcc)['end']();});}};}function handleEntityNotFound(_0x25f4f2,_0x5fab1c){return function(_0x3585c7){if(!_0x3585c7){_0x25f4f2[_0xf955('0x23')](0x194);}return _0x3585c7;};}function handleError(_0x17dec2,_0x102e36){_0x102e36=_0x102e36||0x1f4;return function(_0x1f87f6){logger['error'](_0x1f87f6[_0xf955('0x24')]);if(_0x1f87f6[_0xf955('0x25')]){delete _0x1f87f6[_0xf955('0x25')];}_0x17dec2[_0xf955('0x16')](_0x102e36)[_0xf955('0x26')](_0x1f87f6);};}exports[_0xf955('0x27')]=function(_0x3796f7,_0x51f3ab){var _0x3caea6={},_0x145098={},_0x41c9f6={'count':0x0,'rows':[]};var _0xbd0b74=_[_0xf955('0x28')](db[_0xf955('0x29')]['rawAttributes'],function(_0x2232a7){return{'name':_0x2232a7[_0xf955('0x2a')],'type':_0x2232a7['type'][_0xf955('0x2b')]};});_0x145098[_0xf955('0x2c')]=_[_0xf955('0x28')](_0xbd0b74,_0xf955('0x25'));_0x145098['query']=_[_0xf955('0x2d')](_0x3796f7['query']);_0x145098[_0xf955('0x2e')]=_[_0xf955('0x2f')](_0x145098[_0xf955('0x2c')],_0x145098[_0xf955('0x30')]);_0x3caea6[_0xf955('0x31')]=_[_0xf955('0x2f')](_0x145098[_0xf955('0x2c')],qs[_0xf955('0x32')](_0x3796f7['query'][_0xf955('0x32')]));_0x3caea6[_0xf955('0x31')]=_0x3caea6[_0xf955('0x31')][_0xf955('0x33')]?_0x3caea6['attributes']:_0x145098[_0xf955('0x2c')];if(!_0x3796f7[_0xf955('0x30')][_0xf955('0x34')](_0xf955('0x35'))){_0x3caea6[_0xf955('0x36')]=qs['limit'](_0x3796f7['query']['limit']);_0x3caea6[_0xf955('0x1a')]=qs[_0xf955('0x1a')](_0x3796f7[_0xf955('0x30')][_0xf955('0x1a')]);}_0x3caea6[_0xf955('0x37')]=qs[_0xf955('0x38')](_0x3796f7['query'][_0xf955('0x38')]);_0x3caea6['where']=qs[_0xf955('0x2e')](_[_0xf955('0x39')](_0x3796f7[_0xf955('0x30')],_0x145098['filters']),_0xbd0b74);if(_0x3796f7[_0xf955('0x30')]['filter']){_0x3caea6[_0xf955('0x3a')]=_[_0xf955('0x3b')](_0x3caea6[_0xf955('0x3a')],{'$or':_[_0xf955('0x28')](_0xbd0b74,function(_0x52ab07){if(_0x52ab07[_0xf955('0x3c')]!==_0xf955('0x3d')){var _0x5a48be={};_0x5a48be[_0x52ab07[_0xf955('0x25')]]={'$like':'%'+_0x3796f7[_0xf955('0x30')][_0xf955('0x3e')]+'%'};return _0x5a48be;}})});}_0x3caea6=_['merge']({},_0x3caea6,_0x3796f7[_0xf955('0x3f')]);var _0xffe510={'where':_0x3caea6[_0xf955('0x3a')]};return db['SmsApplication'][_0xf955('0x19')](_0xffe510)[_0xf955('0x22')](function(_0x21e4a6){_0x41c9f6[_0xf955('0x19')]=_0x21e4a6;if(_0x3796f7[_0xf955('0x30')][_0xf955('0x40')]){_0x3caea6[_0xf955('0x41')]=[{'all':!![]}];}return db[_0xf955('0x29')]['findAll'](_0x3caea6);})[_0xf955('0x22')](function(_0x7123c1){_0x41c9f6[_0xf955('0x42')]=_0x7123c1;return _0x41c9f6;})[_0xf955('0x22')](respondWithFilteredResult(_0x51f3ab,_0x3caea6))[_0xf955('0x43')](handleError(_0x51f3ab,null));};exports[_0xf955('0x44')]=function(_0x43ab74,_0x206651){var _0x47651b={'raw':!![],'where':{'id':_0x43ab74[_0xf955('0x45')]['id']}},_0x238a68={};_0x238a68[_0xf955('0x2c')]=_[_0xf955('0x2d')](db[_0xf955('0x29')][_0xf955('0x46')]);_0x238a68[_0xf955('0x30')]=_[_0xf955('0x2d')](_0x43ab74[_0xf955('0x30')]);_0x238a68[_0xf955('0x2e')]=_['intersection'](_0x238a68[_0xf955('0x2c')],_0x238a68[_0xf955('0x30')]);_0x47651b[_0xf955('0x31')]=_['intersection'](_0x238a68[_0xf955('0x2c')],qs['fields'](_0x43ab74[_0xf955('0x30')]['fields']));_0x47651b[_0xf955('0x31')]=_0x47651b[_0xf955('0x31')][_0xf955('0x33')]?_0x47651b[_0xf955('0x31')]:_0x238a68['model'];if(_0x43ab74[_0xf955('0x30')][_0xf955('0x40')]){_0x47651b[_0xf955('0x41')]=[{'all':!![]}];}_0x47651b=_['merge']({},_0x47651b,_0x43ab74['options']);return db[_0xf955('0x29')][_0xf955('0x47')](_0x47651b)[_0xf955('0x22')](handleEntityNotFound(_0x206651,null))[_0xf955('0x22')](respondWithResult(_0x206651,null))['catch'](handleError(_0x206651,null));};exports[_0xf955('0x48')]=function(_0x152f57,_0x1ced36){return db['SmsApplication'][_0xf955('0x48')](_0x152f57['body'],{})[_0xf955('0x22')](respondWithResult(_0x1ced36,0xc9))[_0xf955('0x43')](handleError(_0x1ced36,null));};exports[_0xf955('0x20')]=function(_0x4dd592,_0x3e24c9){if(_0x4dd592[_0xf955('0x49')]['id']){delete _0x4dd592[_0xf955('0x49')]['id'];}return db[_0xf955('0x29')]['find']({'where':{'id':_0x4dd592[_0xf955('0x45')]['id']}})[_0xf955('0x22')](handleEntityNotFound(_0x3e24c9,null))[_0xf955('0x22')](saveUpdates(_0x4dd592[_0xf955('0x49')],null))[_0xf955('0x22')](respondWithResult(_0x3e24c9,null))['catch'](handleError(_0x3e24c9,null));};exports[_0xf955('0x21')]=function(_0x4e7269,_0x35c23c){return db['SmsApplication'][_0xf955('0x47')]({'where':{'id':_0x4e7269['params']['id']}})['then'](handleEntityNotFound(_0x35c23c,null))[_0xf955('0x22')](removeEntity(_0x35c23c,null))[_0xf955('0x43')](handleError(_0x35c23c,null));};