Built motion from commit dbf3a7e2.|2.6.30
[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 _0xc7cb=['catch','params','find','create','body','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','lodash','squel','crypto','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset','undefined','limit','set','Content-Range','reject','save','update','then','destroy','stack','name','index','map','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','options','SmsApplication','count','includeAll','include','rows'];(function(_0x318123,_0x48963a){var _0x40a51c=function(_0x53203b){while(--_0x53203b){_0x318123['push'](_0x318123['shift']());}};_0x40a51c(++_0x48963a);}(_0xc7cb,0x131));var _0xbc7c=function(_0x15b37d,_0x1ea430){_0x15b37d=_0x15b37d-0x0;var _0x4c0c55=_0xc7cb[_0x15b37d];return _0x4c0c55;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xbc7c('0x0'));var zipdir=require(_0xbc7c('0x1'));var jsonpatch=require(_0xbc7c('0x2'));var rp=require(_0xbc7c('0x3'));var moment=require(_0xbc7c('0x4'));var BPromise=require(_0xbc7c('0x5'));var Mustache=require(_0xbc7c('0x6'));var util=require(_0xbc7c('0x7'));var path=require(_0xbc7c('0x8'));var sox=require(_0xbc7c('0x9'));var csv=require(_0xbc7c('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xbc7c('0xb'));var _=require(_0xbc7c('0xc'));var squel=require(_0xbc7c('0xd'));var crypto=require(_0xbc7c('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xbc7c('0xf'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xbc7c('0x10'));var authService=require(_0xbc7c('0x11'));var qs=require(_0xbc7c('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xbc7c('0x13'));var logger=require(_0xbc7c('0x14'))(_0xbc7c('0x15'));var utils=require(_0xbc7c('0x16'));var config=require(_0xbc7c('0x17'));var licenseUtil=require(_0xbc7c('0x18'));var db=require(_0xbc7c('0x19'))['db'];function respondWithStatusCode(_0x594723,_0x47b74c){_0x47b74c=_0x47b74c||0xcc;return function(_0x42c28d){if(_0x42c28d){return _0x594723[_0xbc7c('0x1a')](_0x47b74c);}return _0x594723['status'](_0x47b74c)[_0xbc7c('0x1b')]();};}function respondWithResult(_0x18b328,_0x60296a){_0x60296a=_0x60296a||0xc8;return function(_0x26bd08){if(_0x26bd08){return _0x18b328[_0xbc7c('0x1c')](_0x60296a)[_0xbc7c('0x1d')](_0x26bd08);}};}function respondWithFilteredResult(_0x1b8f72,_0x401b8b){return function(_0x473a0d){if(_0x473a0d){var _0x34d809=typeof _0x401b8b[_0xbc7c('0x1e')]===_0xbc7c('0x1f')&&typeof _0x401b8b[_0xbc7c('0x20')]==='undefined';var _0x3fb0a4=_0x473a0d['count'];var _0x5152ba=_0x34d809?0x0:_0x401b8b['offset'];var _0x8389f1=_0x34d809?_0x473a0d['count']:_0x401b8b[_0xbc7c('0x1e')]+_0x401b8b[_0xbc7c('0x20')];var _0x4db83e;if(_0x8389f1>=_0x3fb0a4){_0x8389f1=_0x3fb0a4;_0x4db83e=0xc8;}else{_0x4db83e=0xce;}_0x1b8f72['status'](_0x4db83e);return _0x1b8f72[_0xbc7c('0x21')](_0xbc7c('0x22'),_0x5152ba+'-'+_0x8389f1+'/'+_0x3fb0a4)[_0xbc7c('0x1d')](_0x473a0d);}return null;};}function patchUpdates(_0x206972){return function(_0x4aa548){try{jsonpatch['apply'](_0x4aa548,_0x206972,!![]);}catch(_0x5edee6){return BPromise[_0xbc7c('0x23')](_0x5edee6);}return _0x4aa548[_0xbc7c('0x24')]();};}function saveUpdates(_0x5e6e33,_0x3ea12b){return function(_0x1002eb){if(_0x1002eb){return _0x1002eb[_0xbc7c('0x25')](_0x5e6e33)[_0xbc7c('0x26')](function(_0x56cc39){return _0x56cc39;});}return null;};}function removeEntity(_0x106a72,_0x2e62a2){return function(_0x5ddedd){if(_0x5ddedd){return _0x5ddedd[_0xbc7c('0x27')]()[_0xbc7c('0x26')](function(){_0x106a72[_0xbc7c('0x1c')](0xcc)[_0xbc7c('0x1b')]();});}};}function handleEntityNotFound(_0x43a5dc,_0x13cb3f){return function(_0x4c1633){if(!_0x4c1633){_0x43a5dc[_0xbc7c('0x1a')](0x194);}return _0x4c1633;};}function handleError(_0x329ece,_0x3e2226){_0x3e2226=_0x3e2226||0x1f4;return function(_0xe076ac){logger['error'](_0xe076ac[_0xbc7c('0x28')]);if(_0xe076ac[_0xbc7c('0x29')]){delete _0xe076ac['name'];}_0x329ece[_0xbc7c('0x1c')](_0x3e2226)['send'](_0xe076ac);};}exports[_0xbc7c('0x2a')]=function(_0x10901a,_0x180909){var _0x1cfa1c={},_0x5d1c9c={},_0x2fe167={'count':0x0,'rows':[]};var _0x25268a=_[_0xbc7c('0x2b')](db['SmsApplication'][_0xbc7c('0x2c')],function(_0xd29c05){return{'name':_0xd29c05[_0xbc7c('0x2d')],'type':_0xd29c05[_0xbc7c('0x2e')][_0xbc7c('0x2f')]};});_0x5d1c9c[_0xbc7c('0x30')]=_[_0xbc7c('0x2b')](_0x25268a,_0xbc7c('0x29'));_0x5d1c9c['query']=_[_0xbc7c('0x31')](_0x10901a[_0xbc7c('0x32')]);_0x5d1c9c[_0xbc7c('0x33')]=_[_0xbc7c('0x34')](_0x5d1c9c[_0xbc7c('0x30')],_0x5d1c9c[_0xbc7c('0x32')]);_0x1cfa1c['attributes']=_[_0xbc7c('0x34')](_0x5d1c9c[_0xbc7c('0x30')],qs[_0xbc7c('0x35')](_0x10901a[_0xbc7c('0x32')][_0xbc7c('0x35')]));_0x1cfa1c[_0xbc7c('0x36')]=_0x1cfa1c['attributes'][_0xbc7c('0x37')]?_0x1cfa1c['attributes']:_0x5d1c9c[_0xbc7c('0x30')];if(!_0x10901a[_0xbc7c('0x32')][_0xbc7c('0x38')](_0xbc7c('0x39'))){_0x1cfa1c['limit']=qs[_0xbc7c('0x20')](_0x10901a[_0xbc7c('0x32')][_0xbc7c('0x20')]);_0x1cfa1c[_0xbc7c('0x1e')]=qs[_0xbc7c('0x1e')](_0x10901a[_0xbc7c('0x32')][_0xbc7c('0x1e')]);}_0x1cfa1c[_0xbc7c('0x3a')]=qs[_0xbc7c('0x3b')](_0x10901a['query'][_0xbc7c('0x3b')]);_0x1cfa1c['where']=qs[_0xbc7c('0x33')](_[_0xbc7c('0x3c')](_0x10901a['query'],_0x5d1c9c['filters']),_0x25268a);if(_0x10901a[_0xbc7c('0x32')][_0xbc7c('0x3d')]){_0x1cfa1c[_0xbc7c('0x3e')]=_[_0xbc7c('0x3f')](_0x1cfa1c[_0xbc7c('0x3e')],{'$or':_['map'](_0x25268a,function(_0x5c5d86){if(_0x5c5d86['type']!=='VIRTUAL'){var _0x4147c4={};_0x4147c4[_0x5c5d86[_0xbc7c('0x29')]]={'$like':'%'+_0x10901a[_0xbc7c('0x32')]['filter']+'%'};return _0x4147c4;}})});}_0x1cfa1c=_[_0xbc7c('0x3f')]({},_0x1cfa1c,_0x10901a[_0xbc7c('0x40')]);var _0x4f4b9c={'where':_0x1cfa1c[_0xbc7c('0x3e')]};return db[_0xbc7c('0x41')]['count'](_0x4f4b9c)['then'](function(_0x2c1652){_0x2fe167[_0xbc7c('0x42')]=_0x2c1652;if(_0x10901a[_0xbc7c('0x32')][_0xbc7c('0x43')]){_0x1cfa1c[_0xbc7c('0x44')]=[{'all':!![]}];}return db[_0xbc7c('0x41')]['findAll'](_0x1cfa1c);})[_0xbc7c('0x26')](function(_0x37b433){_0x2fe167[_0xbc7c('0x45')]=_0x37b433;return _0x2fe167;})[_0xbc7c('0x26')](respondWithFilteredResult(_0x180909,_0x1cfa1c))[_0xbc7c('0x46')](handleError(_0x180909,null));};exports['show']=function(_0x3eecf6,_0xb550fc){var _0x1d0699={'raw':!![],'where':{'id':_0x3eecf6[_0xbc7c('0x47')]['id']}},_0x5a4567={};_0x5a4567['model']=_[_0xbc7c('0x31')](db['SmsApplication']['rawAttributes']);_0x5a4567[_0xbc7c('0x32')]=_[_0xbc7c('0x31')](_0x3eecf6['query']);_0x5a4567['filters']=_[_0xbc7c('0x34')](_0x5a4567['model'],_0x5a4567[_0xbc7c('0x32')]);_0x1d0699[_0xbc7c('0x36')]=_['intersection'](_0x5a4567[_0xbc7c('0x30')],qs[_0xbc7c('0x35')](_0x3eecf6['query']['fields']));_0x1d0699[_0xbc7c('0x36')]=_0x1d0699[_0xbc7c('0x36')][_0xbc7c('0x37')]?_0x1d0699[_0xbc7c('0x36')]:_0x5a4567[_0xbc7c('0x30')];if(_0x3eecf6[_0xbc7c('0x32')][_0xbc7c('0x43')]){_0x1d0699[_0xbc7c('0x44')]=[{'all':!![]}];}_0x1d0699=_[_0xbc7c('0x3f')]({},_0x1d0699,_0x3eecf6[_0xbc7c('0x40')]);return db[_0xbc7c('0x41')][_0xbc7c('0x48')](_0x1d0699)[_0xbc7c('0x26')](handleEntityNotFound(_0xb550fc,null))[_0xbc7c('0x26')](respondWithResult(_0xb550fc,null))[_0xbc7c('0x46')](handleError(_0xb550fc,null));};exports['create']=function(_0x43a3b5,_0x46ef0c){return db[_0xbc7c('0x41')][_0xbc7c('0x49')](_0x43a3b5[_0xbc7c('0x4a')],{})[_0xbc7c('0x26')](respondWithResult(_0x46ef0c,0xc9))[_0xbc7c('0x46')](handleError(_0x46ef0c,null));};exports[_0xbc7c('0x25')]=function(_0x264856,_0x3676ed){if(_0x264856[_0xbc7c('0x4a')]['id']){delete _0x264856[_0xbc7c('0x4a')]['id'];}return db[_0xbc7c('0x41')][_0xbc7c('0x48')]({'where':{'id':_0x264856[_0xbc7c('0x47')]['id']}})[_0xbc7c('0x26')](handleEntityNotFound(_0x3676ed,null))[_0xbc7c('0x26')](saveUpdates(_0x264856[_0xbc7c('0x4a')],null))[_0xbc7c('0x26')](respondWithResult(_0x3676ed,null))[_0xbc7c('0x46')](handleError(_0x3676ed,null));};exports[_0xbc7c('0x27')]=function(_0x152216,_0x1c8dea){return db[_0xbc7c('0x41')][_0xbc7c('0x48')]({'where':{'id':_0x152216[_0xbc7c('0x47')]['id']}})[_0xbc7c('0x26')](handleEntityNotFound(_0x1c8dea,null))[_0xbc7c('0x26')](removeEntity(_0x1c8dea,null))[_0xbc7c('0x46')](handleError(_0x1c8dea,null));};