Built motion from commit (unavailable).|2.5.2
[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 _0xf1f6=['query','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','count','include','rows','params','includeAll','options','find','catch','body','destroy','html-pdf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','json','offset','limit','set','Content-Range','apply','reject','save','update','then','stack','name','index','map','WhatsappApplication','rawAttributes','fieldName','type','key','model','keys'];(function(_0x524f8d,_0x17e0fb){var _0x25e10a=function(_0xf4829c){while(--_0xf4829c){_0x524f8d['push'](_0x524f8d['shift']());}};_0x25e10a(++_0x17e0fb);}(_0xf1f6,0x177));var _0x6f1f=function(_0x193fe6,_0x400019){_0x193fe6=_0x193fe6-0x0;var _0x1e5ef7=_0xf1f6[_0x193fe6];return _0x1e5ef7;};'use strict';var pdf=require(_0x6f1f('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x6f1f('0x1'));var jsonpatch=require(_0x6f1f('0x2'));var rp=require(_0x6f1f('0x3'));var moment=require(_0x6f1f('0x4'));var BPromise=require(_0x6f1f('0x5'));var Mustache=require('mustache');var util=require(_0x6f1f('0x6'));var path=require('path');var sox=require(_0x6f1f('0x7'));var csv=require(_0x6f1f('0x8'));var ejs=require(_0x6f1f('0x9'));var fs=require('fs');var _=require(_0x6f1f('0xa'));var squel=require(_0x6f1f('0xb'));var crypto=require('crypto');var jsforce=require(_0x6f1f('0xc'));var deskjs=require(_0x6f1f('0xd'));var toCsv=require(_0x6f1f('0x8'));var querystring=require(_0x6f1f('0xe'));var Papa=require(_0x6f1f('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x6f1f('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x6f1f('0x11'));var logger=require(_0x6f1f('0x12'))('api');var utils=require(_0x6f1f('0x13'));var config=require(_0x6f1f('0x14'));var db=require(_0x6f1f('0x15'))['db'];function respondWithStatusCode(_0x4e909a,_0xc09a01){_0xc09a01=_0xc09a01||0xcc;return function(_0xcd8b17){if(_0xcd8b17){return _0x4e909a[_0x6f1f('0x16')](_0xc09a01);}return _0x4e909a[_0x6f1f('0x17')](_0xc09a01)['end']();};}function respondWithResult(_0x3c555,_0x26dd9f){_0x26dd9f=_0x26dd9f||0xc8;return function(_0x3440ba){if(_0x3440ba){return _0x3c555[_0x6f1f('0x17')](_0x26dd9f)[_0x6f1f('0x18')](_0x3440ba);}};}function respondWithFilteredResult(_0x35dc22,_0x362b14){return function(_0x4077a8){if(_0x4077a8){var _0x4a80be=_0x4077a8['count'],_0x1be2ae=_0x362b14[_0x6f1f('0x19')],_0x128f4e=_0x362b14['offset']+_0x362b14[_0x6f1f('0x1a')],_0x80cea1;if(_0x128f4e>=_0x4a80be){_0x128f4e=_0x4a80be;_0x80cea1=0xc8;}else{_0x80cea1=0xce;}_0x35dc22[_0x6f1f('0x17')](_0x80cea1);return _0x35dc22[_0x6f1f('0x1b')](_0x6f1f('0x1c'),_0x1be2ae+'-'+_0x128f4e+'/'+_0x4a80be)[_0x6f1f('0x18')](_0x4077a8);}return null;};}function patchUpdates(_0x1c4451){return function(_0x2b1811){try{jsonpatch[_0x6f1f('0x1d')](_0x2b1811,_0x1c4451,!![]);}catch(_0x3ccae4){return BPromise[_0x6f1f('0x1e')](_0x3ccae4);}return _0x2b1811[_0x6f1f('0x1f')]();};}function saveUpdates(_0x59337a,_0x455009){return function(_0x1737fb){if(_0x1737fb){return _0x1737fb[_0x6f1f('0x20')](_0x59337a)['then'](function(_0x498fdb){return _0x498fdb;});}return null;};}function removeEntity(_0x334b2d,_0x301597){return function(_0x1e662a){if(_0x1e662a){return _0x1e662a['destroy']()[_0x6f1f('0x21')](function(){_0x334b2d['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x942280,_0x520a5e){return function(_0x5855c9){if(!_0x5855c9){_0x942280[_0x6f1f('0x16')](0x194);}return _0x5855c9;};}function handleError(_0x112cef,_0x4a92e3){_0x4a92e3=_0x4a92e3||0x1f4;return function(_0x45d636){logger['error'](_0x45d636[_0x6f1f('0x22')]);if(_0x45d636[_0x6f1f('0x23')]){delete _0x45d636[_0x6f1f('0x23')];}_0x112cef['status'](_0x4a92e3)['send'](_0x45d636);};}exports[_0x6f1f('0x24')]=function(_0x36f5ce,_0x50b02a){var _0x2ce6f6={},_0x11a93b={},_0x3e8c2d={'count':0x0,'rows':[]};var _0x3cc455=_[_0x6f1f('0x25')](db[_0x6f1f('0x26')][_0x6f1f('0x27')],function(_0xae81c1){return{'name':_0xae81c1[_0x6f1f('0x28')],'type':_0xae81c1[_0x6f1f('0x29')][_0x6f1f('0x2a')]};});_0x11a93b[_0x6f1f('0x2b')]=_['map'](_0x3cc455,_0x6f1f('0x23'));_0x11a93b['query']=_[_0x6f1f('0x2c')](_0x36f5ce[_0x6f1f('0x2d')]);_0x11a93b[_0x6f1f('0x2e')]=_['intersection'](_0x11a93b[_0x6f1f('0x2b')],_0x11a93b[_0x6f1f('0x2d')]);_0x2ce6f6[_0x6f1f('0x2f')]=_[_0x6f1f('0x30')](_0x11a93b[_0x6f1f('0x2b')],qs[_0x6f1f('0x31')](_0x36f5ce[_0x6f1f('0x2d')][_0x6f1f('0x31')]));_0x2ce6f6[_0x6f1f('0x2f')]=_0x2ce6f6[_0x6f1f('0x2f')][_0x6f1f('0x32')]?_0x2ce6f6['attributes']:_0x11a93b['model'];if(!_0x36f5ce[_0x6f1f('0x2d')][_0x6f1f('0x33')](_0x6f1f('0x34'))){_0x2ce6f6[_0x6f1f('0x1a')]=qs['limit'](_0x36f5ce[_0x6f1f('0x2d')]['limit']);_0x2ce6f6['offset']=qs[_0x6f1f('0x19')](_0x36f5ce[_0x6f1f('0x2d')][_0x6f1f('0x19')]);}_0x2ce6f6[_0x6f1f('0x35')]=qs[_0x6f1f('0x36')](_0x36f5ce[_0x6f1f('0x2d')]['sort']);_0x2ce6f6[_0x6f1f('0x37')]=qs[_0x6f1f('0x2e')](_[_0x6f1f('0x38')](_0x36f5ce[_0x6f1f('0x2d')],_0x11a93b['filters']),_0x3cc455);if(_0x36f5ce['query'][_0x6f1f('0x39')]){_0x2ce6f6[_0x6f1f('0x37')]=_['merge'](_0x2ce6f6['where'],{'$or':_[_0x6f1f('0x25')](_0x3cc455,function(_0x50acfc){if(_0x50acfc[_0x6f1f('0x29')]!==_0x6f1f('0x3a')){var _0xc8b49f={};_0xc8b49f[_0x50acfc[_0x6f1f('0x23')]]={'$like':'%'+_0x36f5ce[_0x6f1f('0x2d')]['filter']+'%'};return _0xc8b49f;}})});}_0x2ce6f6=_[_0x6f1f('0x3b')]({},_0x2ce6f6,_0x36f5ce['options']);var _0x22de45={'where':_0x2ce6f6[_0x6f1f('0x37')]};return db[_0x6f1f('0x26')][_0x6f1f('0x3c')](_0x22de45)[_0x6f1f('0x21')](function(_0x256d57){_0x3e8c2d[_0x6f1f('0x3c')]=_0x256d57;if(_0x36f5ce[_0x6f1f('0x2d')]['includeAll']){_0x2ce6f6[_0x6f1f('0x3d')]=[{'all':!![]}];}return db[_0x6f1f('0x26')]['findAll'](_0x2ce6f6);})[_0x6f1f('0x21')](function(_0x1ba959){_0x3e8c2d[_0x6f1f('0x3e')]=_0x1ba959;return _0x3e8c2d;})[_0x6f1f('0x21')](respondWithFilteredResult(_0x50b02a,_0x2ce6f6))['catch'](handleError(_0x50b02a,null));};exports['show']=function(_0x12ef49,_0x40d7ec){var _0x527379={'raw':!![],'where':{'id':_0x12ef49[_0x6f1f('0x3f')]['id']}},_0xda7f83={};_0xda7f83[_0x6f1f('0x2b')]=_[_0x6f1f('0x2c')](db[_0x6f1f('0x26')][_0x6f1f('0x27')]);_0xda7f83[_0x6f1f('0x2d')]=_['keys'](_0x12ef49[_0x6f1f('0x2d')]);_0xda7f83[_0x6f1f('0x2e')]=_['intersection'](_0xda7f83[_0x6f1f('0x2b')],_0xda7f83['query']);_0x527379[_0x6f1f('0x2f')]=_[_0x6f1f('0x30')](_0xda7f83[_0x6f1f('0x2b')],qs[_0x6f1f('0x31')](_0x12ef49['query']['fields']));_0x527379[_0x6f1f('0x2f')]=_0x527379[_0x6f1f('0x2f')]['length']?_0x527379['attributes']:_0xda7f83['model'];if(_0x12ef49[_0x6f1f('0x2d')][_0x6f1f('0x40')]){_0x527379[_0x6f1f('0x3d')]=[{'all':!![]}];}_0x527379=_[_0x6f1f('0x3b')]({},_0x527379,_0x12ef49[_0x6f1f('0x41')]);return db[_0x6f1f('0x26')][_0x6f1f('0x42')](_0x527379)[_0x6f1f('0x21')](handleEntityNotFound(_0x40d7ec,null))[_0x6f1f('0x21')](respondWithResult(_0x40d7ec,null))[_0x6f1f('0x43')](handleError(_0x40d7ec,null));};exports['create']=function(_0x26bb7d,_0x443245){return db[_0x6f1f('0x26')]['create'](_0x26bb7d[_0x6f1f('0x44')],{})[_0x6f1f('0x21')](respondWithResult(_0x443245,0xc9))[_0x6f1f('0x43')](handleError(_0x443245,null));};exports['update']=function(_0x38edfd,_0x6480c){if(_0x38edfd[_0x6f1f('0x44')]['id']){delete _0x38edfd[_0x6f1f('0x44')]['id'];}return db[_0x6f1f('0x26')][_0x6f1f('0x42')]({'where':{'id':_0x38edfd[_0x6f1f('0x3f')]['id']}})['then'](handleEntityNotFound(_0x6480c,null))[_0x6f1f('0x21')](saveUpdates(_0x38edfd['body'],null))[_0x6f1f('0x21')](respondWithResult(_0x6480c,null))[_0x6f1f('0x43')](handleError(_0x6480c,null));};exports[_0x6f1f('0x45')]=function(_0x48829c,_0x269dba){return db[_0x6f1f('0x26')][_0x6f1f('0x42')]({'where':{'id':_0x48829c[_0x6f1f('0x3f')]['id']}})[_0x6f1f('0x21')](handleEntityNotFound(_0x269dba,null))['then'](removeEntity(_0x269dba,null))[_0x6f1f('0x43')](handleError(_0x269dba,null));};