Built motion from commit d5e4af8c.|2.6.23
[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 _0x8b52=['../../config/license/util','sendStatus','end','status','offset','limit','count','Content-Range','json','reject','save','then','destroy','stack','name','send','index','map','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','sort','where','filter','merge','VIRTUAL','options','WhatsappApplication','includeAll','include','findAll','rows','catch','show','params','keys','find','create','body','update','eml-format','rimraf','zip-dir','request-promise','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils'];(function(_0xfe3bc5,_0x2c8bad){var _0x46686a=function(_0x36338f){while(--_0x36338f){_0xfe3bc5['push'](_0xfe3bc5['shift']());}};_0x46686a(++_0x2c8bad);}(_0x8b52,0x151));var _0x28b5=function(_0x4b055c,_0x4b870b){_0x4b055c=_0x4b055c-0x0;var _0x4b62bb=_0x8b52[_0x4b055c];return _0x4b62bb;};'use strict';var emlformat=require(_0x28b5('0x0'));var rimraf=require(_0x28b5('0x1'));var zipdir=require(_0x28b5('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x28b5('0x3'));var moment=require(_0x28b5('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x28b5('0x5'));var util=require(_0x28b5('0x6'));var path=require(_0x28b5('0x7'));var sox=require(_0x28b5('0x8'));var csv=require(_0x28b5('0x9'));var ejs=require(_0x28b5('0xa'));var fs=require('fs');var fs_extra=require(_0x28b5('0xb'));var _=require(_0x28b5('0xc'));var squel=require(_0x28b5('0xd'));var crypto=require('crypto');var jsforce=require(_0x28b5('0xe'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x28b5('0xf'));var Papa=require(_0x28b5('0x10'));var Redis=require('ioredis');var authService=require(_0x28b5('0x11'));var qs=require(_0x28b5('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x28b5('0x13'));var logger=require(_0x28b5('0x14'))(_0x28b5('0x15'));var utils=require(_0x28b5('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0x28b5('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0xc18108,_0x3bd9f3){_0x3bd9f3=_0x3bd9f3||0xcc;return function(_0x5f41b6){if(_0x5f41b6){return _0xc18108[_0x28b5('0x18')](_0x3bd9f3);}return _0xc18108['status'](_0x3bd9f3)[_0x28b5('0x19')]();};}function respondWithResult(_0x4a684e,_0x58f350){_0x58f350=_0x58f350||0xc8;return function(_0xff943a){if(_0xff943a){return _0x4a684e[_0x28b5('0x1a')](_0x58f350)['json'](_0xff943a);}};}function respondWithFilteredResult(_0x2c17c7,_0x26213c){return function(_0x1e4a10){if(_0x1e4a10){var _0x16c115=typeof _0x26213c[_0x28b5('0x1b')]==='undefined'&&typeof _0x26213c[_0x28b5('0x1c')]==='undefined';var _0x7b6900=_0x1e4a10[_0x28b5('0x1d')];var _0xfea919=_0x16c115?0x0:_0x26213c[_0x28b5('0x1b')];var _0x540933=_0x16c115?_0x1e4a10[_0x28b5('0x1d')]:_0x26213c[_0x28b5('0x1b')]+_0x26213c[_0x28b5('0x1c')];var _0x534136;if(_0x540933>=_0x7b6900){_0x540933=_0x7b6900;_0x534136=0xc8;}else{_0x534136=0xce;}_0x2c17c7[_0x28b5('0x1a')](_0x534136);return _0x2c17c7['set'](_0x28b5('0x1e'),_0xfea919+'-'+_0x540933+'/'+_0x7b6900)[_0x28b5('0x1f')](_0x1e4a10);}return null;};}function patchUpdates(_0x2c4cae){return function(_0x386494){try{jsonpatch['apply'](_0x386494,_0x2c4cae,!![]);}catch(_0x3ebe9e){return BPromise[_0x28b5('0x20')](_0x3ebe9e);}return _0x386494[_0x28b5('0x21')]();};}function saveUpdates(_0x32c819,_0x5c453a){return function(_0x4a8893){if(_0x4a8893){return _0x4a8893['update'](_0x32c819)[_0x28b5('0x22')](function(_0x1bf044){return _0x1bf044;});}return null;};}function removeEntity(_0x395feb,_0x740562){return function(_0x8fa4b9){if(_0x8fa4b9){return _0x8fa4b9[_0x28b5('0x23')]()['then'](function(){_0x395feb['status'](0xcc)[_0x28b5('0x19')]();});}};}function handleEntityNotFound(_0x528993,_0x304f72){return function(_0x25fd54){if(!_0x25fd54){_0x528993[_0x28b5('0x18')](0x194);}return _0x25fd54;};}function handleError(_0x18176c,_0x127ab0){_0x127ab0=_0x127ab0||0x1f4;return function(_0x5ae41d){logger['error'](_0x5ae41d[_0x28b5('0x24')]);if(_0x5ae41d[_0x28b5('0x25')]){delete _0x5ae41d[_0x28b5('0x25')];}_0x18176c[_0x28b5('0x1a')](_0x127ab0)[_0x28b5('0x26')](_0x5ae41d);};}exports[_0x28b5('0x27')]=function(_0x2db6f1,_0x1bbe54){var _0x139524={},_0x2a182a={},_0x491b72={'count':0x0,'rows':[]};var _0x2b46f7=_[_0x28b5('0x28')](db['WhatsappApplication'][_0x28b5('0x29')],function(_0x330767){return{'name':_0x330767[_0x28b5('0x2a')],'type':_0x330767[_0x28b5('0x2b')][_0x28b5('0x2c')]};});_0x2a182a[_0x28b5('0x2d')]=_[_0x28b5('0x28')](_0x2b46f7,'name');_0x2a182a[_0x28b5('0x2e')]=_['keys'](_0x2db6f1[_0x28b5('0x2e')]);_0x2a182a[_0x28b5('0x2f')]=_[_0x28b5('0x30')](_0x2a182a[_0x28b5('0x2d')],_0x2a182a[_0x28b5('0x2e')]);_0x139524[_0x28b5('0x31')]=_[_0x28b5('0x30')](_0x2a182a[_0x28b5('0x2d')],qs[_0x28b5('0x32')](_0x2db6f1[_0x28b5('0x2e')][_0x28b5('0x32')]));_0x139524[_0x28b5('0x31')]=_0x139524[_0x28b5('0x31')][_0x28b5('0x33')]?_0x139524[_0x28b5('0x31')]:_0x2a182a[_0x28b5('0x2d')];if(!_0x2db6f1['query'][_0x28b5('0x34')]('nolimit')){_0x139524[_0x28b5('0x1c')]=qs[_0x28b5('0x1c')](_0x2db6f1[_0x28b5('0x2e')][_0x28b5('0x1c')]);_0x139524['offset']=qs[_0x28b5('0x1b')](_0x2db6f1[_0x28b5('0x2e')][_0x28b5('0x1b')]);}_0x139524['order']=qs['sort'](_0x2db6f1[_0x28b5('0x2e')][_0x28b5('0x35')]);_0x139524[_0x28b5('0x36')]=qs[_0x28b5('0x2f')](_['pick'](_0x2db6f1[_0x28b5('0x2e')],_0x2a182a[_0x28b5('0x2f')]),_0x2b46f7);if(_0x2db6f1[_0x28b5('0x2e')][_0x28b5('0x37')]){_0x139524[_0x28b5('0x36')]=_[_0x28b5('0x38')](_0x139524[_0x28b5('0x36')],{'$or':_[_0x28b5('0x28')](_0x2b46f7,function(_0x4cc88a){if(_0x4cc88a[_0x28b5('0x2b')]!==_0x28b5('0x39')){var _0x4d3d09={};_0x4d3d09[_0x4cc88a[_0x28b5('0x25')]]={'$like':'%'+_0x2db6f1['query'][_0x28b5('0x37')]+'%'};return _0x4d3d09;}})});}_0x139524=_[_0x28b5('0x38')]({},_0x139524,_0x2db6f1[_0x28b5('0x3a')]);var _0x5e1fb2={'where':_0x139524[_0x28b5('0x36')]};return db[_0x28b5('0x3b')][_0x28b5('0x1d')](_0x5e1fb2)[_0x28b5('0x22')](function(_0x31f620){_0x491b72[_0x28b5('0x1d')]=_0x31f620;if(_0x2db6f1['query'][_0x28b5('0x3c')]){_0x139524[_0x28b5('0x3d')]=[{'all':!![]}];}return db[_0x28b5('0x3b')][_0x28b5('0x3e')](_0x139524);})[_0x28b5('0x22')](function(_0x5c237f){_0x491b72[_0x28b5('0x3f')]=_0x5c237f;return _0x491b72;})[_0x28b5('0x22')](respondWithFilteredResult(_0x1bbe54,_0x139524))[_0x28b5('0x40')](handleError(_0x1bbe54,null));};exports[_0x28b5('0x41')]=function(_0x45bd3c,_0x4bd2e3){var _0x2ac508={'raw':!![],'where':{'id':_0x45bd3c[_0x28b5('0x42')]['id']}},_0x5bee77={};_0x5bee77[_0x28b5('0x2d')]=_[_0x28b5('0x43')](db[_0x28b5('0x3b')]['rawAttributes']);_0x5bee77['query']=_[_0x28b5('0x43')](_0x45bd3c[_0x28b5('0x2e')]);_0x5bee77[_0x28b5('0x2f')]=_[_0x28b5('0x30')](_0x5bee77[_0x28b5('0x2d')],_0x5bee77['query']);_0x2ac508[_0x28b5('0x31')]=_['intersection'](_0x5bee77[_0x28b5('0x2d')],qs[_0x28b5('0x32')](_0x45bd3c[_0x28b5('0x2e')][_0x28b5('0x32')]));_0x2ac508[_0x28b5('0x31')]=_0x2ac508[_0x28b5('0x31')][_0x28b5('0x33')]?_0x2ac508['attributes']:_0x5bee77[_0x28b5('0x2d')];if(_0x45bd3c[_0x28b5('0x2e')][_0x28b5('0x3c')]){_0x2ac508[_0x28b5('0x3d')]=[{'all':!![]}];}_0x2ac508=_[_0x28b5('0x38')]({},_0x2ac508,_0x45bd3c[_0x28b5('0x3a')]);return db[_0x28b5('0x3b')][_0x28b5('0x44')](_0x2ac508)[_0x28b5('0x22')](handleEntityNotFound(_0x4bd2e3,null))['then'](respondWithResult(_0x4bd2e3,null))[_0x28b5('0x40')](handleError(_0x4bd2e3,null));};exports[_0x28b5('0x45')]=function(_0xe46b0a,_0x141f9a){return db['WhatsappApplication'][_0x28b5('0x45')](_0xe46b0a[_0x28b5('0x46')],{})[_0x28b5('0x22')](respondWithResult(_0x141f9a,0xc9))[_0x28b5('0x40')](handleError(_0x141f9a,null));};exports[_0x28b5('0x47')]=function(_0xaf449d,_0x3d7fdd){if(_0xaf449d[_0x28b5('0x46')]['id']){delete _0xaf449d[_0x28b5('0x46')]['id'];}return db[_0x28b5('0x3b')][_0x28b5('0x44')]({'where':{'id':_0xaf449d[_0x28b5('0x42')]['id']}})[_0x28b5('0x22')](handleEntityNotFound(_0x3d7fdd,null))[_0x28b5('0x22')](saveUpdates(_0xaf449d['body'],null))['then'](respondWithResult(_0x3d7fdd,null))['catch'](handleError(_0x3d7fdd,null));};exports[_0x28b5('0x23')]=function(_0x97af32,_0x5aaef3){return db[_0x28b5('0x3b')][_0x28b5('0x44')]({'where':{'id':_0x97af32['params']['id']}})[_0x28b5('0x22')](handleEntityNotFound(_0x5aaef3,null))[_0x28b5('0x22')](removeEntity(_0x5aaef3,null))[_0x28b5('0x40')](handleError(_0x5aaef3,null));};