Built motion from commit 994c64e1.|2.6.1
[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 _0xe565=['find','create','body','params','rimraf','zip-dir','fast-json-patch','moment','bluebird','path','sox','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','undefined','limit','count','offset','set','json','apply','reject','save','update','then','destroy','error','stack','name','send','index','SmsApplication','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','pick','filter','where','merge','includeAll','include','findAll','catch','show','options'];(function(_0x1c8e04,_0x6fb850){var _0x474bd5=function(_0x5d8db8){while(--_0x5d8db8){_0x1c8e04['push'](_0x1c8e04['shift']());}};_0x474bd5(++_0x6fb850);}(_0xe565,0x167));var _0x5e56=function(_0x263cfd,_0x947d90){_0x263cfd=_0x263cfd-0x0;var _0x41add9=_0xe565[_0x263cfd];return _0x41add9;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x5e56('0x0'));var zipdir=require(_0x5e56('0x1'));var jsonpatch=require(_0x5e56('0x2'));var rp=require('request-promise');var moment=require(_0x5e56('0x3'));var BPromise=require(_0x5e56('0x4'));var Mustache=require('mustache');var util=require('util');var path=require(_0x5e56('0x5'));var sox=require(_0x5e56('0x6'));var csv=require(_0x5e56('0x7'));var ejs=require(_0x5e56('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x5e56('0x9'));var crypto=require(_0x5e56('0xa'));var jsforce=require(_0x5e56('0xb'));var deskjs=require(_0x5e56('0xc'));var toCsv=require('to-csv');var querystring=require(_0x5e56('0xd'));var Papa=require(_0x5e56('0xe'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x5e56('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x5e56('0x10'));var logger=require(_0x5e56('0x11'))(_0x5e56('0x12'));var utils=require(_0x5e56('0x13'));var config=require(_0x5e56('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0x5e56('0x15'))['db'];function respondWithStatusCode(_0x4385db,_0x1e7c0c){_0x1e7c0c=_0x1e7c0c||0xcc;return function(_0x54583c){if(_0x54583c){return _0x4385db[_0x5e56('0x16')](_0x1e7c0c);}return _0x4385db[_0x5e56('0x17')](_0x1e7c0c)[_0x5e56('0x18')]();};}function respondWithResult(_0x1f1173,_0x4cb30e){_0x4cb30e=_0x4cb30e||0xc8;return function(_0xf3109){if(_0xf3109){return _0x1f1173[_0x5e56('0x17')](_0x4cb30e)['json'](_0xf3109);}};}function respondWithFilteredResult(_0x410fb8,_0x131578){return function(_0x314e1b){if(_0x314e1b){var _0x5e51cf=typeof _0x131578['offset']===_0x5e56('0x19')&&typeof _0x131578[_0x5e56('0x1a')]===_0x5e56('0x19');var _0x5769a1=_0x314e1b[_0x5e56('0x1b')];var _0x21c5f6=_0x5e51cf?0x0:_0x131578[_0x5e56('0x1c')];var _0x41d177=_0x5e51cf?_0x314e1b['count']:_0x131578[_0x5e56('0x1c')]+_0x131578['limit'];var _0x281286;if(_0x41d177>=_0x5769a1){_0x41d177=_0x5769a1;_0x281286=0xc8;}else{_0x281286=0xce;}_0x410fb8[_0x5e56('0x17')](_0x281286);return _0x410fb8[_0x5e56('0x1d')]('Content-Range',_0x21c5f6+'-'+_0x41d177+'/'+_0x5769a1)[_0x5e56('0x1e')](_0x314e1b);}return null;};}function patchUpdates(_0x1d55a9){return function(_0x5700b4){try{jsonpatch[_0x5e56('0x1f')](_0x5700b4,_0x1d55a9,!![]);}catch(_0x21af67){return BPromise[_0x5e56('0x20')](_0x21af67);}return _0x5700b4[_0x5e56('0x21')]();};}function saveUpdates(_0xb994c,_0x3a8123){return function(_0x43aafc){if(_0x43aafc){return _0x43aafc[_0x5e56('0x22')](_0xb994c)[_0x5e56('0x23')](function(_0x5f2c31){return _0x5f2c31;});}return null;};}function removeEntity(_0x1001a4,_0x3bbd2e){return function(_0x16757a){if(_0x16757a){return _0x16757a[_0x5e56('0x24')]()[_0x5e56('0x23')](function(){_0x1001a4[_0x5e56('0x17')](0xcc)[_0x5e56('0x18')]();});}};}function handleEntityNotFound(_0x18afe9,_0x21b885){return function(_0x3b8541){if(!_0x3b8541){_0x18afe9[_0x5e56('0x16')](0x194);}return _0x3b8541;};}function handleError(_0x1d8db9,_0x54beea){_0x54beea=_0x54beea||0x1f4;return function(_0x1e96d6){logger[_0x5e56('0x25')](_0x1e96d6[_0x5e56('0x26')]);if(_0x1e96d6[_0x5e56('0x27')]){delete _0x1e96d6[_0x5e56('0x27')];}_0x1d8db9['status'](_0x54beea)[_0x5e56('0x28')](_0x1e96d6);};}exports[_0x5e56('0x29')]=function(_0x51485d,_0x3a2dd6){var _0x3f6549={},_0xa582d1={},_0x402af7={'count':0x0,'rows':[]};var _0x535546=_['map'](db[_0x5e56('0x2a')][_0x5e56('0x2b')],function(_0x8639a3){return{'name':_0x8639a3[_0x5e56('0x2c')],'type':_0x8639a3[_0x5e56('0x2d')]['key']};});_0xa582d1[_0x5e56('0x2e')]=_['map'](_0x535546,_0x5e56('0x27'));_0xa582d1[_0x5e56('0x2f')]=_[_0x5e56('0x30')](_0x51485d['query']);_0xa582d1[_0x5e56('0x31')]=_[_0x5e56('0x32')](_0xa582d1[_0x5e56('0x2e')],_0xa582d1['query']);_0x3f6549[_0x5e56('0x33')]=_[_0x5e56('0x32')](_0xa582d1[_0x5e56('0x2e')],qs[_0x5e56('0x34')](_0x51485d['query'][_0x5e56('0x34')]));_0x3f6549[_0x5e56('0x33')]=_0x3f6549['attributes'][_0x5e56('0x35')]?_0x3f6549['attributes']:_0xa582d1['model'];if(!_0x51485d[_0x5e56('0x2f')][_0x5e56('0x36')](_0x5e56('0x37'))){_0x3f6549[_0x5e56('0x1a')]=qs[_0x5e56('0x1a')](_0x51485d[_0x5e56('0x2f')][_0x5e56('0x1a')]);_0x3f6549[_0x5e56('0x1c')]=qs[_0x5e56('0x1c')](_0x51485d['query']['offset']);}_0x3f6549['order']=qs['sort'](_0x51485d[_0x5e56('0x2f')][_0x5e56('0x38')]);_0x3f6549['where']=qs[_0x5e56('0x31')](_[_0x5e56('0x39')](_0x51485d[_0x5e56('0x2f')],_0xa582d1[_0x5e56('0x31')]),_0x535546);if(_0x51485d[_0x5e56('0x2f')][_0x5e56('0x3a')]){_0x3f6549[_0x5e56('0x3b')]=_[_0x5e56('0x3c')](_0x3f6549[_0x5e56('0x3b')],{'$or':_['map'](_0x535546,function(_0x5e7fe1){if(_0x5e7fe1[_0x5e56('0x2d')]!=='VIRTUAL'){var _0x314669={};_0x314669[_0x5e7fe1[_0x5e56('0x27')]]={'$like':'%'+_0x51485d[_0x5e56('0x2f')][_0x5e56('0x3a')]+'%'};return _0x314669;}})});}_0x3f6549=_[_0x5e56('0x3c')]({},_0x3f6549,_0x51485d['options']);var _0x4a01d8={'where':_0x3f6549[_0x5e56('0x3b')]};return db['SmsApplication'][_0x5e56('0x1b')](_0x4a01d8)['then'](function(_0x5f3de8){_0x402af7[_0x5e56('0x1b')]=_0x5f3de8;if(_0x51485d['query'][_0x5e56('0x3d')]){_0x3f6549[_0x5e56('0x3e')]=[{'all':!![]}];}return db[_0x5e56('0x2a')][_0x5e56('0x3f')](_0x3f6549);})[_0x5e56('0x23')](function(_0x1885ad){_0x402af7['rows']=_0x1885ad;return _0x402af7;})[_0x5e56('0x23')](respondWithFilteredResult(_0x3a2dd6,_0x3f6549))[_0x5e56('0x40')](handleError(_0x3a2dd6,null));};exports[_0x5e56('0x41')]=function(_0x2c5461,_0xc41a83){var _0x4d8dff={'raw':!![],'where':{'id':_0x2c5461['params']['id']}},_0x3001cc={};_0x3001cc[_0x5e56('0x2e')]=_[_0x5e56('0x30')](db[_0x5e56('0x2a')][_0x5e56('0x2b')]);_0x3001cc[_0x5e56('0x2f')]=_[_0x5e56('0x30')](_0x2c5461[_0x5e56('0x2f')]);_0x3001cc[_0x5e56('0x31')]=_[_0x5e56('0x32')](_0x3001cc[_0x5e56('0x2e')],_0x3001cc[_0x5e56('0x2f')]);_0x4d8dff['attributes']=_[_0x5e56('0x32')](_0x3001cc[_0x5e56('0x2e')],qs[_0x5e56('0x34')](_0x2c5461[_0x5e56('0x2f')][_0x5e56('0x34')]));_0x4d8dff['attributes']=_0x4d8dff[_0x5e56('0x33')][_0x5e56('0x35')]?_0x4d8dff[_0x5e56('0x33')]:_0x3001cc[_0x5e56('0x2e')];if(_0x2c5461['query']['includeAll']){_0x4d8dff[_0x5e56('0x3e')]=[{'all':!![]}];}_0x4d8dff=_[_0x5e56('0x3c')]({},_0x4d8dff,_0x2c5461[_0x5e56('0x42')]);return db[_0x5e56('0x2a')][_0x5e56('0x43')](_0x4d8dff)[_0x5e56('0x23')](handleEntityNotFound(_0xc41a83,null))['then'](respondWithResult(_0xc41a83,null))['catch'](handleError(_0xc41a83,null));};exports[_0x5e56('0x44')]=function(_0x1aeb3f,_0x2267c1){return db['SmsApplication'][_0x5e56('0x44')](_0x1aeb3f['body'],{})['then'](respondWithResult(_0x2267c1,0xc9))['catch'](handleError(_0x2267c1,null));};exports[_0x5e56('0x22')]=function(_0x3cb5e2,_0xec9ce5){if(_0x3cb5e2[_0x5e56('0x45')]['id']){delete _0x3cb5e2[_0x5e56('0x45')]['id'];}return db[_0x5e56('0x2a')][_0x5e56('0x43')]({'where':{'id':_0x3cb5e2[_0x5e56('0x46')]['id']}})['then'](handleEntityNotFound(_0xec9ce5,null))[_0x5e56('0x23')](saveUpdates(_0x3cb5e2[_0x5e56('0x45')],null))['then'](respondWithResult(_0xec9ce5,null))[_0x5e56('0x40')](handleError(_0xec9ce5,null));};exports['destroy']=function(_0x508df7,_0x3588fa){return db['SmsApplication'][_0x5e56('0x43')]({'where':{'id':_0x508df7[_0x5e56('0x46')]['id']}})['then'](handleEntityNotFound(_0x3588fa,null))[_0x5e56('0x23')](removeEntity(_0x3588fa,null))[_0x5e56('0x40')](handleError(_0x3588fa,null));};