bc87a6071cb657d139217267e5e89ea733bb80ea
[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 _0xeb5e=['crypto','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','status','end','offset','undefined','limit','count','set','Content-Range','json','apply','reject','save','update','destroy','sendStatus','stack','name','index','map','SmsApplication','rawAttributes','fieldName','type','model','keys','filters','intersection','query','fields','attributes','length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','then','catch','body','params','eml-format','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','to-csv','fs-extra','lodash'];(function(_0x11261c,_0x50eca9){var _0x4590b7=function(_0x38536a){while(--_0x38536a){_0x11261c['push'](_0x11261c['shift']());}};_0x4590b7(++_0x50eca9);}(_0xeb5e,0x101));var _0xeeb5=function(_0x59c301,_0x359c50){_0x59c301=_0x59c301-0x0;var _0x3866b9=_0xeb5e[_0x59c301];return _0x3866b9;};'use strict';var emlformat=require(_0xeeb5('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xeeb5('0x1'));var jsonpatch=require(_0xeeb5('0x2'));var rp=require(_0xeeb5('0x3'));var moment=require(_0xeeb5('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xeeb5('0x5'));var util=require(_0xeeb5('0x6'));var path=require(_0xeeb5('0x7'));var sox=require('sox');var csv=require(_0xeeb5('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xeeb5('0x9'));var _=require(_0xeeb5('0xa'));var squel=require('squel');var crypto=require(_0xeeb5('0xb'));var jsforce=require(_0xeeb5('0xc'));var deskjs=require(_0xeeb5('0xd'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xeeb5('0xe'));var Redis=require('ioredis');var authService=require(_0xeeb5('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xeeb5('0x10'));var hardwareService=require(_0xeeb5('0x11'));var logger=require('../../config/logger')(_0xeeb5('0x12'));var utils=require('../../config/utils');var config=require(_0xeeb5('0x13'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x4bcc24,_0x6c1052){_0x6c1052=_0x6c1052||0xcc;return function(_0x196210){if(_0x196210){return _0x4bcc24['sendStatus'](_0x6c1052);}return _0x4bcc24[_0xeeb5('0x14')](_0x6c1052)[_0xeeb5('0x15')]();};}function respondWithResult(_0x1bd2a4,_0x1d9e96){_0x1d9e96=_0x1d9e96||0xc8;return function(_0x16f52e){if(_0x16f52e){return _0x1bd2a4[_0xeeb5('0x14')](_0x1d9e96)['json'](_0x16f52e);}};}function respondWithFilteredResult(_0x5ddbc5,_0x16dd6e){return function(_0xb29eae){if(_0xb29eae){var _0x295da2=typeof _0x16dd6e[_0xeeb5('0x16')]===_0xeeb5('0x17')&&typeof _0x16dd6e[_0xeeb5('0x18')]===_0xeeb5('0x17');var _0x2c863c=_0xb29eae['count'];var _0x31ad05=_0x295da2?0x0:_0x16dd6e[_0xeeb5('0x16')];var _0x260f1e=_0x295da2?_0xb29eae[_0xeeb5('0x19')]:_0x16dd6e[_0xeeb5('0x16')]+_0x16dd6e[_0xeeb5('0x18')];var _0xa5f12d;if(_0x260f1e>=_0x2c863c){_0x260f1e=_0x2c863c;_0xa5f12d=0xc8;}else{_0xa5f12d=0xce;}_0x5ddbc5[_0xeeb5('0x14')](_0xa5f12d);return _0x5ddbc5[_0xeeb5('0x1a')](_0xeeb5('0x1b'),_0x31ad05+'-'+_0x260f1e+'/'+_0x2c863c)[_0xeeb5('0x1c')](_0xb29eae);}return null;};}function patchUpdates(_0x38730b){return function(_0x2de9ec){try{jsonpatch[_0xeeb5('0x1d')](_0x2de9ec,_0x38730b,!![]);}catch(_0x30e779){return BPromise[_0xeeb5('0x1e')](_0x30e779);}return _0x2de9ec[_0xeeb5('0x1f')]();};}function saveUpdates(_0x4b1a11,_0x4b6735){return function(_0x2c76fa){if(_0x2c76fa){return _0x2c76fa[_0xeeb5('0x20')](_0x4b1a11)['then'](function(_0xc64bc2){return _0xc64bc2;});}return null;};}function removeEntity(_0x4fbbfa,_0x7b0e76){return function(_0x35d670){if(_0x35d670){return _0x35d670[_0xeeb5('0x21')]()['then'](function(){_0x4fbbfa[_0xeeb5('0x14')](0xcc)[_0xeeb5('0x15')]();});}};}function handleEntityNotFound(_0x52f17e,_0xa9fe67){return function(_0x1680e9){if(!_0x1680e9){_0x52f17e[_0xeeb5('0x22')](0x194);}return _0x1680e9;};}function handleError(_0x3b7782,_0x3f6a26){_0x3f6a26=_0x3f6a26||0x1f4;return function(_0x33a988){logger['error'](_0x33a988[_0xeeb5('0x23')]);if(_0x33a988['name']){delete _0x33a988[_0xeeb5('0x24')];}_0x3b7782[_0xeeb5('0x14')](_0x3f6a26)['send'](_0x33a988);};}exports[_0xeeb5('0x25')]=function(_0xf629e,_0x5466cd){var _0x247458={},_0x534583={},_0x121b9e={'count':0x0,'rows':[]};var _0x499802=_[_0xeeb5('0x26')](db[_0xeeb5('0x27')][_0xeeb5('0x28')],function(_0x551d4c){return{'name':_0x551d4c[_0xeeb5('0x29')],'type':_0x551d4c[_0xeeb5('0x2a')]['key']};});_0x534583[_0xeeb5('0x2b')]=_[_0xeeb5('0x26')](_0x499802,_0xeeb5('0x24'));_0x534583['query']=_[_0xeeb5('0x2c')](_0xf629e['query']);_0x534583[_0xeeb5('0x2d')]=_[_0xeeb5('0x2e')](_0x534583[_0xeeb5('0x2b')],_0x534583[_0xeeb5('0x2f')]);_0x247458['attributes']=_[_0xeeb5('0x2e')](_0x534583[_0xeeb5('0x2b')],qs[_0xeeb5('0x30')](_0xf629e[_0xeeb5('0x2f')][_0xeeb5('0x30')]));_0x247458['attributes']=_0x247458[_0xeeb5('0x31')][_0xeeb5('0x32')]?_0x247458[_0xeeb5('0x31')]:_0x534583[_0xeeb5('0x2b')];if(!_0xf629e['query']['hasOwnProperty'](_0xeeb5('0x33'))){_0x247458[_0xeeb5('0x18')]=qs['limit'](_0xf629e['query']['limit']);_0x247458[_0xeeb5('0x16')]=qs[_0xeeb5('0x16')](_0xf629e['query'][_0xeeb5('0x16')]);}_0x247458[_0xeeb5('0x34')]=qs[_0xeeb5('0x35')](_0xf629e[_0xeeb5('0x2f')][_0xeeb5('0x35')]);_0x247458[_0xeeb5('0x36')]=qs[_0xeeb5('0x2d')](_[_0xeeb5('0x37')](_0xf629e[_0xeeb5('0x2f')],_0x534583[_0xeeb5('0x2d')]),_0x499802);if(_0xf629e['query'][_0xeeb5('0x38')]){_0x247458[_0xeeb5('0x36')]=_[_0xeeb5('0x39')](_0x247458[_0xeeb5('0x36')],{'$or':_[_0xeeb5('0x26')](_0x499802,function(_0x7244cd){if(_0x7244cd[_0xeeb5('0x2a')]!==_0xeeb5('0x3a')){var _0x49ea5f={};_0x49ea5f[_0x7244cd[_0xeeb5('0x24')]]={'$like':'%'+_0xf629e[_0xeeb5('0x2f')][_0xeeb5('0x38')]+'%'};return _0x49ea5f;}})});}_0x247458=_['merge']({},_0x247458,_0xf629e[_0xeeb5('0x3b')]);var _0x7faebb={'where':_0x247458[_0xeeb5('0x36')]};return db[_0xeeb5('0x27')][_0xeeb5('0x19')](_0x7faebb)['then'](function(_0x51bf56){_0x121b9e[_0xeeb5('0x19')]=_0x51bf56;if(_0xf629e[_0xeeb5('0x2f')][_0xeeb5('0x3c')]){_0x247458[_0xeeb5('0x3d')]=[{'all':!![]}];}return db['SmsApplication'][_0xeeb5('0x3e')](_0x247458);})[_0xeeb5('0x3f')](function(_0x41d1cb){_0x121b9e['rows']=_0x41d1cb;return _0x121b9e;})[_0xeeb5('0x3f')](respondWithFilteredResult(_0x5466cd,_0x247458))[_0xeeb5('0x40')](handleError(_0x5466cd,null));};exports['show']=function(_0x1f3420,_0x4db2ce){var _0x30f401={'raw':!![],'where':{'id':_0x1f3420['params']['id']}},_0x434978={};_0x434978['model']=_[_0xeeb5('0x2c')](db[_0xeeb5('0x27')][_0xeeb5('0x28')]);_0x434978[_0xeeb5('0x2f')]=_[_0xeeb5('0x2c')](_0x1f3420['query']);_0x434978[_0xeeb5('0x2d')]=_['intersection'](_0x434978[_0xeeb5('0x2b')],_0x434978[_0xeeb5('0x2f')]);_0x30f401[_0xeeb5('0x31')]=_['intersection'](_0x434978[_0xeeb5('0x2b')],qs[_0xeeb5('0x30')](_0x1f3420[_0xeeb5('0x2f')][_0xeeb5('0x30')]));_0x30f401[_0xeeb5('0x31')]=_0x30f401[_0xeeb5('0x31')][_0xeeb5('0x32')]?_0x30f401[_0xeeb5('0x31')]:_0x434978[_0xeeb5('0x2b')];if(_0x1f3420['query']['includeAll']){_0x30f401['include']=[{'all':!![]}];}_0x30f401=_[_0xeeb5('0x39')]({},_0x30f401,_0x1f3420['options']);return db[_0xeeb5('0x27')]['find'](_0x30f401)[_0xeeb5('0x3f')](handleEntityNotFound(_0x4db2ce,null))[_0xeeb5('0x3f')](respondWithResult(_0x4db2ce,null))['catch'](handleError(_0x4db2ce,null));};exports['create']=function(_0x3c8c15,_0x81a29c){return db[_0xeeb5('0x27')]['create'](_0x3c8c15['body'],{})[_0xeeb5('0x3f')](respondWithResult(_0x81a29c,0xc9))['catch'](handleError(_0x81a29c,null));};exports[_0xeeb5('0x20')]=function(_0x5c6bce,_0x88342d){if(_0x5c6bce['body']['id']){delete _0x5c6bce[_0xeeb5('0x41')]['id'];}return db[_0xeeb5('0x27')]['find']({'where':{'id':_0x5c6bce['params']['id']}})[_0xeeb5('0x3f')](handleEntityNotFound(_0x88342d,null))['then'](saveUpdates(_0x5c6bce['body'],null))[_0xeeb5('0x3f')](respondWithResult(_0x88342d,null))[_0xeeb5('0x40')](handleError(_0x88342d,null));};exports[_0xeeb5('0x21')]=function(_0x4caea1,_0x381f3a){return db[_0xeeb5('0x27')]['find']({'where':{'id':_0x4caea1[_0xeeb5('0x42')]['id']}})['then'](handleEntityNotFound(_0x381f3a,null))[_0xeeb5('0x3f')](removeEntity(_0x381f3a,null))[_0xeeb5('0x40')](handleError(_0x381f3a,null));};