Built motion from commit eddce310.|2.6.12
[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 _0x11e7=['to-csv','fs-extra','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','../../config/license/util','../../mysqldb','status','json','offset','limit','count','set','Content-Range','update','then','destroy','end','error','name','send','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','VIRTUAL','options','SmsApplication','includeAll','include','findAll','catch','show','params','find','create','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util'];(function(_0x2e75af,_0x238d0f){var _0xee7299=function(_0x4487f7){while(--_0x4487f7){_0x2e75af['push'](_0x2e75af['shift']());}};_0xee7299(++_0x238d0f);}(_0x11e7,0x1e1));var _0x711e=function(_0x2b5dbd,_0xf786ac){_0x2b5dbd=_0x2b5dbd-0x0;var _0x4d39d7=_0x11e7[_0x2b5dbd];return _0x4d39d7;};'use strict';var emlformat=require(_0x711e('0x0'));var rimraf=require(_0x711e('0x1'));var zipdir=require(_0x711e('0x2'));var jsonpatch=require(_0x711e('0x3'));var rp=require(_0x711e('0x4'));var moment=require(_0x711e('0x5'));var BPromise=require(_0x711e('0x6'));var Mustache=require(_0x711e('0x7'));var util=require(_0x711e('0x8'));var path=require('path');var sox=require('sox');var csv=require(_0x711e('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x711e('0xa'));var _=require(_0x711e('0xb'));var squel=require(_0x711e('0xc'));var crypto=require('crypto');var jsforce=require(_0x711e('0xd'));var deskjs=require(_0x711e('0xe'));var toCsv=require('to-csv');var querystring=require(_0x711e('0xf'));var Papa=require(_0x711e('0x10'));var Redis=require(_0x711e('0x11'));var authService=require(_0x711e('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x711e('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x711e('0x14'))('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x711e('0x15'));var db=require(_0x711e('0x16'))['db'];function respondWithStatusCode(_0x28c654,_0xf852c7){_0xf852c7=_0xf852c7||0xcc;return function(_0x16fddc){if(_0x16fddc){return _0x28c654['sendStatus'](_0xf852c7);}return _0x28c654[_0x711e('0x17')](_0xf852c7)['end']();};}function respondWithResult(_0x584d04,_0x3fafd2){_0x3fafd2=_0x3fafd2||0xc8;return function(_0x27d658){if(_0x27d658){return _0x584d04[_0x711e('0x17')](_0x3fafd2)[_0x711e('0x18')](_0x27d658);}};}function respondWithFilteredResult(_0x5b4c03,_0x294cce){return function(_0x137c65){if(_0x137c65){var _0x36cec7=typeof _0x294cce[_0x711e('0x19')]==='undefined'&&typeof _0x294cce[_0x711e('0x1a')]==='undefined';var _0x54e812=_0x137c65[_0x711e('0x1b')];var _0x2d2be4=_0x36cec7?0x0:_0x294cce[_0x711e('0x19')];var _0x32ab8b=_0x36cec7?_0x137c65[_0x711e('0x1b')]:_0x294cce[_0x711e('0x19')]+_0x294cce[_0x711e('0x1a')];var _0x7bf5cb;if(_0x32ab8b>=_0x54e812){_0x32ab8b=_0x54e812;_0x7bf5cb=0xc8;}else{_0x7bf5cb=0xce;}_0x5b4c03[_0x711e('0x17')](_0x7bf5cb);return _0x5b4c03[_0x711e('0x1c')](_0x711e('0x1d'),_0x2d2be4+'-'+_0x32ab8b+'/'+_0x54e812)[_0x711e('0x18')](_0x137c65);}return null;};}function patchUpdates(_0x776d61){return function(_0x351667){try{jsonpatch['apply'](_0x351667,_0x776d61,!![]);}catch(_0x36f4d2){return BPromise['reject'](_0x36f4d2);}return _0x351667['save']();};}function saveUpdates(_0x29190e,_0x3a4e2d){return function(_0xe9da6f){if(_0xe9da6f){return _0xe9da6f[_0x711e('0x1e')](_0x29190e)[_0x711e('0x1f')](function(_0x5ae394){return _0x5ae394;});}return null;};}function removeEntity(_0x3d4eec,_0x2c4fdb){return function(_0x32f008){if(_0x32f008){return _0x32f008[_0x711e('0x20')]()[_0x711e('0x1f')](function(){_0x3d4eec['status'](0xcc)[_0x711e('0x21')]();});}};}function handleEntityNotFound(_0x49abe5,_0x59b947){return function(_0x5ba616){if(!_0x5ba616){_0x49abe5['sendStatus'](0x194);}return _0x5ba616;};}function handleError(_0x568f83,_0x27da8c){_0x27da8c=_0x27da8c||0x1f4;return function(_0x56e2fc){logger[_0x711e('0x22')](_0x56e2fc['stack']);if(_0x56e2fc[_0x711e('0x23')]){delete _0x56e2fc['name'];}_0x568f83[_0x711e('0x17')](_0x27da8c)[_0x711e('0x24')](_0x56e2fc);};}exports[_0x711e('0x25')]=function(_0x225b8b,_0x37f6be){var _0x9e8674={},_0x2e2c47={},_0x4a03f9={'count':0x0,'rows':[]};var _0x4f9b4d=_[_0x711e('0x26')](db['SmsApplication'][_0x711e('0x27')],function(_0x29a090){return{'name':_0x29a090[_0x711e('0x28')],'type':_0x29a090[_0x711e('0x29')][_0x711e('0x2a')]};});_0x2e2c47[_0x711e('0x2b')]=_[_0x711e('0x26')](_0x4f9b4d,_0x711e('0x23'));_0x2e2c47[_0x711e('0x2c')]=_[_0x711e('0x2d')](_0x225b8b[_0x711e('0x2c')]);_0x2e2c47[_0x711e('0x2e')]=_[_0x711e('0x2f')](_0x2e2c47[_0x711e('0x2b')],_0x2e2c47['query']);_0x9e8674['attributes']=_[_0x711e('0x2f')](_0x2e2c47[_0x711e('0x2b')],qs[_0x711e('0x30')](_0x225b8b[_0x711e('0x2c')][_0x711e('0x30')]));_0x9e8674[_0x711e('0x31')]=_0x9e8674[_0x711e('0x31')][_0x711e('0x32')]?_0x9e8674[_0x711e('0x31')]:_0x2e2c47[_0x711e('0x2b')];if(!_0x225b8b['query'][_0x711e('0x33')](_0x711e('0x34'))){_0x9e8674['limit']=qs[_0x711e('0x1a')](_0x225b8b[_0x711e('0x2c')]['limit']);_0x9e8674[_0x711e('0x19')]=qs[_0x711e('0x19')](_0x225b8b[_0x711e('0x2c')]['offset']);}_0x9e8674['order']=qs[_0x711e('0x35')](_0x225b8b[_0x711e('0x2c')][_0x711e('0x35')]);_0x9e8674[_0x711e('0x36')]=qs[_0x711e('0x2e')](_[_0x711e('0x37')](_0x225b8b[_0x711e('0x2c')],_0x2e2c47[_0x711e('0x2e')]),_0x4f9b4d);if(_0x225b8b[_0x711e('0x2c')][_0x711e('0x38')]){_0x9e8674['where']=_[_0x711e('0x39')](_0x9e8674[_0x711e('0x36')],{'$or':_[_0x711e('0x26')](_0x4f9b4d,function(_0x201d29){if(_0x201d29[_0x711e('0x29')]!==_0x711e('0x3a')){var _0x15917e={};_0x15917e[_0x201d29[_0x711e('0x23')]]={'$like':'%'+_0x225b8b['query'][_0x711e('0x38')]+'%'};return _0x15917e;}})});}_0x9e8674=_[_0x711e('0x39')]({},_0x9e8674,_0x225b8b[_0x711e('0x3b')]);var _0x2987fb={'where':_0x9e8674[_0x711e('0x36')]};return db[_0x711e('0x3c')]['count'](_0x2987fb)[_0x711e('0x1f')](function(_0x1a74cf){_0x4a03f9[_0x711e('0x1b')]=_0x1a74cf;if(_0x225b8b[_0x711e('0x2c')][_0x711e('0x3d')]){_0x9e8674[_0x711e('0x3e')]=[{'all':!![]}];}return db['SmsApplication'][_0x711e('0x3f')](_0x9e8674);})[_0x711e('0x1f')](function(_0x527538){_0x4a03f9['rows']=_0x527538;return _0x4a03f9;})['then'](respondWithFilteredResult(_0x37f6be,_0x9e8674))[_0x711e('0x40')](handleError(_0x37f6be,null));};exports[_0x711e('0x41')]=function(_0x39b959,_0x2402d){var _0x1da06c={'raw':!![],'where':{'id':_0x39b959[_0x711e('0x42')]['id']}},_0x3a91d7={};_0x3a91d7[_0x711e('0x2b')]=_[_0x711e('0x2d')](db[_0x711e('0x3c')]['rawAttributes']);_0x3a91d7['query']=_[_0x711e('0x2d')](_0x39b959[_0x711e('0x2c')]);_0x3a91d7[_0x711e('0x2e')]=_[_0x711e('0x2f')](_0x3a91d7[_0x711e('0x2b')],_0x3a91d7[_0x711e('0x2c')]);_0x1da06c[_0x711e('0x31')]=_[_0x711e('0x2f')](_0x3a91d7['model'],qs[_0x711e('0x30')](_0x39b959[_0x711e('0x2c')][_0x711e('0x30')]));_0x1da06c['attributes']=_0x1da06c[_0x711e('0x31')][_0x711e('0x32')]?_0x1da06c['attributes']:_0x3a91d7['model'];if(_0x39b959['query'][_0x711e('0x3d')]){_0x1da06c[_0x711e('0x3e')]=[{'all':!![]}];}_0x1da06c=_['merge']({},_0x1da06c,_0x39b959['options']);return db[_0x711e('0x3c')][_0x711e('0x43')](_0x1da06c)[_0x711e('0x1f')](handleEntityNotFound(_0x2402d,null))[_0x711e('0x1f')](respondWithResult(_0x2402d,null))['catch'](handleError(_0x2402d,null));};exports[_0x711e('0x44')]=function(_0x1f4b3a,_0xb8956){return db['SmsApplication'][_0x711e('0x44')](_0x1f4b3a[_0x711e('0x45')],{})['then'](respondWithResult(_0xb8956,0xc9))[_0x711e('0x40')](handleError(_0xb8956,null));};exports['update']=function(_0x138c63,_0x130660){if(_0x138c63[_0x711e('0x45')]['id']){delete _0x138c63[_0x711e('0x45')]['id'];}return db[_0x711e('0x3c')][_0x711e('0x43')]({'where':{'id':_0x138c63['params']['id']}})[_0x711e('0x1f')](handleEntityNotFound(_0x130660,null))[_0x711e('0x1f')](saveUpdates(_0x138c63['body'],null))['then'](respondWithResult(_0x130660,null))[_0x711e('0x40')](handleError(_0x130660,null));};exports[_0x711e('0x20')]=function(_0x240e06,_0x509c86){return db[_0x711e('0x3c')][_0x711e('0x43')]({'where':{'id':_0x240e06[_0x711e('0x42')]['id']}})[_0x711e('0x1f')](handleEntityNotFound(_0x509c86,null))['then'](removeEntity(_0x509c86,null))['catch'](handleError(_0x509c86,null));};