cd42b44e05e0e496d0bfb2693ff665aee7e43a61
[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 _0x7afc=['name','index','map','WhatsappApplication','fieldName','model','query','keys','intersection','attributes','length','hasOwnProperty','nolimit','offset','order','sort','where','filters','merge','type','VIRTUAL','filter','includeAll','include','findAll','catch','show','params','fields','options','create','body','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','path','sox','to-csv','ejs','crypto','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','count','limit','set','Content-Range','json','apply','reject','save','update','then','destroy','error'];(function(_0x380356,_0x44304f){var _0x542fb4=function(_0x132eec){while(--_0x132eec){_0x380356['push'](_0x380356['shift']());}};_0x542fb4(++_0x44304f);}(_0x7afc,0xf2));var _0xc7af=function(_0x29b886,_0x3ec7c2){_0x29b886=_0x29b886-0x0;var _0x263ef9=_0x7afc[_0x29b886];return _0x263ef9;};'use strict';var pdf=require(_0xc7af('0x0'));var emlformat=require(_0xc7af('0x1'));var rimraf=require(_0xc7af('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0xc7af('0x3'));var rp=require(_0xc7af('0x4'));var moment=require(_0xc7af('0x5'));var BPromise=require(_0xc7af('0x6'));var Mustache=require('mustache');var util=require('util');var path=require(_0xc7af('0x7'));var sox=require(_0xc7af('0x8'));var csv=require(_0xc7af('0x9'));var ejs=require(_0xc7af('0xa'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0xc7af('0xb'));var jsforce=require('jsforce');var deskjs=require(_0xc7af('0xc'));var toCsv=require(_0xc7af('0x9'));var querystring=require(_0xc7af('0xd'));var Papa=require(_0xc7af('0xe'));var Redis=require('ioredis');var authService=require(_0xc7af('0xf'));var qs=require(_0xc7af('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xc7af('0x11'));var logger=require(_0xc7af('0x12'))('api');var utils=require(_0xc7af('0x13'));var config=require(_0xc7af('0x14'));var licenseUtil=require(_0xc7af('0x15'));var db=require(_0xc7af('0x16'))['db'];function respondWithStatusCode(_0xc65e6,_0x3e85ba){_0x3e85ba=_0x3e85ba||0xcc;return function(_0x578718){if(_0x578718){return _0xc65e6[_0xc7af('0x17')](_0x3e85ba);}return _0xc65e6[_0xc7af('0x18')](_0x3e85ba)[_0xc7af('0x19')]();};}function respondWithResult(_0x3ae73d,_0x555525){_0x555525=_0x555525||0xc8;return function(_0x2c02a3){if(_0x2c02a3){return _0x3ae73d[_0xc7af('0x18')](_0x555525)['json'](_0x2c02a3);}};}function respondWithFilteredResult(_0x867539,_0x1d1952){return function(_0x4dc74c){if(_0x4dc74c){var _0x2efcc=_0x4dc74c[_0xc7af('0x1a')],_0x2a550f=_0x1d1952['offset'],_0x929a12=_0x1d1952['offset']+_0x1d1952[_0xc7af('0x1b')],_0x42e565;if(_0x929a12>=_0x2efcc){_0x929a12=_0x2efcc;_0x42e565=0xc8;}else{_0x42e565=0xce;}_0x867539[_0xc7af('0x18')](_0x42e565);return _0x867539[_0xc7af('0x1c')](_0xc7af('0x1d'),_0x2a550f+'-'+_0x929a12+'/'+_0x2efcc)[_0xc7af('0x1e')](_0x4dc74c);}return null;};}function patchUpdates(_0x114163){return function(_0x40b135){try{jsonpatch[_0xc7af('0x1f')](_0x40b135,_0x114163,!![]);}catch(_0x1b83a2){return BPromise[_0xc7af('0x20')](_0x1b83a2);}return _0x40b135[_0xc7af('0x21')]();};}function saveUpdates(_0x4303c1,_0x16836e){return function(_0x5ed597){if(_0x5ed597){return _0x5ed597[_0xc7af('0x22')](_0x4303c1)[_0xc7af('0x23')](function(_0x2c006d){return _0x2c006d;});}return null;};}function removeEntity(_0x5b0c1c,_0x521166){return function(_0x4f097b){if(_0x4f097b){return _0x4f097b[_0xc7af('0x24')]()[_0xc7af('0x23')](function(){_0x5b0c1c[_0xc7af('0x18')](0xcc)[_0xc7af('0x19')]();});}};}function handleEntityNotFound(_0xbf0bc0,_0x1decb8){return function(_0x48ac5b){if(!_0x48ac5b){_0xbf0bc0[_0xc7af('0x17')](0x194);}return _0x48ac5b;};}function handleError(_0x5d9b7a,_0x4245ed){_0x4245ed=_0x4245ed||0x1f4;return function(_0x42e9ee){logger[_0xc7af('0x25')](_0x42e9ee['stack']);if(_0x42e9ee[_0xc7af('0x26')]){delete _0x42e9ee['name'];}_0x5d9b7a['status'](_0x4245ed)['send'](_0x42e9ee);};}exports[_0xc7af('0x27')]=function(_0x17dc6f,_0x158926){var _0x3a9f56={},_0x4d349b={},_0xd7b1b8={'count':0x0,'rows':[]};var _0x262265=_[_0xc7af('0x28')](db[_0xc7af('0x29')]['rawAttributes'],function(_0x21611f){return{'name':_0x21611f[_0xc7af('0x2a')],'type':_0x21611f['type']['key']};});_0x4d349b[_0xc7af('0x2b')]=_[_0xc7af('0x28')](_0x262265,_0xc7af('0x26'));_0x4d349b[_0xc7af('0x2c')]=_[_0xc7af('0x2d')](_0x17dc6f[_0xc7af('0x2c')]);_0x4d349b['filters']=_[_0xc7af('0x2e')](_0x4d349b[_0xc7af('0x2b')],_0x4d349b[_0xc7af('0x2c')]);_0x3a9f56[_0xc7af('0x2f')]=_['intersection'](_0x4d349b[_0xc7af('0x2b')],qs['fields'](_0x17dc6f['query']['fields']));_0x3a9f56['attributes']=_0x3a9f56[_0xc7af('0x2f')][_0xc7af('0x30')]?_0x3a9f56[_0xc7af('0x2f')]:_0x4d349b[_0xc7af('0x2b')];if(!_0x17dc6f['query'][_0xc7af('0x31')](_0xc7af('0x32'))){_0x3a9f56[_0xc7af('0x1b')]=qs[_0xc7af('0x1b')](_0x17dc6f['query'][_0xc7af('0x1b')]);_0x3a9f56['offset']=qs['offset'](_0x17dc6f[_0xc7af('0x2c')][_0xc7af('0x33')]);}_0x3a9f56[_0xc7af('0x34')]=qs[_0xc7af('0x35')](_0x17dc6f[_0xc7af('0x2c')][_0xc7af('0x35')]);_0x3a9f56[_0xc7af('0x36')]=qs[_0xc7af('0x37')](_['pick'](_0x17dc6f[_0xc7af('0x2c')],_0x4d349b[_0xc7af('0x37')]),_0x262265);if(_0x17dc6f[_0xc7af('0x2c')]['filter']){_0x3a9f56[_0xc7af('0x36')]=_[_0xc7af('0x38')](_0x3a9f56[_0xc7af('0x36')],{'$or':_[_0xc7af('0x28')](_0x262265,function(_0x2e4dd6){if(_0x2e4dd6[_0xc7af('0x39')]!==_0xc7af('0x3a')){var _0x3ce556={};_0x3ce556[_0x2e4dd6['name']]={'$like':'%'+_0x17dc6f[_0xc7af('0x2c')][_0xc7af('0x3b')]+'%'};return _0x3ce556;}})});}_0x3a9f56=_[_0xc7af('0x38')]({},_0x3a9f56,_0x17dc6f['options']);var _0x2dbe04={'where':_0x3a9f56[_0xc7af('0x36')]};return db[_0xc7af('0x29')][_0xc7af('0x1a')](_0x2dbe04)['then'](function(_0x954f9){_0xd7b1b8[_0xc7af('0x1a')]=_0x954f9;if(_0x17dc6f[_0xc7af('0x2c')][_0xc7af('0x3c')]){_0x3a9f56[_0xc7af('0x3d')]=[{'all':!![]}];}return db[_0xc7af('0x29')][_0xc7af('0x3e')](_0x3a9f56);})[_0xc7af('0x23')](function(_0x4011e7){_0xd7b1b8['rows']=_0x4011e7;return _0xd7b1b8;})[_0xc7af('0x23')](respondWithFilteredResult(_0x158926,_0x3a9f56))[_0xc7af('0x3f')](handleError(_0x158926,null));};exports[_0xc7af('0x40')]=function(_0x11da65,_0x5ce9cf){var _0xc18ef5={'raw':!![],'where':{'id':_0x11da65[_0xc7af('0x41')]['id']}},_0x5b53a5={};_0x5b53a5[_0xc7af('0x2b')]=_[_0xc7af('0x2d')](db['WhatsappApplication']['rawAttributes']);_0x5b53a5[_0xc7af('0x2c')]=_[_0xc7af('0x2d')](_0x11da65[_0xc7af('0x2c')]);_0x5b53a5[_0xc7af('0x37')]=_[_0xc7af('0x2e')](_0x5b53a5[_0xc7af('0x2b')],_0x5b53a5[_0xc7af('0x2c')]);_0xc18ef5['attributes']=_[_0xc7af('0x2e')](_0x5b53a5[_0xc7af('0x2b')],qs[_0xc7af('0x42')](_0x11da65[_0xc7af('0x2c')][_0xc7af('0x42')]));_0xc18ef5[_0xc7af('0x2f')]=_0xc18ef5[_0xc7af('0x2f')][_0xc7af('0x30')]?_0xc18ef5[_0xc7af('0x2f')]:_0x5b53a5[_0xc7af('0x2b')];if(_0x11da65[_0xc7af('0x2c')][_0xc7af('0x3c')]){_0xc18ef5[_0xc7af('0x3d')]=[{'all':!![]}];}_0xc18ef5=_[_0xc7af('0x38')]({},_0xc18ef5,_0x11da65[_0xc7af('0x43')]);return db[_0xc7af('0x29')]['find'](_0xc18ef5)[_0xc7af('0x23')](handleEntityNotFound(_0x5ce9cf,null))[_0xc7af('0x23')](respondWithResult(_0x5ce9cf,null))[_0xc7af('0x3f')](handleError(_0x5ce9cf,null));};exports[_0xc7af('0x44')]=function(_0x44576c,_0xd10adc){return db[_0xc7af('0x29')][_0xc7af('0x44')](_0x44576c[_0xc7af('0x45')],{})['then'](respondWithResult(_0xd10adc,0xc9))[_0xc7af('0x3f')](handleError(_0xd10adc,null));};exports[_0xc7af('0x22')]=function(_0x5b4f40,_0x4de8a8){if(_0x5b4f40[_0xc7af('0x45')]['id']){delete _0x5b4f40[_0xc7af('0x45')]['id'];}return db[_0xc7af('0x29')]['find']({'where':{'id':_0x5b4f40[_0xc7af('0x41')]['id']}})['then'](handleEntityNotFound(_0x4de8a8,null))[_0xc7af('0x23')](saveUpdates(_0x5b4f40[_0xc7af('0x45')],null))['then'](respondWithResult(_0x4de8a8,null))['catch'](handleError(_0x4de8a8,null));};exports[_0xc7af('0x24')]=function(_0x2dfc4e,_0x166070){return db['WhatsappApplication']['find']({'where':{'id':_0x2dfc4e['params']['id']}})['then'](handleEntityNotFound(_0x166070,null))[_0xc7af('0x23')](removeEntity(_0x166070,null))[_0xc7af('0x3f')](handleError(_0x166070,null));};