Built motion from commit (unavailable).|2.5.3
[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 _0xfef3=['jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','sendStatus','status','count','offset','limit','set','json','apply','reject','save','update','then','destroy','error','stack','name','SmsApplication','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','fields','length','nolimit','order','sort','where','pick','filters','filter','map','VIRTUAL','merge','options','includeAll','include','findAll','catch','show','params','find','create','body','html-pdf','rimraf','fast-json-patch','request-promise','bluebird','mustache','path','sox','ejs','lodash','squel','crypto'];(function(_0x3d38ae,_0x51102b){var _0x3757ee=function(_0x22bac8){while(--_0x22bac8){_0x3d38ae['push'](_0x3d38ae['shift']());}};_0x3757ee(++_0x51102b);}(_0xfef3,0x118));var _0x3fef=function(_0x132399,_0x1c4b0f){_0x132399=_0x132399-0x0;var _0x2a27e9=_0xfef3[_0x132399];return _0x2a27e9;};'use strict';var pdf=require(_0x3fef('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x3fef('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x3fef('0x2'));var rp=require(_0x3fef('0x3'));var moment=require('moment');var BPromise=require(_0x3fef('0x4'));var Mustache=require(_0x3fef('0x5'));var util=require('util');var path=require(_0x3fef('0x6'));var sox=require(_0x3fef('0x7'));var csv=require('to-csv');var ejs=require(_0x3fef('0x8'));var fs=require('fs');var _=require(_0x3fef('0x9'));var squel=require(_0x3fef('0xa'));var crypto=require(_0x3fef('0xb'));var jsforce=require(_0x3fef('0xc'));var deskjs=require(_0x3fef('0xd'));var toCsv=require(_0x3fef('0xe'));var querystring=require(_0x3fef('0xf'));var Papa=require(_0x3fef('0x10'));var Redis=require(_0x3fef('0x11'));var authService=require(_0x3fef('0x12'));var qs=require(_0x3fef('0x13'));var as=require(_0x3fef('0x14'));var hardwareService=require(_0x3fef('0x15'));var logger=require('../../config/logger')(_0x3fef('0x16'));var utils=require(_0x3fef('0x17'));var config=require(_0x3fef('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1c20b3,_0x4c4a47){_0x4c4a47=_0x4c4a47||0xcc;return function(_0x2c99ff){if(_0x2c99ff){return _0x1c20b3[_0x3fef('0x19')](_0x4c4a47);}return _0x1c20b3[_0x3fef('0x1a')](_0x4c4a47)['end']();};}function respondWithResult(_0x42c3d2,_0x4be62f){_0x4be62f=_0x4be62f||0xc8;return function(_0x15b757){if(_0x15b757){return _0x42c3d2[_0x3fef('0x1a')](_0x4be62f)['json'](_0x15b757);}};}function respondWithFilteredResult(_0x2dec1b,_0x177e28){return function(_0x40b479){if(_0x40b479){var _0x79b617=_0x40b479[_0x3fef('0x1b')],_0x395df0=_0x177e28[_0x3fef('0x1c')],_0x2af1ba=_0x177e28[_0x3fef('0x1c')]+_0x177e28[_0x3fef('0x1d')],_0x5c899f;if(_0x2af1ba>=_0x79b617){_0x2af1ba=_0x79b617;_0x5c899f=0xc8;}else{_0x5c899f=0xce;}_0x2dec1b[_0x3fef('0x1a')](_0x5c899f);return _0x2dec1b[_0x3fef('0x1e')]('Content-Range',_0x395df0+'-'+_0x2af1ba+'/'+_0x79b617)[_0x3fef('0x1f')](_0x40b479);}return null;};}function patchUpdates(_0x3eb287){return function(_0x53d4fd){try{jsonpatch[_0x3fef('0x20')](_0x53d4fd,_0x3eb287,!![]);}catch(_0x51a554){return BPromise[_0x3fef('0x21')](_0x51a554);}return _0x53d4fd[_0x3fef('0x22')]();};}function saveUpdates(_0x245332,_0x2b5226){return function(_0x451d11){if(_0x451d11){return _0x451d11[_0x3fef('0x23')](_0x245332)[_0x3fef('0x24')](function(_0xd64bf4){return _0xd64bf4;});}return null;};}function removeEntity(_0x1f5aaf,_0x3bb110){return function(_0x2eb578){if(_0x2eb578){return _0x2eb578[_0x3fef('0x25')]()[_0x3fef('0x24')](function(){_0x1f5aaf['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x50025f,_0x378b03){return function(_0x3ba38d){if(!_0x3ba38d){_0x50025f[_0x3fef('0x19')](0x194);}return _0x3ba38d;};}function handleError(_0x5f047c,_0x4d462c){_0x4d462c=_0x4d462c||0x1f4;return function(_0x56c542){logger[_0x3fef('0x26')](_0x56c542[_0x3fef('0x27')]);if(_0x56c542[_0x3fef('0x28')]){delete _0x56c542[_0x3fef('0x28')];}_0x5f047c[_0x3fef('0x1a')](_0x4d462c)['send'](_0x56c542);};}exports['index']=function(_0x563556,_0x121ff0){var _0x3baa52={},_0x4ea2ab={},_0x462ee7={'count':0x0,'rows':[]};var _0x6d08cd=_['map'](db[_0x3fef('0x29')][_0x3fef('0x2a')],function(_0xf892bb){return{'name':_0xf892bb[_0x3fef('0x2b')],'type':_0xf892bb[_0x3fef('0x2c')][_0x3fef('0x2d')]};});_0x4ea2ab[_0x3fef('0x2e')]=_['map'](_0x6d08cd,_0x3fef('0x28'));_0x4ea2ab[_0x3fef('0x2f')]=_[_0x3fef('0x30')](_0x563556[_0x3fef('0x2f')]);_0x4ea2ab['filters']=_[_0x3fef('0x31')](_0x4ea2ab['model'],_0x4ea2ab[_0x3fef('0x2f')]);_0x3baa52[_0x3fef('0x32')]=_[_0x3fef('0x31')](_0x4ea2ab[_0x3fef('0x2e')],qs[_0x3fef('0x33')](_0x563556[_0x3fef('0x2f')][_0x3fef('0x33')]));_0x3baa52[_0x3fef('0x32')]=_0x3baa52[_0x3fef('0x32')][_0x3fef('0x34')]?_0x3baa52['attributes']:_0x4ea2ab['model'];if(!_0x563556[_0x3fef('0x2f')]['hasOwnProperty'](_0x3fef('0x35'))){_0x3baa52[_0x3fef('0x1d')]=qs[_0x3fef('0x1d')](_0x563556[_0x3fef('0x2f')][_0x3fef('0x1d')]);_0x3baa52[_0x3fef('0x1c')]=qs[_0x3fef('0x1c')](_0x563556[_0x3fef('0x2f')][_0x3fef('0x1c')]);}_0x3baa52[_0x3fef('0x36')]=qs[_0x3fef('0x37')](_0x563556[_0x3fef('0x2f')][_0x3fef('0x37')]);_0x3baa52[_0x3fef('0x38')]=qs['filters'](_[_0x3fef('0x39')](_0x563556[_0x3fef('0x2f')],_0x4ea2ab[_0x3fef('0x3a')]),_0x6d08cd);if(_0x563556[_0x3fef('0x2f')][_0x3fef('0x3b')]){_0x3baa52[_0x3fef('0x38')]=_['merge'](_0x3baa52['where'],{'$or':_[_0x3fef('0x3c')](_0x6d08cd,function(_0x163de0){if(_0x163de0[_0x3fef('0x2c')]!==_0x3fef('0x3d')){var _0x69e494={};_0x69e494[_0x163de0[_0x3fef('0x28')]]={'$like':'%'+_0x563556[_0x3fef('0x2f')][_0x3fef('0x3b')]+'%'};return _0x69e494;}})});}_0x3baa52=_[_0x3fef('0x3e')]({},_0x3baa52,_0x563556[_0x3fef('0x3f')]);var _0x391053={'where':_0x3baa52['where']};return db[_0x3fef('0x29')][_0x3fef('0x1b')](_0x391053)['then'](function(_0x54e329){_0x462ee7[_0x3fef('0x1b')]=_0x54e329;if(_0x563556[_0x3fef('0x2f')][_0x3fef('0x40')]){_0x3baa52[_0x3fef('0x41')]=[{'all':!![]}];}return db[_0x3fef('0x29')][_0x3fef('0x42')](_0x3baa52);})[_0x3fef('0x24')](function(_0x42e43d){_0x462ee7['rows']=_0x42e43d;return _0x462ee7;})[_0x3fef('0x24')](respondWithFilteredResult(_0x121ff0,_0x3baa52))[_0x3fef('0x43')](handleError(_0x121ff0,null));};exports[_0x3fef('0x44')]=function(_0x3dceed,_0x1fe9ee){var _0x2143ec={'raw':!![],'where':{'id':_0x3dceed[_0x3fef('0x45')]['id']}},_0x545154={};_0x545154[_0x3fef('0x2e')]=_[_0x3fef('0x30')](db[_0x3fef('0x29')][_0x3fef('0x2a')]);_0x545154[_0x3fef('0x2f')]=_[_0x3fef('0x30')](_0x3dceed[_0x3fef('0x2f')]);_0x545154['filters']=_[_0x3fef('0x31')](_0x545154[_0x3fef('0x2e')],_0x545154[_0x3fef('0x2f')]);_0x2143ec[_0x3fef('0x32')]=_[_0x3fef('0x31')](_0x545154[_0x3fef('0x2e')],qs['fields'](_0x3dceed[_0x3fef('0x2f')]['fields']));_0x2143ec[_0x3fef('0x32')]=_0x2143ec[_0x3fef('0x32')]['length']?_0x2143ec[_0x3fef('0x32')]:_0x545154['model'];if(_0x3dceed[_0x3fef('0x2f')][_0x3fef('0x40')]){_0x2143ec[_0x3fef('0x41')]=[{'all':!![]}];}_0x2143ec=_[_0x3fef('0x3e')]({},_0x2143ec,_0x3dceed[_0x3fef('0x3f')]);return db[_0x3fef('0x29')][_0x3fef('0x46')](_0x2143ec)[_0x3fef('0x24')](handleEntityNotFound(_0x1fe9ee,null))[_0x3fef('0x24')](respondWithResult(_0x1fe9ee,null))[_0x3fef('0x43')](handleError(_0x1fe9ee,null));};exports[_0x3fef('0x47')]=function(_0x3e96c9,_0xce173f){return db['SmsApplication'][_0x3fef('0x47')](_0x3e96c9[_0x3fef('0x48')],{})['then'](respondWithResult(_0xce173f,0xc9))[_0x3fef('0x43')](handleError(_0xce173f,null));};exports[_0x3fef('0x23')]=function(_0x2f00c0,_0x505680){if(_0x2f00c0[_0x3fef('0x48')]['id']){delete _0x2f00c0[_0x3fef('0x48')]['id'];}return db['SmsApplication'][_0x3fef('0x46')]({'where':{'id':_0x2f00c0['params']['id']}})['then'](handleEntityNotFound(_0x505680,null))[_0x3fef('0x24')](saveUpdates(_0x2f00c0['body'],null))[_0x3fef('0x24')](respondWithResult(_0x505680,null))[_0x3fef('0x43')](handleError(_0x505680,null));};exports['destroy']=function(_0x4535e8,_0x2823f4){return db[_0x3fef('0x29')]['find']({'where':{'id':_0x4535e8[_0x3fef('0x45')]['id']}})[_0x3fef('0x24')](handleEntityNotFound(_0x2823f4,null))[_0x3fef('0x24')](removeEntity(_0x2823f4,null))['catch'](handleError(_0x2823f4,null));};