aa3090a1422f25e8c4e2a7005301fa873032f030
[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 _0xb2b7=['status','end','undefined','count','offset','limit','set','Content-Range','json','apply','reject','save','update','then','destroy','stack','name','send','map','SmsApplication','rawAttributes','type','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','rows','catch','params','find','create','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','util','path','sox','to-csv','fs-extra','lodash','crypto','jsforce','desk.js','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','sendStatus'];(function(_0x61e694,_0x51e3c5){var _0x268618=function(_0x473051){while(--_0x473051){_0x61e694['push'](_0x61e694['shift']());}};_0x268618(++_0x51e3c5);}(_0xb2b7,0x78));var _0x7b2b=function(_0x171d17,_0x45d819){_0x171d17=_0x171d17-0x0;var _0x1a7b5b=_0xb2b7[_0x171d17];return _0x1a7b5b;};'use strict';var emlformat=require(_0x7b2b('0x0'));var rimraf=require(_0x7b2b('0x1'));var zipdir=require(_0x7b2b('0x2'));var jsonpatch=require(_0x7b2b('0x3'));var rp=require(_0x7b2b('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x7b2b('0x5'));var util=require(_0x7b2b('0x6'));var path=require(_0x7b2b('0x7'));var sox=require(_0x7b2b('0x8'));var csv=require(_0x7b2b('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x7b2b('0xa'));var _=require(_0x7b2b('0xb'));var squel=require('squel');var crypto=require(_0x7b2b('0xc'));var jsforce=require(_0x7b2b('0xd'));var deskjs=require(_0x7b2b('0xe'));var toCsv=require('to-csv');var querystring=require(_0x7b2b('0xf'));var Papa=require(_0x7b2b('0x10'));var Redis=require(_0x7b2b('0x11'));var authService=require(_0x7b2b('0x12'));var qs=require(_0x7b2b('0x13'));var as=require(_0x7b2b('0x14'));var hardwareService=require(_0x7b2b('0x15'));var logger=require(_0x7b2b('0x16'))(_0x7b2b('0x17'));var utils=require(_0x7b2b('0x18'));var config=require(_0x7b2b('0x19'));var licenseUtil=require(_0x7b2b('0x1a'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x2371ad,_0x73788e){_0x73788e=_0x73788e||0xcc;return function(_0x6e23ad){if(_0x6e23ad){return _0x2371ad[_0x7b2b('0x1b')](_0x73788e);}return _0x2371ad[_0x7b2b('0x1c')](_0x73788e)[_0x7b2b('0x1d')]();};}function respondWithResult(_0x156782,_0x5e24a7){_0x5e24a7=_0x5e24a7||0xc8;return function(_0x2ba2da){if(_0x2ba2da){return _0x156782[_0x7b2b('0x1c')](_0x5e24a7)['json'](_0x2ba2da);}};}function respondWithFilteredResult(_0x5de518,_0x3e9edf){return function(_0x4b437e){if(_0x4b437e){var _0x1cdcf0=typeof _0x3e9edf['offset']===_0x7b2b('0x1e')&&typeof _0x3e9edf['limit']===_0x7b2b('0x1e');var _0x9e604c=_0x4b437e[_0x7b2b('0x1f')];var _0x288fa2=_0x1cdcf0?0x0:_0x3e9edf[_0x7b2b('0x20')];var _0x32619a=_0x1cdcf0?_0x4b437e[_0x7b2b('0x1f')]:_0x3e9edf[_0x7b2b('0x20')]+_0x3e9edf[_0x7b2b('0x21')];var _0x712f25;if(_0x32619a>=_0x9e604c){_0x32619a=_0x9e604c;_0x712f25=0xc8;}else{_0x712f25=0xce;}_0x5de518['status'](_0x712f25);return _0x5de518[_0x7b2b('0x22')](_0x7b2b('0x23'),_0x288fa2+'-'+_0x32619a+'/'+_0x9e604c)[_0x7b2b('0x24')](_0x4b437e);}return null;};}function patchUpdates(_0xf8cac9){return function(_0x47e18b){try{jsonpatch[_0x7b2b('0x25')](_0x47e18b,_0xf8cac9,!![]);}catch(_0x1a3a4a){return BPromise[_0x7b2b('0x26')](_0x1a3a4a);}return _0x47e18b[_0x7b2b('0x27')]();};}function saveUpdates(_0x22f772,_0x46c400){return function(_0x1f3068){if(_0x1f3068){return _0x1f3068[_0x7b2b('0x28')](_0x22f772)[_0x7b2b('0x29')](function(_0x334eda){return _0x334eda;});}return null;};}function removeEntity(_0xb3831d,_0x187c5e){return function(_0x1f6a58){if(_0x1f6a58){return _0x1f6a58[_0x7b2b('0x2a')]()[_0x7b2b('0x29')](function(){_0xb3831d[_0x7b2b('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x41649f,_0xb06bf4){return function(_0x5d3000){if(!_0x5d3000){_0x41649f[_0x7b2b('0x1b')](0x194);}return _0x5d3000;};}function handleError(_0x3a3a60,_0x388695){_0x388695=_0x388695||0x1f4;return function(_0x249406){logger['error'](_0x249406[_0x7b2b('0x2b')]);if(_0x249406[_0x7b2b('0x2c')]){delete _0x249406[_0x7b2b('0x2c')];}_0x3a3a60[_0x7b2b('0x1c')](_0x388695)[_0x7b2b('0x2d')](_0x249406);};}exports['index']=function(_0xceb3b3,_0x1008e1){var _0xd97854={},_0xa0f87c={},_0x2e86e1={'count':0x0,'rows':[]};var _0xc4d6f5=_[_0x7b2b('0x2e')](db[_0x7b2b('0x2f')][_0x7b2b('0x30')],function(_0x53af14){return{'name':_0x53af14['fieldName'],'type':_0x53af14[_0x7b2b('0x31')][_0x7b2b('0x32')]};});_0xa0f87c[_0x7b2b('0x33')]=_[_0x7b2b('0x2e')](_0xc4d6f5,'name');_0xa0f87c[_0x7b2b('0x34')]=_[_0x7b2b('0x35')](_0xceb3b3[_0x7b2b('0x34')]);_0xa0f87c[_0x7b2b('0x36')]=_[_0x7b2b('0x37')](_0xa0f87c[_0x7b2b('0x33')],_0xa0f87c[_0x7b2b('0x34')]);_0xd97854[_0x7b2b('0x38')]=_[_0x7b2b('0x37')](_0xa0f87c['model'],qs[_0x7b2b('0x39')](_0xceb3b3[_0x7b2b('0x34')][_0x7b2b('0x39')]));_0xd97854[_0x7b2b('0x38')]=_0xd97854[_0x7b2b('0x38')]['length']?_0xd97854['attributes']:_0xa0f87c['model'];if(!_0xceb3b3[_0x7b2b('0x34')][_0x7b2b('0x3a')](_0x7b2b('0x3b'))){_0xd97854[_0x7b2b('0x21')]=qs[_0x7b2b('0x21')](_0xceb3b3['query']['limit']);_0xd97854[_0x7b2b('0x20')]=qs[_0x7b2b('0x20')](_0xceb3b3[_0x7b2b('0x34')]['offset']);}_0xd97854['order']=qs[_0x7b2b('0x3c')](_0xceb3b3['query'][_0x7b2b('0x3c')]);_0xd97854[_0x7b2b('0x3d')]=qs[_0x7b2b('0x36')](_[_0x7b2b('0x3e')](_0xceb3b3[_0x7b2b('0x34')],_0xa0f87c['filters']),_0xc4d6f5);if(_0xceb3b3['query'][_0x7b2b('0x3f')]){_0xd97854['where']=_[_0x7b2b('0x40')](_0xd97854[_0x7b2b('0x3d')],{'$or':_['map'](_0xc4d6f5,function(_0x3799b3){if(_0x3799b3['type']!==_0x7b2b('0x41')){var _0x4201fa={};_0x4201fa[_0x3799b3[_0x7b2b('0x2c')]]={'$like':'%'+_0xceb3b3['query'][_0x7b2b('0x3f')]+'%'};return _0x4201fa;}})});}_0xd97854=_[_0x7b2b('0x40')]({},_0xd97854,_0xceb3b3['options']);var _0x3034ea={'where':_0xd97854[_0x7b2b('0x3d')]};return db[_0x7b2b('0x2f')]['count'](_0x3034ea)[_0x7b2b('0x29')](function(_0x5bad05){_0x2e86e1[_0x7b2b('0x1f')]=_0x5bad05;if(_0xceb3b3[_0x7b2b('0x34')][_0x7b2b('0x42')]){_0xd97854[_0x7b2b('0x43')]=[{'all':!![]}];}return db[_0x7b2b('0x2f')]['findAll'](_0xd97854);})[_0x7b2b('0x29')](function(_0xb2791){_0x2e86e1[_0x7b2b('0x44')]=_0xb2791;return _0x2e86e1;})[_0x7b2b('0x29')](respondWithFilteredResult(_0x1008e1,_0xd97854))[_0x7b2b('0x45')](handleError(_0x1008e1,null));};exports['show']=function(_0x23d0d1,_0x5adf32){var _0x1aa3a7={'raw':!![],'where':{'id':_0x23d0d1[_0x7b2b('0x46')]['id']}},_0x2f857f={};_0x2f857f['model']=_[_0x7b2b('0x35')](db[_0x7b2b('0x2f')]['rawAttributes']);_0x2f857f[_0x7b2b('0x34')]=_['keys'](_0x23d0d1[_0x7b2b('0x34')]);_0x2f857f[_0x7b2b('0x36')]=_[_0x7b2b('0x37')](_0x2f857f[_0x7b2b('0x33')],_0x2f857f['query']);_0x1aa3a7[_0x7b2b('0x38')]=_[_0x7b2b('0x37')](_0x2f857f[_0x7b2b('0x33')],qs[_0x7b2b('0x39')](_0x23d0d1[_0x7b2b('0x34')][_0x7b2b('0x39')]));_0x1aa3a7[_0x7b2b('0x38')]=_0x1aa3a7[_0x7b2b('0x38')]['length']?_0x1aa3a7['attributes']:_0x2f857f[_0x7b2b('0x33')];if(_0x23d0d1[_0x7b2b('0x34')][_0x7b2b('0x42')]){_0x1aa3a7['include']=[{'all':!![]}];}_0x1aa3a7=_['merge']({},_0x1aa3a7,_0x23d0d1['options']);return db[_0x7b2b('0x2f')][_0x7b2b('0x47')](_0x1aa3a7)['then'](handleEntityNotFound(_0x5adf32,null))[_0x7b2b('0x29')](respondWithResult(_0x5adf32,null))[_0x7b2b('0x45')](handleError(_0x5adf32,null));};exports[_0x7b2b('0x48')]=function(_0x46d791,_0x196988){return db['SmsApplication'][_0x7b2b('0x48')](_0x46d791[_0x7b2b('0x49')],{})[_0x7b2b('0x29')](respondWithResult(_0x196988,0xc9))[_0x7b2b('0x45')](handleError(_0x196988,null));};exports['update']=function(_0x1cb6b8,_0x2d80bb){if(_0x1cb6b8[_0x7b2b('0x49')]['id']){delete _0x1cb6b8['body']['id'];}return db[_0x7b2b('0x2f')]['find']({'where':{'id':_0x1cb6b8[_0x7b2b('0x46')]['id']}})[_0x7b2b('0x29')](handleEntityNotFound(_0x2d80bb,null))[_0x7b2b('0x29')](saveUpdates(_0x1cb6b8[_0x7b2b('0x49')],null))['then'](respondWithResult(_0x2d80bb,null))[_0x7b2b('0x45')](handleError(_0x2d80bb,null));};exports[_0x7b2b('0x2a')]=function(_0x3b22ac,_0x48bc3e){return db[_0x7b2b('0x2f')][_0x7b2b('0x47')]({'where':{'id':_0x3b22ac[_0x7b2b('0x46')]['id']}})['then'](handleEntityNotFound(_0x48bc3e,null))[_0x7b2b('0x29')](removeEntity(_0x48bc3e,null))[_0x7b2b('0x45')](handleError(_0x48bc3e,null));};