1b27f82dca513af89e980adc183fb47dac7539b3
[motion2.git] / server / api / whatsappApplication / whatsappApplication.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 _0xbc7a=['model','attributes','intersection','fields','length','hasOwnProperty','order','sort','pick','filter','where','merge','VIRTUAL','options','includeAll','include','catch','show','params','find','create','body','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','status','end','json','offset','undefined','limit','count','Content-Range','apply','reject','update','destroy','then','sendStatus','stack','name','map','WhatsappApplication','rawAttributes','fieldName','type','key','query','keys'];(function(_0x58a474,_0x29e424){var _0x1d24f4=function(_0x231fc1){while(--_0x231fc1){_0x58a474['push'](_0x58a474['shift']());}};_0x1d24f4(++_0x29e424);}(_0xbc7a,0xa4));var _0xabc7=function(_0xb13f04,_0x53203e){_0xb13f04=_0xb13f04-0x0;var _0x25e517=_0xbc7a[_0xb13f04];return _0x25e517;};'use strict';var emlformat=require(_0xabc7('0x0'));var rimraf=require(_0xabc7('0x1'));var zipdir=require(_0xabc7('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xabc7('0x3'));var moment=require(_0xabc7('0x4'));var BPromise=require(_0xabc7('0x5'));var Mustache=require(_0xabc7('0x6'));var util=require(_0xabc7('0x7'));var path=require(_0xabc7('0x8'));var sox=require('sox');var csv=require(_0xabc7('0x9'));var ejs=require(_0xabc7('0xa'));var fs=require('fs');var fs_extra=require(_0xabc7('0xb'));var _=require(_0xabc7('0xc'));var squel=require(_0xabc7('0xd'));var crypto=require(_0xabc7('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xabc7('0xf'));var toCsv=require('to-csv');var querystring=require(_0xabc7('0x10'));var Papa=require(_0xabc7('0x11'));var Redis=require(_0xabc7('0x12'));var authService=require(_0xabc7('0x13'));var qs=require(_0xabc7('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xabc7('0x15'))('api');var utils=require(_0xabc7('0x16'));var config=require(_0xabc7('0x17'));var licenseUtil=require(_0xabc7('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1f1410,_0x4030f7){_0x4030f7=_0x4030f7||0xcc;return function(_0x58c9db){if(_0x58c9db){return _0x1f1410['sendStatus'](_0x4030f7);}return _0x1f1410[_0xabc7('0x19')](_0x4030f7)[_0xabc7('0x1a')]();};}function respondWithResult(_0x4db820,_0x218831){_0x218831=_0x218831||0xc8;return function(_0x4e1c98){if(_0x4e1c98){return _0x4db820[_0xabc7('0x19')](_0x218831)[_0xabc7('0x1b')](_0x4e1c98);}};}function respondWithFilteredResult(_0x3f3436,_0x2d4c5b){return function(_0x4b3575){if(_0x4b3575){var _0x50027a=typeof _0x2d4c5b[_0xabc7('0x1c')]===_0xabc7('0x1d')&&typeof _0x2d4c5b[_0xabc7('0x1e')]===_0xabc7('0x1d');var _0x5a184e=_0x4b3575['count'];var _0x4184e1=_0x50027a?0x0:_0x2d4c5b[_0xabc7('0x1c')];var _0x541a68=_0x50027a?_0x4b3575[_0xabc7('0x1f')]:_0x2d4c5b[_0xabc7('0x1c')]+_0x2d4c5b['limit'];var _0x273148;if(_0x541a68>=_0x5a184e){_0x541a68=_0x5a184e;_0x273148=0xc8;}else{_0x273148=0xce;}_0x3f3436[_0xabc7('0x19')](_0x273148);return _0x3f3436['set'](_0xabc7('0x20'),_0x4184e1+'-'+_0x541a68+'/'+_0x5a184e)['json'](_0x4b3575);}return null;};}function patchUpdates(_0x5905db){return function(_0x552ffa){try{jsonpatch[_0xabc7('0x21')](_0x552ffa,_0x5905db,!![]);}catch(_0x58ef0f){return BPromise[_0xabc7('0x22')](_0x58ef0f);}return _0x552ffa['save']();};}function saveUpdates(_0x4b13fa,_0x2862f9){return function(_0x20201c){if(_0x20201c){return _0x20201c[_0xabc7('0x23')](_0x4b13fa)['then'](function(_0x173881){return _0x173881;});}return null;};}function removeEntity(_0x390c50,_0x34dcc8){return function(_0x53d4fc){if(_0x53d4fc){return _0x53d4fc[_0xabc7('0x24')]()[_0xabc7('0x25')](function(){_0x390c50[_0xabc7('0x19')](0xcc)[_0xabc7('0x1a')]();});}};}function handleEntityNotFound(_0x924f1b,_0x52b87b){return function(_0x12ccd2){if(!_0x12ccd2){_0x924f1b[_0xabc7('0x26')](0x194);}return _0x12ccd2;};}function handleError(_0x10bb9e,_0x5b5a59){_0x5b5a59=_0x5b5a59||0x1f4;return function(_0xc42c6d){logger['error'](_0xc42c6d[_0xabc7('0x27')]);if(_0xc42c6d[_0xabc7('0x28')]){delete _0xc42c6d[_0xabc7('0x28')];}_0x10bb9e[_0xabc7('0x19')](_0x5b5a59)['send'](_0xc42c6d);};}exports['index']=function(_0x3b0bdc,_0x5dd2a3){var _0x5a4c1d={},_0x1fdbea={},_0x1df938={'count':0x0,'rows':[]};var _0x3cb4c9=_[_0xabc7('0x29')](db[_0xabc7('0x2a')][_0xabc7('0x2b')],function(_0x968c61){return{'name':_0x968c61[_0xabc7('0x2c')],'type':_0x968c61[_0xabc7('0x2d')][_0xabc7('0x2e')]};});_0x1fdbea['model']=_['map'](_0x3cb4c9,_0xabc7('0x28'));_0x1fdbea[_0xabc7('0x2f')]=_[_0xabc7('0x30')](_0x3b0bdc['query']);_0x1fdbea['filters']=_['intersection'](_0x1fdbea[_0xabc7('0x31')],_0x1fdbea[_0xabc7('0x2f')]);_0x5a4c1d[_0xabc7('0x32')]=_[_0xabc7('0x33')](_0x1fdbea[_0xabc7('0x31')],qs[_0xabc7('0x34')](_0x3b0bdc[_0xabc7('0x2f')][_0xabc7('0x34')]));_0x5a4c1d[_0xabc7('0x32')]=_0x5a4c1d[_0xabc7('0x32')][_0xabc7('0x35')]?_0x5a4c1d[_0xabc7('0x32')]:_0x1fdbea[_0xabc7('0x31')];if(!_0x3b0bdc[_0xabc7('0x2f')][_0xabc7('0x36')]('nolimit')){_0x5a4c1d[_0xabc7('0x1e')]=qs[_0xabc7('0x1e')](_0x3b0bdc[_0xabc7('0x2f')][_0xabc7('0x1e')]);_0x5a4c1d[_0xabc7('0x1c')]=qs[_0xabc7('0x1c')](_0x3b0bdc['query'][_0xabc7('0x1c')]);}_0x5a4c1d[_0xabc7('0x37')]=qs[_0xabc7('0x38')](_0x3b0bdc[_0xabc7('0x2f')][_0xabc7('0x38')]);_0x5a4c1d['where']=qs['filters'](_[_0xabc7('0x39')](_0x3b0bdc[_0xabc7('0x2f')],_0x1fdbea['filters']),_0x3cb4c9);if(_0x3b0bdc[_0xabc7('0x2f')][_0xabc7('0x3a')]){_0x5a4c1d[_0xabc7('0x3b')]=_[_0xabc7('0x3c')](_0x5a4c1d[_0xabc7('0x3b')],{'$or':_[_0xabc7('0x29')](_0x3cb4c9,function(_0x4dce4b){if(_0x4dce4b['type']!==_0xabc7('0x3d')){var _0x3110ab={};_0x3110ab[_0x4dce4b[_0xabc7('0x28')]]={'$like':'%'+_0x3b0bdc[_0xabc7('0x2f')][_0xabc7('0x3a')]+'%'};return _0x3110ab;}})});}_0x5a4c1d=_['merge']({},_0x5a4c1d,_0x3b0bdc[_0xabc7('0x3e')]);var _0x40a780={'where':_0x5a4c1d[_0xabc7('0x3b')]};return db[_0xabc7('0x2a')]['count'](_0x40a780)[_0xabc7('0x25')](function(_0x51c861){_0x1df938[_0xabc7('0x1f')]=_0x51c861;if(_0x3b0bdc[_0xabc7('0x2f')][_0xabc7('0x3f')]){_0x5a4c1d[_0xabc7('0x40')]=[{'all':!![]}];}return db['WhatsappApplication']['findAll'](_0x5a4c1d);})[_0xabc7('0x25')](function(_0x3444f3){_0x1df938['rows']=_0x3444f3;return _0x1df938;})[_0xabc7('0x25')](respondWithFilteredResult(_0x5dd2a3,_0x5a4c1d))[_0xabc7('0x41')](handleError(_0x5dd2a3,null));};exports[_0xabc7('0x42')]=function(_0x234ae8,_0x49abf1){var _0x5c21b1={'raw':!![],'where':{'id':_0x234ae8[_0xabc7('0x43')]['id']}},_0x1bec95={};_0x1bec95['model']=_[_0xabc7('0x30')](db[_0xabc7('0x2a')][_0xabc7('0x2b')]);_0x1bec95[_0xabc7('0x2f')]=_[_0xabc7('0x30')](_0x234ae8['query']);_0x1bec95['filters']=_[_0xabc7('0x33')](_0x1bec95[_0xabc7('0x31')],_0x1bec95['query']);_0x5c21b1[_0xabc7('0x32')]=_[_0xabc7('0x33')](_0x1bec95[_0xabc7('0x31')],qs[_0xabc7('0x34')](_0x234ae8['query']['fields']));_0x5c21b1[_0xabc7('0x32')]=_0x5c21b1[_0xabc7('0x32')][_0xabc7('0x35')]?_0x5c21b1['attributes']:_0x1bec95[_0xabc7('0x31')];if(_0x234ae8[_0xabc7('0x2f')][_0xabc7('0x3f')]){_0x5c21b1[_0xabc7('0x40')]=[{'all':!![]}];}_0x5c21b1=_['merge']({},_0x5c21b1,_0x234ae8[_0xabc7('0x3e')]);return db[_0xabc7('0x2a')][_0xabc7('0x44')](_0x5c21b1)[_0xabc7('0x25')](handleEntityNotFound(_0x49abf1,null))[_0xabc7('0x25')](respondWithResult(_0x49abf1,null))[_0xabc7('0x41')](handleError(_0x49abf1,null));};exports[_0xabc7('0x45')]=function(_0x24dacf,_0x3d835d){return db[_0xabc7('0x2a')][_0xabc7('0x45')](_0x24dacf[_0xabc7('0x46')],{})[_0xabc7('0x25')](respondWithResult(_0x3d835d,0xc9))['catch'](handleError(_0x3d835d,null));};exports[_0xabc7('0x23')]=function(_0x19b6ff,_0x109582){if(_0x19b6ff[_0xabc7('0x46')]['id']){delete _0x19b6ff[_0xabc7('0x46')]['id'];}return db[_0xabc7('0x2a')][_0xabc7('0x44')]({'where':{'id':_0x19b6ff['params']['id']}})[_0xabc7('0x25')](handleEntityNotFound(_0x109582,null))[_0xabc7('0x25')](saveUpdates(_0x19b6ff[_0xabc7('0x46')],null))[_0xabc7('0x25')](respondWithResult(_0x109582,null))[_0xabc7('0x41')](handleError(_0x109582,null));};exports[_0xabc7('0x24')]=function(_0x59dba6,_0x3e9665){return db[_0xabc7('0x2a')][_0xabc7('0x44')]({'where':{'id':_0x59dba6[_0xabc7('0x43')]['id']}})[_0xabc7('0x25')](handleEntityNotFound(_0x3e9665,null))[_0xabc7('0x25')](removeEntity(_0x3e9665,null))['catch'](handleError(_0x3e9665,null));};