Built motion from commit 14588770.|2.5.38
[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 _0x3f6b=['sendStatus','status','end','json','offset','limit','undefined','count','set','apply','reject','save','destroy','then','error','stack','name','send','index','map','SmsApplication','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','pick','filter','where','merge','VIRTUAL','options','includeAll','findAll','catch','show','params','find','create','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','path','sox','ejs','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb'];(function(_0x26c5f0,_0x301f2d){var _0x12b94a=function(_0x101c5e){while(--_0x101c5e){_0x26c5f0['push'](_0x26c5f0['shift']());}};_0x12b94a(++_0x301f2d);}(_0x3f6b,0x113));var _0xb3f6=function(_0x5fc032,_0x4d20b1){_0x5fc032=_0x5fc032-0x0;var _0x43ff5a=_0x3f6b[_0x5fc032];return _0x43ff5a;};'use strict';var emlformat=require(_0xb3f6('0x0'));var rimraf=require(_0xb3f6('0x1'));var zipdir=require(_0xb3f6('0x2'));var jsonpatch=require(_0xb3f6('0x3'));var rp=require(_0xb3f6('0x4'));var moment=require('moment');var BPromise=require(_0xb3f6('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0xb3f6('0x6'));var sox=require(_0xb3f6('0x7'));var csv=require('to-csv');var ejs=require(_0xb3f6('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require('squel');var crypto=require(_0xb3f6('0x9'));var jsforce=require(_0xb3f6('0xa'));var deskjs=require(_0xb3f6('0xb'));var toCsv=require(_0xb3f6('0xc'));var querystring=require(_0xb3f6('0xd'));var Papa=require(_0xb3f6('0xe'));var Redis=require(_0xb3f6('0xf'));var authService=require(_0xb3f6('0x10'));var qs=require(_0xb3f6('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xb3f6('0x12'));var logger=require(_0xb3f6('0x13'))(_0xb3f6('0x14'));var utils=require(_0xb3f6('0x15'));var config=require(_0xb3f6('0x16'));var licenseUtil=require(_0xb3f6('0x17'));var db=require(_0xb3f6('0x18'))['db'];function respondWithStatusCode(_0x3f1340,_0xff817a){_0xff817a=_0xff817a||0xcc;return function(_0x357175){if(_0x357175){return _0x3f1340[_0xb3f6('0x19')](_0xff817a);}return _0x3f1340[_0xb3f6('0x1a')](_0xff817a)[_0xb3f6('0x1b')]();};}function respondWithResult(_0x3b80f5,_0x53a286){_0x53a286=_0x53a286||0xc8;return function(_0x2f2b8e){if(_0x2f2b8e){return _0x3b80f5[_0xb3f6('0x1a')](_0x53a286)[_0xb3f6('0x1c')](_0x2f2b8e);}};}function respondWithFilteredResult(_0x3f03d2,_0xd41895){return function(_0x210eb4){if(_0x210eb4){var _0x403194=typeof _0xd41895[_0xb3f6('0x1d')]==='undefined'&&typeof _0xd41895[_0xb3f6('0x1e')]===_0xb3f6('0x1f');var _0xdc9a25=_0x210eb4[_0xb3f6('0x20')];var _0x3afd73=_0x403194?0x0:_0xd41895[_0xb3f6('0x1d')];var _0x5c67c7=_0x403194?_0x210eb4[_0xb3f6('0x20')]:_0xd41895[_0xb3f6('0x1d')]+_0xd41895['limit'];var _0x581d19;if(_0x5c67c7>=_0xdc9a25){_0x5c67c7=_0xdc9a25;_0x581d19=0xc8;}else{_0x581d19=0xce;}_0x3f03d2[_0xb3f6('0x1a')](_0x581d19);return _0x3f03d2[_0xb3f6('0x21')]('Content-Range',_0x3afd73+'-'+_0x5c67c7+'/'+_0xdc9a25)[_0xb3f6('0x1c')](_0x210eb4);}return null;};}function patchUpdates(_0x4098db){return function(_0x461d2e){try{jsonpatch[_0xb3f6('0x22')](_0x461d2e,_0x4098db,!![]);}catch(_0x514588){return BPromise[_0xb3f6('0x23')](_0x514588);}return _0x461d2e[_0xb3f6('0x24')]();};}function saveUpdates(_0x56d3ed,_0x4af572){return function(_0x3a6475){if(_0x3a6475){return _0x3a6475['update'](_0x56d3ed)['then'](function(_0x534bcf){return _0x534bcf;});}return null;};}function removeEntity(_0xb03f0a,_0x10641d){return function(_0x15d7dc){if(_0x15d7dc){return _0x15d7dc[_0xb3f6('0x25')]()[_0xb3f6('0x26')](function(){_0xb03f0a[_0xb3f6('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x29678f,_0x206b55){return function(_0x475c2a){if(!_0x475c2a){_0x29678f[_0xb3f6('0x19')](0x194);}return _0x475c2a;};}function handleError(_0x23a6ce,_0xb114e9){_0xb114e9=_0xb114e9||0x1f4;return function(_0x181507){logger[_0xb3f6('0x27')](_0x181507[_0xb3f6('0x28')]);if(_0x181507['name']){delete _0x181507[_0xb3f6('0x29')];}_0x23a6ce[_0xb3f6('0x1a')](_0xb114e9)[_0xb3f6('0x2a')](_0x181507);};}exports[_0xb3f6('0x2b')]=function(_0x20ffec,_0x1a1e34){var _0x12660d={},_0x36e193={},_0x18d8e9={'count':0x0,'rows':[]};var _0x4c7699=_[_0xb3f6('0x2c')](db[_0xb3f6('0x2d')][_0xb3f6('0x2e')],function(_0x2bc148){return{'name':_0x2bc148[_0xb3f6('0x2f')],'type':_0x2bc148[_0xb3f6('0x30')][_0xb3f6('0x31')]};});_0x36e193[_0xb3f6('0x32')]=_[_0xb3f6('0x2c')](_0x4c7699,_0xb3f6('0x29'));_0x36e193[_0xb3f6('0x33')]=_[_0xb3f6('0x34')](_0x20ffec[_0xb3f6('0x33')]);_0x36e193[_0xb3f6('0x35')]=_[_0xb3f6('0x36')](_0x36e193['model'],_0x36e193[_0xb3f6('0x33')]);_0x12660d[_0xb3f6('0x37')]=_['intersection'](_0x36e193[_0xb3f6('0x32')],qs['fields'](_0x20ffec[_0xb3f6('0x33')][_0xb3f6('0x38')]));_0x12660d[_0xb3f6('0x37')]=_0x12660d['attributes'][_0xb3f6('0x39')]?_0x12660d[_0xb3f6('0x37')]:_0x36e193[_0xb3f6('0x32')];if(!_0x20ffec[_0xb3f6('0x33')][_0xb3f6('0x3a')](_0xb3f6('0x3b'))){_0x12660d['limit']=qs['limit'](_0x20ffec[_0xb3f6('0x33')][_0xb3f6('0x1e')]);_0x12660d[_0xb3f6('0x1d')]=qs[_0xb3f6('0x1d')](_0x20ffec[_0xb3f6('0x33')]['offset']);}_0x12660d['order']=qs[_0xb3f6('0x3c')](_0x20ffec['query'][_0xb3f6('0x3c')]);_0x12660d['where']=qs['filters'](_[_0xb3f6('0x3d')](_0x20ffec[_0xb3f6('0x33')],_0x36e193[_0xb3f6('0x35')]),_0x4c7699);if(_0x20ffec[_0xb3f6('0x33')][_0xb3f6('0x3e')]){_0x12660d[_0xb3f6('0x3f')]=_[_0xb3f6('0x40')](_0x12660d[_0xb3f6('0x3f')],{'$or':_['map'](_0x4c7699,function(_0x301543){if(_0x301543[_0xb3f6('0x30')]!==_0xb3f6('0x41')){var _0x4ee423={};_0x4ee423[_0x301543[_0xb3f6('0x29')]]={'$like':'%'+_0x20ffec[_0xb3f6('0x33')][_0xb3f6('0x3e')]+'%'};return _0x4ee423;}})});}_0x12660d=_[_0xb3f6('0x40')]({},_0x12660d,_0x20ffec[_0xb3f6('0x42')]);var _0x579f3f={'where':_0x12660d[_0xb3f6('0x3f')]};return db[_0xb3f6('0x2d')]['count'](_0x579f3f)[_0xb3f6('0x26')](function(_0x1d6e79){_0x18d8e9[_0xb3f6('0x20')]=_0x1d6e79;if(_0x20ffec['query'][_0xb3f6('0x43')]){_0x12660d['include']=[{'all':!![]}];}return db[_0xb3f6('0x2d')][_0xb3f6('0x44')](_0x12660d);})['then'](function(_0x1fe919){_0x18d8e9['rows']=_0x1fe919;return _0x18d8e9;})[_0xb3f6('0x26')](respondWithFilteredResult(_0x1a1e34,_0x12660d))[_0xb3f6('0x45')](handleError(_0x1a1e34,null));};exports[_0xb3f6('0x46')]=function(_0x2411f0,_0x53024c){var _0x5de90a={'raw':!![],'where':{'id':_0x2411f0[_0xb3f6('0x47')]['id']}},_0x580bb4={};_0x580bb4['model']=_['keys'](db[_0xb3f6('0x2d')][_0xb3f6('0x2e')]);_0x580bb4[_0xb3f6('0x33')]=_[_0xb3f6('0x34')](_0x2411f0[_0xb3f6('0x33')]);_0x580bb4[_0xb3f6('0x35')]=_[_0xb3f6('0x36')](_0x580bb4[_0xb3f6('0x32')],_0x580bb4[_0xb3f6('0x33')]);_0x5de90a[_0xb3f6('0x37')]=_[_0xb3f6('0x36')](_0x580bb4[_0xb3f6('0x32')],qs[_0xb3f6('0x38')](_0x2411f0[_0xb3f6('0x33')][_0xb3f6('0x38')]));_0x5de90a[_0xb3f6('0x37')]=_0x5de90a[_0xb3f6('0x37')][_0xb3f6('0x39')]?_0x5de90a[_0xb3f6('0x37')]:_0x580bb4[_0xb3f6('0x32')];if(_0x2411f0['query'][_0xb3f6('0x43')]){_0x5de90a['include']=[{'all':!![]}];}_0x5de90a=_['merge']({},_0x5de90a,_0x2411f0[_0xb3f6('0x42')]);return db[_0xb3f6('0x2d')][_0xb3f6('0x48')](_0x5de90a)['then'](handleEntityNotFound(_0x53024c,null))['then'](respondWithResult(_0x53024c,null))[_0xb3f6('0x45')](handleError(_0x53024c,null));};exports[_0xb3f6('0x49')]=function(_0x37d92d,_0x307adf){return db[_0xb3f6('0x2d')][_0xb3f6('0x49')](_0x37d92d[_0xb3f6('0x4a')],{})[_0xb3f6('0x26')](respondWithResult(_0x307adf,0xc9))[_0xb3f6('0x45')](handleError(_0x307adf,null));};exports['update']=function(_0x28a60e,_0x439de4){if(_0x28a60e[_0xb3f6('0x4a')]['id']){delete _0x28a60e[_0xb3f6('0x4a')]['id'];}return db[_0xb3f6('0x2d')]['find']({'where':{'id':_0x28a60e[_0xb3f6('0x47')]['id']}})[_0xb3f6('0x26')](handleEntityNotFound(_0x439de4,null))[_0xb3f6('0x26')](saveUpdates(_0x28a60e['body'],null))[_0xb3f6('0x26')](respondWithResult(_0x439de4,null))[_0xb3f6('0x45')](handleError(_0x439de4,null));};exports['destroy']=function(_0x2d90a6,_0x5e88a2){return db['SmsApplication'][_0xb3f6('0x48')]({'where':{'id':_0x2d90a6['params']['id']}})[_0xb3f6('0x26')](handleEntityNotFound(_0x5e88a2,null))[_0xb3f6('0x26')](removeEntity(_0x5e88a2,null))[_0xb3f6('0x45')](handleError(_0x5e88a2,null));};