Built motion from commit f7863d46.|2.5.41
[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 _0xeb77=['crypto','jsforce','to-csv','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','sendStatus','status','end','json','undefined','limit','count','offset','set','Content-Range','reject','save','update','then','destroy','error','stack','name','send','index','map','SmsApplication','rawAttributes','fieldName','type','key','model','keys','filters','intersection','query','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','VIRTUAL','options','findAll','catch','show','params','include','find','create','body','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','ejs','fs-extra','lodash','squel'];(function(_0x19dcda,_0x2d21ba){var _0x2c14=function(_0x446cd5){while(--_0x446cd5){_0x19dcda['push'](_0x19dcda['shift']());}};_0x2c14(++_0x2d21ba);}(_0xeb77,0x8b));var _0x7eb7=function(_0x80d733,_0x266211){_0x80d733=_0x80d733-0x0;var _0x435868=_0xeb77[_0x80d733];return _0x435868;};'use strict';var emlformat=require(_0x7eb7('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x7eb7('0x1'));var jsonpatch=require(_0x7eb7('0x2'));var rp=require(_0x7eb7('0x3'));var moment=require(_0x7eb7('0x4'));var BPromise=require(_0x7eb7('0x5'));var Mustache=require(_0x7eb7('0x6'));var util=require('util');var path=require(_0x7eb7('0x7'));var sox=require(_0x7eb7('0x8'));var csv=require('to-csv');var ejs=require(_0x7eb7('0x9'));var fs=require('fs');var fs_extra=require(_0x7eb7('0xa'));var _=require(_0x7eb7('0xb'));var squel=require(_0x7eb7('0xc'));var crypto=require(_0x7eb7('0xd'));var jsforce=require(_0x7eb7('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x7eb7('0xf'));var querystring=require(_0x7eb7('0x10'));var Papa=require('papaparse');var Redis=require(_0x7eb7('0x11'));var authService=require('../../components/auth/service');var qs=require(_0x7eb7('0x12'));var as=require(_0x7eb7('0x13'));var hardwareService=require(_0x7eb7('0x14'));var logger=require(_0x7eb7('0x15'))(_0x7eb7('0x16'));var utils=require('../../config/utils');var config=require(_0x7eb7('0x17'));var licenseUtil=require(_0x7eb7('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x25a048,_0x451920){_0x451920=_0x451920||0xcc;return function(_0x589d9c){if(_0x589d9c){return _0x25a048[_0x7eb7('0x19')](_0x451920);}return _0x25a048[_0x7eb7('0x1a')](_0x451920)[_0x7eb7('0x1b')]();};}function respondWithResult(_0x41c70c,_0x4dbcab){_0x4dbcab=_0x4dbcab||0xc8;return function(_0x345998){if(_0x345998){return _0x41c70c[_0x7eb7('0x1a')](_0x4dbcab)[_0x7eb7('0x1c')](_0x345998);}};}function respondWithFilteredResult(_0x288084,_0x44b7c3){return function(_0x1a3e93){if(_0x1a3e93){var _0x11937a=typeof _0x44b7c3['offset']===_0x7eb7('0x1d')&&typeof _0x44b7c3[_0x7eb7('0x1e')]===_0x7eb7('0x1d');var _0x272f63=_0x1a3e93[_0x7eb7('0x1f')];var _0x3e94ac=_0x11937a?0x0:_0x44b7c3['offset'];var _0x286986=_0x11937a?_0x1a3e93[_0x7eb7('0x1f')]:_0x44b7c3[_0x7eb7('0x20')]+_0x44b7c3['limit'];var _0x34d718;if(_0x286986>=_0x272f63){_0x286986=_0x272f63;_0x34d718=0xc8;}else{_0x34d718=0xce;}_0x288084[_0x7eb7('0x1a')](_0x34d718);return _0x288084[_0x7eb7('0x21')](_0x7eb7('0x22'),_0x3e94ac+'-'+_0x286986+'/'+_0x272f63)['json'](_0x1a3e93);}return null;};}function patchUpdates(_0x470b78){return function(_0x274849){try{jsonpatch['apply'](_0x274849,_0x470b78,!![]);}catch(_0x99d8f4){return BPromise[_0x7eb7('0x23')](_0x99d8f4);}return _0x274849[_0x7eb7('0x24')]();};}function saveUpdates(_0x4ee2c0,_0xcb434e){return function(_0x411c92){if(_0x411c92){return _0x411c92[_0x7eb7('0x25')](_0x4ee2c0)[_0x7eb7('0x26')](function(_0x23790a){return _0x23790a;});}return null;};}function removeEntity(_0x5629df,_0x44aecc){return function(_0x2bf877){if(_0x2bf877){return _0x2bf877[_0x7eb7('0x27')]()['then'](function(){_0x5629df[_0x7eb7('0x1a')](0xcc)[_0x7eb7('0x1b')]();});}};}function handleEntityNotFound(_0x50f18b,_0x51d842){return function(_0x86fef4){if(!_0x86fef4){_0x50f18b[_0x7eb7('0x19')](0x194);}return _0x86fef4;};}function handleError(_0x6310e8,_0x4e8c75){_0x4e8c75=_0x4e8c75||0x1f4;return function(_0x38b83e){logger[_0x7eb7('0x28')](_0x38b83e[_0x7eb7('0x29')]);if(_0x38b83e[_0x7eb7('0x2a')]){delete _0x38b83e['name'];}_0x6310e8['status'](_0x4e8c75)[_0x7eb7('0x2b')](_0x38b83e);};}exports[_0x7eb7('0x2c')]=function(_0x48923d,_0x4252c6){var _0x3f6741={},_0x117970={},_0x3e7eeb={'count':0x0,'rows':[]};var _0x4e73de=_[_0x7eb7('0x2d')](db[_0x7eb7('0x2e')][_0x7eb7('0x2f')],function(_0x16af69){return{'name':_0x16af69[_0x7eb7('0x30')],'type':_0x16af69[_0x7eb7('0x31')][_0x7eb7('0x32')]};});_0x117970[_0x7eb7('0x33')]=_['map'](_0x4e73de,_0x7eb7('0x2a'));_0x117970['query']=_[_0x7eb7('0x34')](_0x48923d['query']);_0x117970[_0x7eb7('0x35')]=_[_0x7eb7('0x36')](_0x117970['model'],_0x117970[_0x7eb7('0x37')]);_0x3f6741[_0x7eb7('0x38')]=_[_0x7eb7('0x36')](_0x117970[_0x7eb7('0x33')],qs['fields'](_0x48923d[_0x7eb7('0x37')][_0x7eb7('0x39')]));_0x3f6741[_0x7eb7('0x38')]=_0x3f6741[_0x7eb7('0x38')][_0x7eb7('0x3a')]?_0x3f6741['attributes']:_0x117970[_0x7eb7('0x33')];if(!_0x48923d[_0x7eb7('0x37')][_0x7eb7('0x3b')](_0x7eb7('0x3c'))){_0x3f6741[_0x7eb7('0x1e')]=qs[_0x7eb7('0x1e')](_0x48923d[_0x7eb7('0x37')][_0x7eb7('0x1e')]);_0x3f6741[_0x7eb7('0x20')]=qs[_0x7eb7('0x20')](_0x48923d[_0x7eb7('0x37')][_0x7eb7('0x20')]);}_0x3f6741[_0x7eb7('0x3d')]=qs[_0x7eb7('0x3e')](_0x48923d[_0x7eb7('0x37')][_0x7eb7('0x3e')]);_0x3f6741[_0x7eb7('0x3f')]=qs[_0x7eb7('0x35')](_['pick'](_0x48923d[_0x7eb7('0x37')],_0x117970['filters']),_0x4e73de);if(_0x48923d[_0x7eb7('0x37')][_0x7eb7('0x40')]){_0x3f6741[_0x7eb7('0x3f')]=_[_0x7eb7('0x41')](_0x3f6741[_0x7eb7('0x3f')],{'$or':_[_0x7eb7('0x2d')](_0x4e73de,function(_0x66011f){if(_0x66011f[_0x7eb7('0x31')]!==_0x7eb7('0x42')){var _0x3df13a={};_0x3df13a[_0x66011f[_0x7eb7('0x2a')]]={'$like':'%'+_0x48923d[_0x7eb7('0x37')][_0x7eb7('0x40')]+'%'};return _0x3df13a;}})});}_0x3f6741=_[_0x7eb7('0x41')]({},_0x3f6741,_0x48923d[_0x7eb7('0x43')]);var _0x5a8df5={'where':_0x3f6741['where']};return db[_0x7eb7('0x2e')][_0x7eb7('0x1f')](_0x5a8df5)['then'](function(_0x37a83a){_0x3e7eeb[_0x7eb7('0x1f')]=_0x37a83a;if(_0x48923d[_0x7eb7('0x37')]['includeAll']){_0x3f6741['include']=[{'all':!![]}];}return db['SmsApplication'][_0x7eb7('0x44')](_0x3f6741);})[_0x7eb7('0x26')](function(_0x392822){_0x3e7eeb['rows']=_0x392822;return _0x3e7eeb;})[_0x7eb7('0x26')](respondWithFilteredResult(_0x4252c6,_0x3f6741))[_0x7eb7('0x45')](handleError(_0x4252c6,null));};exports[_0x7eb7('0x46')]=function(_0x3d3c7b,_0x44eb66){var _0x35a8c4={'raw':!![],'where':{'id':_0x3d3c7b[_0x7eb7('0x47')]['id']}},_0x1349af={};_0x1349af['model']=_[_0x7eb7('0x34')](db['SmsApplication'][_0x7eb7('0x2f')]);_0x1349af[_0x7eb7('0x37')]=_['keys'](_0x3d3c7b[_0x7eb7('0x37')]);_0x1349af['filters']=_[_0x7eb7('0x36')](_0x1349af[_0x7eb7('0x33')],_0x1349af['query']);_0x35a8c4[_0x7eb7('0x38')]=_[_0x7eb7('0x36')](_0x1349af[_0x7eb7('0x33')],qs['fields'](_0x3d3c7b[_0x7eb7('0x37')][_0x7eb7('0x39')]));_0x35a8c4[_0x7eb7('0x38')]=_0x35a8c4[_0x7eb7('0x38')][_0x7eb7('0x3a')]?_0x35a8c4[_0x7eb7('0x38')]:_0x1349af[_0x7eb7('0x33')];if(_0x3d3c7b[_0x7eb7('0x37')]['includeAll']){_0x35a8c4[_0x7eb7('0x48')]=[{'all':!![]}];}_0x35a8c4=_[_0x7eb7('0x41')]({},_0x35a8c4,_0x3d3c7b['options']);return db[_0x7eb7('0x2e')][_0x7eb7('0x49')](_0x35a8c4)[_0x7eb7('0x26')](handleEntityNotFound(_0x44eb66,null))[_0x7eb7('0x26')](respondWithResult(_0x44eb66,null))[_0x7eb7('0x45')](handleError(_0x44eb66,null));};exports[_0x7eb7('0x4a')]=function(_0x10d451,_0x515588){return db[_0x7eb7('0x2e')][_0x7eb7('0x4a')](_0x10d451['body'],{})[_0x7eb7('0x26')](respondWithResult(_0x515588,0xc9))[_0x7eb7('0x45')](handleError(_0x515588,null));};exports[_0x7eb7('0x25')]=function(_0x3a788e,_0x5504d7){if(_0x3a788e['body']['id']){delete _0x3a788e['body']['id'];}return db[_0x7eb7('0x2e')][_0x7eb7('0x49')]({'where':{'id':_0x3a788e[_0x7eb7('0x47')]['id']}})[_0x7eb7('0x26')](handleEntityNotFound(_0x5504d7,null))[_0x7eb7('0x26')](saveUpdates(_0x3a788e[_0x7eb7('0x4b')],null))[_0x7eb7('0x26')](respondWithResult(_0x5504d7,null))[_0x7eb7('0x45')](handleError(_0x5504d7,null));};exports[_0x7eb7('0x27')]=function(_0x205c93,_0x201d72){return db['SmsApplication']['find']({'where':{'id':_0x205c93[_0x7eb7('0x47')]['id']}})[_0x7eb7('0x26')](handleEntityNotFound(_0x201d72,null))['then'](removeEntity(_0x201d72,null))[_0x7eb7('0x45')](handleError(_0x201d72,null));};