Built motion from commit 449495f6.|2.6.27
[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 _0xf7cc=['limit','count','set','Content-Range','apply','reject','update','destroy','then','end','error','stack','name','send','index','map','SmsApplication','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','merge','VIRTUAL','options','include','findAll','catch','show','params','includeAll','create','body','find','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','to-csv','fs-extra','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined'];(function(_0x3d8251,_0x435dbf){var _0x2ed649=function(_0x229898){while(--_0x229898){_0x3d8251['push'](_0x3d8251['shift']());}};_0x2ed649(++_0x435dbf);}(_0xf7cc,0x167));var _0xcf7c=function(_0x4b369d,_0x265eb8){_0x4b369d=_0x4b369d-0x0;var _0x571a98=_0xf7cc[_0x4b369d];return _0x571a98;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xcf7c('0x0'));var zipdir=require(_0xcf7c('0x1'));var jsonpatch=require(_0xcf7c('0x2'));var rp=require(_0xcf7c('0x3'));var moment=require(_0xcf7c('0x4'));var BPromise=require(_0xcf7c('0x5'));var Mustache=require('mustache');var util=require(_0xcf7c('0x6'));var path=require(_0xcf7c('0x7'));var sox=require('sox');var csv=require(_0xcf7c('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xcf7c('0x9'));var _=require('lodash');var squel=require(_0xcf7c('0xa'));var crypto=require(_0xcf7c('0xb'));var jsforce=require(_0xcf7c('0xc'));var deskjs=require('desk.js');var toCsv=require(_0xcf7c('0x8'));var querystring=require(_0xcf7c('0xd'));var Papa=require(_0xcf7c('0xe'));var Redis=require(_0xcf7c('0xf'));var authService=require(_0xcf7c('0x10'));var qs=require(_0xcf7c('0x11'));var as=require(_0xcf7c('0x12'));var hardwareService=require(_0xcf7c('0x13'));var logger=require(_0xcf7c('0x14'))(_0xcf7c('0x15'));var utils=require(_0xcf7c('0x16'));var config=require(_0xcf7c('0x17'));var licenseUtil=require(_0xcf7c('0x18'));var db=require(_0xcf7c('0x19'))['db'];function respondWithStatusCode(_0x3a09a1,_0x47cbf3){_0x47cbf3=_0x47cbf3||0xcc;return function(_0x5b3248){if(_0x5b3248){return _0x3a09a1[_0xcf7c('0x1a')](_0x47cbf3);}return _0x3a09a1[_0xcf7c('0x1b')](_0x47cbf3)['end']();};}function respondWithResult(_0x2fe120,_0x1badfe){_0x1badfe=_0x1badfe||0xc8;return function(_0x2d852a){if(_0x2d852a){return _0x2fe120[_0xcf7c('0x1b')](_0x1badfe)[_0xcf7c('0x1c')](_0x2d852a);}};}function respondWithFilteredResult(_0xc8c43e,_0x513f20){return function(_0x2d422e){if(_0x2d422e){var _0x52af23=typeof _0x513f20[_0xcf7c('0x1d')]===_0xcf7c('0x1e')&&typeof _0x513f20[_0xcf7c('0x1f')]==='undefined';var _0x1c525d=_0x2d422e[_0xcf7c('0x20')];var _0x593307=_0x52af23?0x0:_0x513f20[_0xcf7c('0x1d')];var _0x4202f4=_0x52af23?_0x2d422e['count']:_0x513f20[_0xcf7c('0x1d')]+_0x513f20[_0xcf7c('0x1f')];var _0x5d400e;if(_0x4202f4>=_0x1c525d){_0x4202f4=_0x1c525d;_0x5d400e=0xc8;}else{_0x5d400e=0xce;}_0xc8c43e[_0xcf7c('0x1b')](_0x5d400e);return _0xc8c43e[_0xcf7c('0x21')](_0xcf7c('0x22'),_0x593307+'-'+_0x4202f4+'/'+_0x1c525d)['json'](_0x2d422e);}return null;};}function patchUpdates(_0x21fb2c){return function(_0x541412){try{jsonpatch[_0xcf7c('0x23')](_0x541412,_0x21fb2c,!![]);}catch(_0x47e7b2){return BPromise[_0xcf7c('0x24')](_0x47e7b2);}return _0x541412['save']();};}function saveUpdates(_0x35b3fb,_0x28b517){return function(_0x4cab9c){if(_0x4cab9c){return _0x4cab9c[_0xcf7c('0x25')](_0x35b3fb)['then'](function(_0x59b0c1){return _0x59b0c1;});}return null;};}function removeEntity(_0x3e300b,_0x1f7fef){return function(_0x30f94a){if(_0x30f94a){return _0x30f94a[_0xcf7c('0x26')]()[_0xcf7c('0x27')](function(){_0x3e300b['status'](0xcc)[_0xcf7c('0x28')]();});}};}function handleEntityNotFound(_0x1de6b2,_0x34c4a1){return function(_0x23a25f){if(!_0x23a25f){_0x1de6b2['sendStatus'](0x194);}return _0x23a25f;};}function handleError(_0x37e033,_0x5e3cbe){_0x5e3cbe=_0x5e3cbe||0x1f4;return function(_0x54b692){logger[_0xcf7c('0x29')](_0x54b692[_0xcf7c('0x2a')]);if(_0x54b692[_0xcf7c('0x2b')]){delete _0x54b692[_0xcf7c('0x2b')];}_0x37e033[_0xcf7c('0x1b')](_0x5e3cbe)[_0xcf7c('0x2c')](_0x54b692);};}exports[_0xcf7c('0x2d')]=function(_0x26af32,_0x505e99){var _0x9e44ba={},_0xe296b8={},_0x348d0d={'count':0x0,'rows':[]};var _0x186ff2=_[_0xcf7c('0x2e')](db[_0xcf7c('0x2f')][_0xcf7c('0x30')],function(_0x44b122){return{'name':_0x44b122[_0xcf7c('0x31')],'type':_0x44b122[_0xcf7c('0x32')][_0xcf7c('0x33')]};});_0xe296b8[_0xcf7c('0x34')]=_['map'](_0x186ff2,'name');_0xe296b8[_0xcf7c('0x35')]=_[_0xcf7c('0x36')](_0x26af32[_0xcf7c('0x35')]);_0xe296b8[_0xcf7c('0x37')]=_[_0xcf7c('0x38')](_0xe296b8[_0xcf7c('0x34')],_0xe296b8[_0xcf7c('0x35')]);_0x9e44ba[_0xcf7c('0x39')]=_[_0xcf7c('0x38')](_0xe296b8[_0xcf7c('0x34')],qs['fields'](_0x26af32[_0xcf7c('0x35')][_0xcf7c('0x3a')]));_0x9e44ba['attributes']=_0x9e44ba[_0xcf7c('0x39')][_0xcf7c('0x3b')]?_0x9e44ba['attributes']:_0xe296b8[_0xcf7c('0x34')];if(!_0x26af32[_0xcf7c('0x35')][_0xcf7c('0x3c')](_0xcf7c('0x3d'))){_0x9e44ba[_0xcf7c('0x1f')]=qs[_0xcf7c('0x1f')](_0x26af32['query'][_0xcf7c('0x1f')]);_0x9e44ba['offset']=qs[_0xcf7c('0x1d')](_0x26af32['query']['offset']);}_0x9e44ba[_0xcf7c('0x3e')]=qs[_0xcf7c('0x3f')](_0x26af32[_0xcf7c('0x35')][_0xcf7c('0x3f')]);_0x9e44ba['where']=qs['filters'](_[_0xcf7c('0x40')](_0x26af32[_0xcf7c('0x35')],_0xe296b8[_0xcf7c('0x37')]),_0x186ff2);if(_0x26af32[_0xcf7c('0x35')][_0xcf7c('0x41')]){_0x9e44ba['where']=_[_0xcf7c('0x42')](_0x9e44ba['where'],{'$or':_[_0xcf7c('0x2e')](_0x186ff2,function(_0x2e407a){if(_0x2e407a[_0xcf7c('0x32')]!==_0xcf7c('0x43')){var _0x42725d={};_0x42725d[_0x2e407a[_0xcf7c('0x2b')]]={'$like':'%'+_0x26af32['query'][_0xcf7c('0x41')]+'%'};return _0x42725d;}})});}_0x9e44ba=_['merge']({},_0x9e44ba,_0x26af32[_0xcf7c('0x44')]);var _0x120159={'where':_0x9e44ba['where']};return db[_0xcf7c('0x2f')][_0xcf7c('0x20')](_0x120159)[_0xcf7c('0x27')](function(_0x3154ef){_0x348d0d[_0xcf7c('0x20')]=_0x3154ef;if(_0x26af32[_0xcf7c('0x35')]['includeAll']){_0x9e44ba[_0xcf7c('0x45')]=[{'all':!![]}];}return db[_0xcf7c('0x2f')][_0xcf7c('0x46')](_0x9e44ba);})[_0xcf7c('0x27')](function(_0x3aef57){_0x348d0d['rows']=_0x3aef57;return _0x348d0d;})['then'](respondWithFilteredResult(_0x505e99,_0x9e44ba))[_0xcf7c('0x47')](handleError(_0x505e99,null));};exports[_0xcf7c('0x48')]=function(_0x316822,_0x3a73d5){var _0x5df8c3={'raw':!![],'where':{'id':_0x316822[_0xcf7c('0x49')]['id']}},_0x313bf5={};_0x313bf5['model']=_['keys'](db['SmsApplication'][_0xcf7c('0x30')]);_0x313bf5[_0xcf7c('0x35')]=_[_0xcf7c('0x36')](_0x316822['query']);_0x313bf5[_0xcf7c('0x37')]=_[_0xcf7c('0x38')](_0x313bf5[_0xcf7c('0x34')],_0x313bf5[_0xcf7c('0x35')]);_0x5df8c3['attributes']=_[_0xcf7c('0x38')](_0x313bf5[_0xcf7c('0x34')],qs[_0xcf7c('0x3a')](_0x316822['query']['fields']));_0x5df8c3[_0xcf7c('0x39')]=_0x5df8c3[_0xcf7c('0x39')][_0xcf7c('0x3b')]?_0x5df8c3[_0xcf7c('0x39')]:_0x313bf5[_0xcf7c('0x34')];if(_0x316822[_0xcf7c('0x35')][_0xcf7c('0x4a')]){_0x5df8c3['include']=[{'all':!![]}];}_0x5df8c3=_['merge']({},_0x5df8c3,_0x316822[_0xcf7c('0x44')]);return db['SmsApplication']['find'](_0x5df8c3)[_0xcf7c('0x27')](handleEntityNotFound(_0x3a73d5,null))[_0xcf7c('0x27')](respondWithResult(_0x3a73d5,null))[_0xcf7c('0x47')](handleError(_0x3a73d5,null));};exports[_0xcf7c('0x4b')]=function(_0x136c76,_0x695b80){return db[_0xcf7c('0x2f')][_0xcf7c('0x4b')](_0x136c76['body'],{})[_0xcf7c('0x27')](respondWithResult(_0x695b80,0xc9))[_0xcf7c('0x47')](handleError(_0x695b80,null));};exports[_0xcf7c('0x25')]=function(_0x317b07,_0x2c1013){if(_0x317b07[_0xcf7c('0x4c')]['id']){delete _0x317b07['body']['id'];}return db[_0xcf7c('0x2f')]['find']({'where':{'id':_0x317b07[_0xcf7c('0x49')]['id']}})['then'](handleEntityNotFound(_0x2c1013,null))[_0xcf7c('0x27')](saveUpdates(_0x317b07['body'],null))[_0xcf7c('0x27')](respondWithResult(_0x2c1013,null))['catch'](handleError(_0x2c1013,null));};exports['destroy']=function(_0x2a265c,_0x557db0){return db[_0xcf7c('0x2f')][_0xcf7c('0x4d')]({'where':{'id':_0x2a265c[_0xcf7c('0x49')]['id']}})[_0xcf7c('0x27')](handleEntityNotFound(_0x557db0,null))[_0xcf7c('0x27')](removeEntity(_0x557db0,null))[_0xcf7c('0x47')](handleError(_0x557db0,null));};