2ff175d81a06429a35401bb14d5ec8125fb56e4f
[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 _0x633f=['../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','sendStatus','end','json','offset','undefined','limit','count','Content-Range','apply','reject','save','destroy','then','status','name','index','rawAttributes','fieldName','type','key','model','map','query','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filters','filter','merge','SmsApplication','includeAll','include','findAll','rows','catch','show','params','keys','options','create','body','update','find','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis'];(function(_0x15e098,_0x539cfc){var _0x2ab697=function(_0x53a216){while(--_0x53a216){_0x15e098['push'](_0x15e098['shift']());}};_0x2ab697(++_0x539cfc);}(_0x633f,0x1c0));var _0xf633=function(_0x4e9f9f,_0x1f5c62){_0x4e9f9f=_0x4e9f9f-0x0;var _0x5ada14=_0x633f[_0x4e9f9f];return _0x5ada14;};'use strict';var emlformat=require(_0xf633('0x0'));var rimraf=require(_0xf633('0x1'));var zipdir=require(_0xf633('0x2'));var jsonpatch=require(_0xf633('0x3'));var rp=require(_0xf633('0x4'));var moment=require(_0xf633('0x5'));var BPromise=require(_0xf633('0x6'));var Mustache=require(_0xf633('0x7'));var util=require('util');var path=require(_0xf633('0x8'));var sox=require(_0xf633('0x9'));var csv=require(_0xf633('0xa'));var ejs=require(_0xf633('0xb'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xf633('0xc'));var squel=require(_0xf633('0xd'));var crypto=require(_0xf633('0xe'));var jsforce=require(_0xf633('0xf'));var deskjs=require(_0xf633('0x10'));var toCsv=require(_0xf633('0xa'));var querystring=require(_0xf633('0x11'));var Papa=require(_0xf633('0x12'));var Redis=require(_0xf633('0x13'));var authService=require(_0xf633('0x14'));var qs=require(_0xf633('0x15'));var as=require(_0xf633('0x16'));var hardwareService=require(_0xf633('0x17'));var logger=require(_0xf633('0x18'))(_0xf633('0x19'));var utils=require('../../config/utils');var config=require(_0xf633('0x1a'));var licenseUtil=require('../../config/license/util');var db=require(_0xf633('0x1b'))['db'];function respondWithStatusCode(_0x42f6b8,_0x5c84a4){_0x5c84a4=_0x5c84a4||0xcc;return function(_0x5bb3a5){if(_0x5bb3a5){return _0x42f6b8[_0xf633('0x1c')](_0x5c84a4);}return _0x42f6b8['status'](_0x5c84a4)[_0xf633('0x1d')]();};}function respondWithResult(_0xff14a3,_0x1a70b8){_0x1a70b8=_0x1a70b8||0xc8;return function(_0x369ed2){if(_0x369ed2){return _0xff14a3['status'](_0x1a70b8)[_0xf633('0x1e')](_0x369ed2);}};}function respondWithFilteredResult(_0x5983d5,_0x276198){return function(_0x2492d8){if(_0x2492d8){var _0x4c9a75=typeof _0x276198[_0xf633('0x1f')]===_0xf633('0x20')&&typeof _0x276198[_0xf633('0x21')]===_0xf633('0x20');var _0x1f0d63=_0x2492d8['count'];var _0x301c17=_0x4c9a75?0x0:_0x276198[_0xf633('0x1f')];var _0x1647cc=_0x4c9a75?_0x2492d8[_0xf633('0x22')]:_0x276198[_0xf633('0x1f')]+_0x276198[_0xf633('0x21')];var _0x7e1fb1;if(_0x1647cc>=_0x1f0d63){_0x1647cc=_0x1f0d63;_0x7e1fb1=0xc8;}else{_0x7e1fb1=0xce;}_0x5983d5['status'](_0x7e1fb1);return _0x5983d5['set'](_0xf633('0x23'),_0x301c17+'-'+_0x1647cc+'/'+_0x1f0d63)[_0xf633('0x1e')](_0x2492d8);}return null;};}function patchUpdates(_0x4b6c43){return function(_0x3f11f7){try{jsonpatch[_0xf633('0x24')](_0x3f11f7,_0x4b6c43,!![]);}catch(_0x47d8c5){return BPromise[_0xf633('0x25')](_0x47d8c5);}return _0x3f11f7[_0xf633('0x26')]();};}function saveUpdates(_0x361576,_0x27f958){return function(_0x166394){if(_0x166394){return _0x166394['update'](_0x361576)['then'](function(_0x5a5926){return _0x5a5926;});}return null;};}function removeEntity(_0x1d0e87,_0x57947d){return function(_0x450347){if(_0x450347){return _0x450347[_0xf633('0x27')]()[_0xf633('0x28')](function(){_0x1d0e87[_0xf633('0x29')](0xcc)[_0xf633('0x1d')]();});}};}function handleEntityNotFound(_0x33ac03,_0x28bdf0){return function(_0x17b869){if(!_0x17b869){_0x33ac03['sendStatus'](0x194);}return _0x17b869;};}function handleError(_0x2beafb,_0x7199fa){_0x7199fa=_0x7199fa||0x1f4;return function(_0x1eac07){logger['error'](_0x1eac07['stack']);if(_0x1eac07[_0xf633('0x2a')]){delete _0x1eac07[_0xf633('0x2a')];}_0x2beafb[_0xf633('0x29')](_0x7199fa)['send'](_0x1eac07);};}exports[_0xf633('0x2b')]=function(_0x4971e7,_0x2cc24f){var _0x187c02={},_0x470a24={},_0x332cfb={'count':0x0,'rows':[]};var _0x162798=_['map'](db['SmsApplication'][_0xf633('0x2c')],function(_0x4fe981){return{'name':_0x4fe981[_0xf633('0x2d')],'type':_0x4fe981[_0xf633('0x2e')][_0xf633('0x2f')]};});_0x470a24[_0xf633('0x30')]=_[_0xf633('0x31')](_0x162798,_0xf633('0x2a'));_0x470a24[_0xf633('0x32')]=_['keys'](_0x4971e7[_0xf633('0x32')]);_0x470a24['filters']=_['intersection'](_0x470a24[_0xf633('0x30')],_0x470a24[_0xf633('0x32')]);_0x187c02[_0xf633('0x33')]=_[_0xf633('0x34')](_0x470a24[_0xf633('0x30')],qs['fields'](_0x4971e7['query'][_0xf633('0x35')]));_0x187c02[_0xf633('0x33')]=_0x187c02[_0xf633('0x33')][_0xf633('0x36')]?_0x187c02['attributes']:_0x470a24[_0xf633('0x30')];if(!_0x4971e7[_0xf633('0x32')][_0xf633('0x37')](_0xf633('0x38'))){_0x187c02[_0xf633('0x21')]=qs[_0xf633('0x21')](_0x4971e7[_0xf633('0x32')][_0xf633('0x21')]);_0x187c02[_0xf633('0x1f')]=qs[_0xf633('0x1f')](_0x4971e7[_0xf633('0x32')][_0xf633('0x1f')]);}_0x187c02[_0xf633('0x39')]=qs['sort'](_0x4971e7[_0xf633('0x32')][_0xf633('0x3a')]);_0x187c02[_0xf633('0x3b')]=qs['filters'](_[_0xf633('0x3c')](_0x4971e7[_0xf633('0x32')],_0x470a24[_0xf633('0x3d')]),_0x162798);if(_0x4971e7[_0xf633('0x32')][_0xf633('0x3e')]){_0x187c02[_0xf633('0x3b')]=_[_0xf633('0x3f')](_0x187c02['where'],{'$or':_['map'](_0x162798,function(_0x1a8f87){if(_0x1a8f87[_0xf633('0x2e')]!=='VIRTUAL'){var _0x2d0c99={};_0x2d0c99[_0x1a8f87[_0xf633('0x2a')]]={'$like':'%'+_0x4971e7[_0xf633('0x32')][_0xf633('0x3e')]+'%'};return _0x2d0c99;}})});}_0x187c02=_[_0xf633('0x3f')]({},_0x187c02,_0x4971e7['options']);var _0x26c89e={'where':_0x187c02[_0xf633('0x3b')]};return db[_0xf633('0x40')][_0xf633('0x22')](_0x26c89e)[_0xf633('0x28')](function(_0x49eafc){_0x332cfb[_0xf633('0x22')]=_0x49eafc;if(_0x4971e7[_0xf633('0x32')][_0xf633('0x41')]){_0x187c02[_0xf633('0x42')]=[{'all':!![]}];}return db[_0xf633('0x40')][_0xf633('0x43')](_0x187c02);})[_0xf633('0x28')](function(_0x502905){_0x332cfb[_0xf633('0x44')]=_0x502905;return _0x332cfb;})[_0xf633('0x28')](respondWithFilteredResult(_0x2cc24f,_0x187c02))[_0xf633('0x45')](handleError(_0x2cc24f,null));};exports[_0xf633('0x46')]=function(_0xa8177c,_0x11af93){var _0x2eff66={'raw':!![],'where':{'id':_0xa8177c[_0xf633('0x47')]['id']}},_0x14a70a={};_0x14a70a['model']=_[_0xf633('0x48')](db[_0xf633('0x40')]['rawAttributes']);_0x14a70a[_0xf633('0x32')]=_[_0xf633('0x48')](_0xa8177c[_0xf633('0x32')]);_0x14a70a[_0xf633('0x3d')]=_[_0xf633('0x34')](_0x14a70a['model'],_0x14a70a[_0xf633('0x32')]);_0x2eff66[_0xf633('0x33')]=_[_0xf633('0x34')](_0x14a70a[_0xf633('0x30')],qs['fields'](_0xa8177c['query'][_0xf633('0x35')]));_0x2eff66[_0xf633('0x33')]=_0x2eff66[_0xf633('0x33')][_0xf633('0x36')]?_0x2eff66[_0xf633('0x33')]:_0x14a70a[_0xf633('0x30')];if(_0xa8177c[_0xf633('0x32')][_0xf633('0x41')]){_0x2eff66[_0xf633('0x42')]=[{'all':!![]}];}_0x2eff66=_[_0xf633('0x3f')]({},_0x2eff66,_0xa8177c[_0xf633('0x49')]);return db[_0xf633('0x40')]['find'](_0x2eff66)['then'](handleEntityNotFound(_0x11af93,null))[_0xf633('0x28')](respondWithResult(_0x11af93,null))['catch'](handleError(_0x11af93,null));};exports[_0xf633('0x4a')]=function(_0x222d0e,_0x1a1df5){return db[_0xf633('0x40')][_0xf633('0x4a')](_0x222d0e[_0xf633('0x4b')],{})['then'](respondWithResult(_0x1a1df5,0xc9))[_0xf633('0x45')](handleError(_0x1a1df5,null));};exports[_0xf633('0x4c')]=function(_0x3aab14,_0x1ea1e5){if(_0x3aab14[_0xf633('0x4b')]['id']){delete _0x3aab14['body']['id'];}return db[_0xf633('0x40')]['find']({'where':{'id':_0x3aab14[_0xf633('0x47')]['id']}})['then'](handleEntityNotFound(_0x1ea1e5,null))[_0xf633('0x28')](saveUpdates(_0x3aab14[_0xf633('0x4b')],null))[_0xf633('0x28')](respondWithResult(_0x1ea1e5,null))[_0xf633('0x45')](handleError(_0x1ea1e5,null));};exports[_0xf633('0x27')]=function(_0x1707bc,_0x3ba2cd){return db['SmsApplication'][_0xf633('0x4d')]({'where':{'id':_0x1707bc[_0xf633('0x47')]['id']}})[_0xf633('0x28')](handleEntityNotFound(_0x3ba2cd,null))[_0xf633('0x28')](removeEntity(_0x3ba2cd,null))[_0xf633('0x45')](handleError(_0x3ba2cd,null));};