Built motion from commit (unavailable).|2.5.7
[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 _0xff0f=['desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/utils','../../config/license/util','sendStatus','status','json','count','offset','set','apply','save','then','destroy','end','stack','name','send','map','WhatsappApplication','fieldName','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','sort','filter','merge','where','VIRTUAL','options','include','findAll','rows','catch','show','params','rawAttributes','filters','create','update','body','find','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto'];(function(_0x33e84b,_0x5c0c44){var _0x712fb4=function(_0x12759d){while(--_0x12759d){_0x33e84b['push'](_0x33e84b['shift']());}};_0x712fb4(++_0x5c0c44);}(_0xff0f,0x1e2));var _0xfff0=function(_0x34a62b,_0x169578){_0x34a62b=_0x34a62b-0x0;var _0x40e4dc=_0xff0f[_0x34a62b];return _0x40e4dc;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xfff0('0x0'));var rimraf=require(_0xfff0('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xfff0('0x2'));var rp=require(_0xfff0('0x3'));var moment=require(_0xfff0('0x4'));var BPromise=require(_0xfff0('0x5'));var Mustache=require(_0xfff0('0x6'));var util=require(_0xfff0('0x7'));var path=require(_0xfff0('0x8'));var sox=require(_0xfff0('0x9'));var csv=require(_0xfff0('0xa'));var ejs=require(_0xfff0('0xb'));var fs=require('fs');var _=require(_0xfff0('0xc'));var squel=require(_0xfff0('0xd'));var crypto=require(_0xfff0('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xfff0('0xf'));var toCsv=require(_0xfff0('0xa'));var querystring=require(_0xfff0('0x10'));var Papa=require(_0xfff0('0x11'));var Redis=require(_0xfff0('0x12'));var authService=require(_0xfff0('0x13'));var qs=require(_0xfff0('0x14'));var as=require(_0xfff0('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0xfff0('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0xfff0('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x912daa,_0x4f598e){_0x4f598e=_0x4f598e||0xcc;return function(_0x5752aa){if(_0x5752aa){return _0x912daa[_0xfff0('0x18')](_0x4f598e);}return _0x912daa[_0xfff0('0x19')](_0x4f598e)['end']();};}function respondWithResult(_0x5bf7cb,_0xde7ff2){_0xde7ff2=_0xde7ff2||0xc8;return function(_0x446676){if(_0x446676){return _0x5bf7cb[_0xfff0('0x19')](_0xde7ff2)[_0xfff0('0x1a')](_0x446676);}};}function respondWithFilteredResult(_0x6ef117,_0x2f04c3){return function(_0x58e950){if(_0x58e950){var _0x4a7d8c=_0x58e950[_0xfff0('0x1b')],_0x146701=_0x2f04c3['offset'],_0x2aae28=_0x2f04c3[_0xfff0('0x1c')]+_0x2f04c3['limit'],_0x550ba1;if(_0x2aae28>=_0x4a7d8c){_0x2aae28=_0x4a7d8c;_0x550ba1=0xc8;}else{_0x550ba1=0xce;}_0x6ef117[_0xfff0('0x19')](_0x550ba1);return _0x6ef117[_0xfff0('0x1d')]('Content-Range',_0x146701+'-'+_0x2aae28+'/'+_0x4a7d8c)[_0xfff0('0x1a')](_0x58e950);}return null;};}function patchUpdates(_0x11cee5){return function(_0x28938a){try{jsonpatch[_0xfff0('0x1e')](_0x28938a,_0x11cee5,!![]);}catch(_0x3dd073){return BPromise['reject'](_0x3dd073);}return _0x28938a[_0xfff0('0x1f')]();};}function saveUpdates(_0xfbe406,_0x4b4215){return function(_0x4450fb){if(_0x4450fb){return _0x4450fb['update'](_0xfbe406)[_0xfff0('0x20')](function(_0x368c8b){return _0x368c8b;});}return null;};}function removeEntity(_0xff7106,_0x27a2fd){return function(_0x36a6ac){if(_0x36a6ac){return _0x36a6ac[_0xfff0('0x21')]()[_0xfff0('0x20')](function(){_0xff7106[_0xfff0('0x19')](0xcc)[_0xfff0('0x22')]();});}};}function handleEntityNotFound(_0x2af0f0,_0x55c9ee){return function(_0x4049fd){if(!_0x4049fd){_0x2af0f0['sendStatus'](0x194);}return _0x4049fd;};}function handleError(_0x3d319e,_0x3eb81b){_0x3eb81b=_0x3eb81b||0x1f4;return function(_0x4bceb5){logger['error'](_0x4bceb5[_0xfff0('0x23')]);if(_0x4bceb5[_0xfff0('0x24')]){delete _0x4bceb5[_0xfff0('0x24')];}_0x3d319e[_0xfff0('0x19')](_0x3eb81b)[_0xfff0('0x25')](_0x4bceb5);};}exports['index']=function(_0x51cfc1,_0x30f1e9){var _0x2b26e2={},_0x1144a1={},_0x347137={'count':0x0,'rows':[]};var _0x269bb3=_[_0xfff0('0x26')](db[_0xfff0('0x27')]['rawAttributes'],function(_0x7bcc3f){return{'name':_0x7bcc3f[_0xfff0('0x28')],'type':_0x7bcc3f[_0xfff0('0x29')][_0xfff0('0x2a')]};});_0x1144a1[_0xfff0('0x2b')]=_['map'](_0x269bb3,_0xfff0('0x24'));_0x1144a1[_0xfff0('0x2c')]=_[_0xfff0('0x2d')](_0x51cfc1[_0xfff0('0x2c')]);_0x1144a1['filters']=_[_0xfff0('0x2e')](_0x1144a1['model'],_0x1144a1['query']);_0x2b26e2[_0xfff0('0x2f')]=_['intersection'](_0x1144a1[_0xfff0('0x2b')],qs['fields'](_0x51cfc1[_0xfff0('0x2c')][_0xfff0('0x30')]));_0x2b26e2[_0xfff0('0x2f')]=_0x2b26e2[_0xfff0('0x2f')][_0xfff0('0x31')]?_0x2b26e2[_0xfff0('0x2f')]:_0x1144a1[_0xfff0('0x2b')];if(!_0x51cfc1['query'][_0xfff0('0x32')](_0xfff0('0x33'))){_0x2b26e2[_0xfff0('0x34')]=qs['limit'](_0x51cfc1[_0xfff0('0x2c')]['limit']);_0x2b26e2[_0xfff0('0x1c')]=qs[_0xfff0('0x1c')](_0x51cfc1[_0xfff0('0x2c')]['offset']);}_0x2b26e2['order']=qs[_0xfff0('0x35')](_0x51cfc1['query']['sort']);_0x2b26e2['where']=qs['filters'](_['pick'](_0x51cfc1['query'],_0x1144a1['filters']),_0x269bb3);if(_0x51cfc1['query'][_0xfff0('0x36')]){_0x2b26e2['where']=_[_0xfff0('0x37')](_0x2b26e2[_0xfff0('0x38')],{'$or':_[_0xfff0('0x26')](_0x269bb3,function(_0x24cc3b){if(_0x24cc3b[_0xfff0('0x29')]!==_0xfff0('0x39')){var _0x4cd7d5={};_0x4cd7d5[_0x24cc3b[_0xfff0('0x24')]]={'$like':'%'+_0x51cfc1[_0xfff0('0x2c')][_0xfff0('0x36')]+'%'};return _0x4cd7d5;}})});}_0x2b26e2=_[_0xfff0('0x37')]({},_0x2b26e2,_0x51cfc1[_0xfff0('0x3a')]);var _0x526b20={'where':_0x2b26e2[_0xfff0('0x38')]};return db[_0xfff0('0x27')]['count'](_0x526b20)[_0xfff0('0x20')](function(_0x47c012){_0x347137[_0xfff0('0x1b')]=_0x47c012;if(_0x51cfc1[_0xfff0('0x2c')]['includeAll']){_0x2b26e2[_0xfff0('0x3b')]=[{'all':!![]}];}return db[_0xfff0('0x27')][_0xfff0('0x3c')](_0x2b26e2);})['then'](function(_0x34acdc){_0x347137[_0xfff0('0x3d')]=_0x34acdc;return _0x347137;})['then'](respondWithFilteredResult(_0x30f1e9,_0x2b26e2))[_0xfff0('0x3e')](handleError(_0x30f1e9,null));};exports[_0xfff0('0x3f')]=function(_0x42e9a3,_0x3326f5){var _0xa014ec={'raw':!![],'where':{'id':_0x42e9a3[_0xfff0('0x40')]['id']}},_0x157345={};_0x157345[_0xfff0('0x2b')]=_['keys'](db[_0xfff0('0x27')][_0xfff0('0x41')]);_0x157345[_0xfff0('0x2c')]=_[_0xfff0('0x2d')](_0x42e9a3[_0xfff0('0x2c')]);_0x157345[_0xfff0('0x42')]=_[_0xfff0('0x2e')](_0x157345[_0xfff0('0x2b')],_0x157345[_0xfff0('0x2c')]);_0xa014ec[_0xfff0('0x2f')]=_[_0xfff0('0x2e')](_0x157345[_0xfff0('0x2b')],qs[_0xfff0('0x30')](_0x42e9a3[_0xfff0('0x2c')][_0xfff0('0x30')]));_0xa014ec['attributes']=_0xa014ec[_0xfff0('0x2f')]['length']?_0xa014ec[_0xfff0('0x2f')]:_0x157345[_0xfff0('0x2b')];if(_0x42e9a3['query']['includeAll']){_0xa014ec[_0xfff0('0x3b')]=[{'all':!![]}];}_0xa014ec=_[_0xfff0('0x37')]({},_0xa014ec,_0x42e9a3['options']);return db[_0xfff0('0x27')]['find'](_0xa014ec)[_0xfff0('0x20')](handleEntityNotFound(_0x3326f5,null))[_0xfff0('0x20')](respondWithResult(_0x3326f5,null))[_0xfff0('0x3e')](handleError(_0x3326f5,null));};exports['create']=function(_0x123c50,_0x48e19b){return db['WhatsappApplication'][_0xfff0('0x43')](_0x123c50['body'],{})['then'](respondWithResult(_0x48e19b,0xc9))[_0xfff0('0x3e')](handleError(_0x48e19b,null));};exports[_0xfff0('0x44')]=function(_0x36a5b5,_0x2f6fbe){if(_0x36a5b5[_0xfff0('0x45')]['id']){delete _0x36a5b5[_0xfff0('0x45')]['id'];}return db[_0xfff0('0x27')][_0xfff0('0x46')]({'where':{'id':_0x36a5b5[_0xfff0('0x40')]['id']}})[_0xfff0('0x20')](handleEntityNotFound(_0x2f6fbe,null))[_0xfff0('0x20')](saveUpdates(_0x36a5b5[_0xfff0('0x45')],null))[_0xfff0('0x20')](respondWithResult(_0x2f6fbe,null))['catch'](handleError(_0x2f6fbe,null));};exports[_0xfff0('0x21')]=function(_0x1a68d8,_0x5a89a5){return db[_0xfff0('0x27')][_0xfff0('0x46')]({'where':{'id':_0x1a68d8[_0xfff0('0x40')]['id']}})[_0xfff0('0x20')](handleEntityNotFound(_0x5a89a5,null))['then'](removeEntity(_0x5a89a5,null))['catch'](handleError(_0x5a89a5,null));};