3926fcb3395b8309466a5fdcddbe72a2cf84d8d7
[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 _0xf600=['then','error','stack','name','send','index','map','rawAttributes','fieldName','type','model','keys','query','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','options','SmsApplication','includeAll','findAll','rows','catch','show','params','include','create','body','find','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','destroy'];(function(_0x320771,_0x49f175){var _0x3197e6=function(_0x3ffa62){while(--_0x3ffa62){_0x320771['push'](_0x320771['shift']());}};_0x3197e6(++_0x49f175);}(_0xf600,0x119));var _0x0f60=function(_0x531761,_0x520a8){_0x531761=_0x531761-0x0;var _0x2f32c6=_0xf600[_0x531761];return _0x2f32c6;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x0f60('0x0'));var zipdir=require(_0x0f60('0x1'));var jsonpatch=require(_0x0f60('0x2'));var rp=require(_0x0f60('0x3'));var moment=require(_0x0f60('0x4'));var BPromise=require(_0x0f60('0x5'));var Mustache=require(_0x0f60('0x6'));var util=require(_0x0f60('0x7'));var path=require(_0x0f60('0x8'));var sox=require('sox');var csv=require(_0x0f60('0x9'));var ejs=require(_0x0f60('0xa'));var fs=require('fs');var fs_extra=require(_0x0f60('0xb'));var _=require(_0x0f60('0xc'));var squel=require(_0x0f60('0xd'));var crypto=require(_0x0f60('0xe'));var jsforce=require(_0x0f60('0xf'));var deskjs=require(_0x0f60('0x10'));var toCsv=require(_0x0f60('0x9'));var querystring=require('querystring');var Papa=require(_0x0f60('0x11'));var Redis=require(_0x0f60('0x12'));var authService=require(_0x0f60('0x13'));var qs=require(_0x0f60('0x14'));var as=require(_0x0f60('0x15'));var hardwareService=require(_0x0f60('0x16'));var logger=require(_0x0f60('0x17'))(_0x0f60('0x18'));var utils=require(_0x0f60('0x19'));var config=require(_0x0f60('0x1a'));var licenseUtil=require('../../config/license/util');var db=require(_0x0f60('0x1b'))['db'];function respondWithStatusCode(_0x404d6a,_0x16108f){_0x16108f=_0x16108f||0xcc;return function(_0x2ef822){if(_0x2ef822){return _0x404d6a[_0x0f60('0x1c')](_0x16108f);}return _0x404d6a[_0x0f60('0x1d')](_0x16108f)[_0x0f60('0x1e')]();};}function respondWithResult(_0x25fb62,_0x21b645){_0x21b645=_0x21b645||0xc8;return function(_0xcb5bcc){if(_0xcb5bcc){return _0x25fb62[_0x0f60('0x1d')](_0x21b645)[_0x0f60('0x1f')](_0xcb5bcc);}};}function respondWithFilteredResult(_0x434a05,_0x423fc0){return function(_0x6c3461){if(_0x6c3461){var _0x8af8ac=typeof _0x423fc0[_0x0f60('0x20')]===_0x0f60('0x21')&&typeof _0x423fc0[_0x0f60('0x22')]===_0x0f60('0x21');var _0x43ee20=_0x6c3461[_0x0f60('0x23')];var _0x6536e=_0x8af8ac?0x0:_0x423fc0[_0x0f60('0x20')];var _0x59d952=_0x8af8ac?_0x6c3461['count']:_0x423fc0[_0x0f60('0x20')]+_0x423fc0[_0x0f60('0x22')];var _0x5254b2;if(_0x59d952>=_0x43ee20){_0x59d952=_0x43ee20;_0x5254b2=0xc8;}else{_0x5254b2=0xce;}_0x434a05[_0x0f60('0x1d')](_0x5254b2);return _0x434a05[_0x0f60('0x24')](_0x0f60('0x25'),_0x6536e+'-'+_0x59d952+'/'+_0x43ee20)[_0x0f60('0x1f')](_0x6c3461);}return null;};}function patchUpdates(_0x51cf4e){return function(_0x16aeee){try{jsonpatch[_0x0f60('0x26')](_0x16aeee,_0x51cf4e,!![]);}catch(_0x3a0e1c){return BPromise[_0x0f60('0x27')](_0x3a0e1c);}return _0x16aeee[_0x0f60('0x28')]();};}function saveUpdates(_0x13915d,_0x1316b5){return function(_0x12019e){if(_0x12019e){return _0x12019e[_0x0f60('0x29')](_0x13915d)['then'](function(_0xd28a12){return _0xd28a12;});}return null;};}function removeEntity(_0x2fa93a,_0x1cf1a2){return function(_0x318f8d){if(_0x318f8d){return _0x318f8d[_0x0f60('0x2a')]()[_0x0f60('0x2b')](function(){_0x2fa93a[_0x0f60('0x1d')](0xcc)[_0x0f60('0x1e')]();});}};}function handleEntityNotFound(_0x1a43be,_0x2c1dbb){return function(_0x4a2e3c){if(!_0x4a2e3c){_0x1a43be[_0x0f60('0x1c')](0x194);}return _0x4a2e3c;};}function handleError(_0x31c856,_0x3f4a28){_0x3f4a28=_0x3f4a28||0x1f4;return function(_0x4a59b1){logger[_0x0f60('0x2c')](_0x4a59b1[_0x0f60('0x2d')]);if(_0x4a59b1[_0x0f60('0x2e')]){delete _0x4a59b1[_0x0f60('0x2e')];}_0x31c856[_0x0f60('0x1d')](_0x3f4a28)[_0x0f60('0x2f')](_0x4a59b1);};}exports[_0x0f60('0x30')]=function(_0x4cb605,_0x36d87b){var _0x53281f={},_0x31c692={},_0x50a7fb={'count':0x0,'rows':[]};var _0x4d1ef2=_[_0x0f60('0x31')](db['SmsApplication'][_0x0f60('0x32')],function(_0x4fff12){return{'name':_0x4fff12[_0x0f60('0x33')],'type':_0x4fff12[_0x0f60('0x34')]['key']};});_0x31c692[_0x0f60('0x35')]=_['map'](_0x4d1ef2,_0x0f60('0x2e'));_0x31c692['query']=_[_0x0f60('0x36')](_0x4cb605[_0x0f60('0x37')]);_0x31c692['filters']=_[_0x0f60('0x38')](_0x31c692[_0x0f60('0x35')],_0x31c692['query']);_0x53281f['attributes']=_[_0x0f60('0x38')](_0x31c692[_0x0f60('0x35')],qs[_0x0f60('0x39')](_0x4cb605[_0x0f60('0x37')][_0x0f60('0x39')]));_0x53281f[_0x0f60('0x3a')]=_0x53281f[_0x0f60('0x3a')][_0x0f60('0x3b')]?_0x53281f[_0x0f60('0x3a')]:_0x31c692['model'];if(!_0x4cb605[_0x0f60('0x37')][_0x0f60('0x3c')](_0x0f60('0x3d'))){_0x53281f['limit']=qs[_0x0f60('0x22')](_0x4cb605[_0x0f60('0x37')]['limit']);_0x53281f[_0x0f60('0x20')]=qs[_0x0f60('0x20')](_0x4cb605[_0x0f60('0x37')][_0x0f60('0x20')]);}_0x53281f[_0x0f60('0x3e')]=qs[_0x0f60('0x3f')](_0x4cb605['query'][_0x0f60('0x3f')]);_0x53281f[_0x0f60('0x40')]=qs[_0x0f60('0x41')](_[_0x0f60('0x42')](_0x4cb605[_0x0f60('0x37')],_0x31c692[_0x0f60('0x41')]),_0x4d1ef2);if(_0x4cb605[_0x0f60('0x37')][_0x0f60('0x43')]){_0x53281f[_0x0f60('0x40')]=_[_0x0f60('0x44')](_0x53281f[_0x0f60('0x40')],{'$or':_[_0x0f60('0x31')](_0x4d1ef2,function(_0x48e261){if(_0x48e261[_0x0f60('0x34')]!=='VIRTUAL'){var _0x7cc93b={};_0x7cc93b[_0x48e261[_0x0f60('0x2e')]]={'$like':'%'+_0x4cb605['query'][_0x0f60('0x43')]+'%'};return _0x7cc93b;}})});}_0x53281f=_[_0x0f60('0x44')]({},_0x53281f,_0x4cb605[_0x0f60('0x45')]);var _0x4e52bb={'where':_0x53281f[_0x0f60('0x40')]};return db[_0x0f60('0x46')][_0x0f60('0x23')](_0x4e52bb)['then'](function(_0x208efa){_0x50a7fb[_0x0f60('0x23')]=_0x208efa;if(_0x4cb605[_0x0f60('0x37')][_0x0f60('0x47')]){_0x53281f['include']=[{'all':!![]}];}return db[_0x0f60('0x46')][_0x0f60('0x48')](_0x53281f);})[_0x0f60('0x2b')](function(_0x3e21b8){_0x50a7fb[_0x0f60('0x49')]=_0x3e21b8;return _0x50a7fb;})['then'](respondWithFilteredResult(_0x36d87b,_0x53281f))[_0x0f60('0x4a')](handleError(_0x36d87b,null));};exports[_0x0f60('0x4b')]=function(_0x1ed85d,_0x31af9e){var _0x4e42f3={'raw':!![],'where':{'id':_0x1ed85d[_0x0f60('0x4c')]['id']}},_0x312536={};_0x312536[_0x0f60('0x35')]=_[_0x0f60('0x36')](db[_0x0f60('0x46')][_0x0f60('0x32')]);_0x312536[_0x0f60('0x37')]=_[_0x0f60('0x36')](_0x1ed85d[_0x0f60('0x37')]);_0x312536['filters']=_[_0x0f60('0x38')](_0x312536[_0x0f60('0x35')],_0x312536[_0x0f60('0x37')]);_0x4e42f3['attributes']=_['intersection'](_0x312536[_0x0f60('0x35')],qs[_0x0f60('0x39')](_0x1ed85d[_0x0f60('0x37')][_0x0f60('0x39')]));_0x4e42f3['attributes']=_0x4e42f3['attributes'][_0x0f60('0x3b')]?_0x4e42f3[_0x0f60('0x3a')]:_0x312536[_0x0f60('0x35')];if(_0x1ed85d[_0x0f60('0x37')]['includeAll']){_0x4e42f3[_0x0f60('0x4d')]=[{'all':!![]}];}_0x4e42f3=_[_0x0f60('0x44')]({},_0x4e42f3,_0x1ed85d[_0x0f60('0x45')]);return db['SmsApplication']['find'](_0x4e42f3)[_0x0f60('0x2b')](handleEntityNotFound(_0x31af9e,null))[_0x0f60('0x2b')](respondWithResult(_0x31af9e,null))[_0x0f60('0x4a')](handleError(_0x31af9e,null));};exports[_0x0f60('0x4e')]=function(_0x1cd7bf,_0x34a7f9){return db[_0x0f60('0x46')]['create'](_0x1cd7bf[_0x0f60('0x4f')],{})[_0x0f60('0x2b')](respondWithResult(_0x34a7f9,0xc9))[_0x0f60('0x4a')](handleError(_0x34a7f9,null));};exports[_0x0f60('0x29')]=function(_0x4d3d69,_0x557390){if(_0x4d3d69[_0x0f60('0x4f')]['id']){delete _0x4d3d69['body']['id'];}return db[_0x0f60('0x46')][_0x0f60('0x50')]({'where':{'id':_0x4d3d69[_0x0f60('0x4c')]['id']}})[_0x0f60('0x2b')](handleEntityNotFound(_0x557390,null))[_0x0f60('0x2b')](saveUpdates(_0x4d3d69[_0x0f60('0x4f')],null))['then'](respondWithResult(_0x557390,null))[_0x0f60('0x4a')](handleError(_0x557390,null));};exports[_0x0f60('0x2a')]=function(_0x209932,_0x12a4c6){return db[_0x0f60('0x46')][_0x0f60('0x50')]({'where':{'id':_0x209932[_0x0f60('0x4c')]['id']}})[_0x0f60('0x2b')](handleEntityNotFound(_0x12a4c6,null))[_0x0f60('0x2b')](removeEntity(_0x12a4c6,null))['catch'](handleError(_0x12a4c6,null));};