Built motion from commit 0c5f406c.|2.6.29
[motion2.git] / server / api / chatProactiveAction / chatProactiveAction.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 _0x34f2=['../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','json','reject','save','update','then','destroy','error','stack','name','send','params','model','keys','ChatProactiveAction','rawAttributes','query','intersection','attributes','fields','length','merge','find','catch','create','body','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','../../components/auth/service','../../components/parsers/qs'];(function(_0x722d30,_0x1633a3){var _0x22b826=function(_0x2fc0e0){while(--_0x2fc0e0){_0x722d30['push'](_0x722d30['shift']());}};_0x22b826(++_0x1633a3);}(_0x34f2,0x15a));var _0x234f=function(_0x3c41d8,_0x15f585){_0x3c41d8=_0x3c41d8-0x0;var _0x3338a7=_0x34f2[_0x3c41d8];return _0x3338a7;};'use strict';var emlformat=require(_0x234f('0x0'));var rimraf=require(_0x234f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x234f('0x2'));var rp=require(_0x234f('0x3'));var moment=require(_0x234f('0x4'));var BPromise=require(_0x234f('0x5'));var Mustache=require(_0x234f('0x6'));var util=require(_0x234f('0x7'));var path=require(_0x234f('0x8'));var sox=require(_0x234f('0x9'));var csv=require(_0x234f('0xa'));var ejs=require(_0x234f('0xb'));var fs=require('fs');var fs_extra=require(_0x234f('0xc'));var _=require(_0x234f('0xd'));var squel=require(_0x234f('0xe'));var crypto=require(_0x234f('0xf'));var jsforce=require(_0x234f('0x10'));var deskjs=require('desk.js');var toCsv=require(_0x234f('0xa'));var querystring=require(_0x234f('0x11'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x234f('0x12'));var qs=require(_0x234f('0x13'));var as=require(_0x234f('0x14'));var hardwareService=require(_0x234f('0x15'));var logger=require(_0x234f('0x16'))('api');var utils=require(_0x234f('0x17'));var config=require(_0x234f('0x18'));var licenseUtil=require(_0x234f('0x19'));var db=require(_0x234f('0x1a'))['db'];function respondWithStatusCode(_0x518485,_0x41f471){_0x41f471=_0x41f471||0xcc;return function(_0x4aefa2){if(_0x4aefa2){return _0x518485[_0x234f('0x1b')](_0x41f471);}return _0x518485[_0x234f('0x1c')](_0x41f471)[_0x234f('0x1d')]();};}function respondWithResult(_0x31c3d6,_0x2fea04){_0x2fea04=_0x2fea04||0xc8;return function(_0x10ee30){if(_0x10ee30){return _0x31c3d6[_0x234f('0x1c')](_0x2fea04)['json'](_0x10ee30);}};}function respondWithFilteredResult(_0x5ada71,_0x2d47cf){return function(_0x162275){if(_0x162275){var _0x5f0e9c=typeof _0x2d47cf[_0x234f('0x1e')]===_0x234f('0x1f')&&typeof _0x2d47cf[_0x234f('0x20')]===_0x234f('0x1f');var _0x304c08=_0x162275[_0x234f('0x21')];var _0x144ea0=_0x5f0e9c?0x0:_0x2d47cf[_0x234f('0x1e')];var _0x77399f=_0x5f0e9c?_0x162275['count']:_0x2d47cf[_0x234f('0x1e')]+_0x2d47cf[_0x234f('0x20')];var _0x357ecb;if(_0x77399f>=_0x304c08){_0x77399f=_0x304c08;_0x357ecb=0xc8;}else{_0x357ecb=0xce;}_0x5ada71[_0x234f('0x1c')](_0x357ecb);return _0x5ada71[_0x234f('0x22')](_0x234f('0x23'),_0x144ea0+'-'+_0x77399f+'/'+_0x304c08)[_0x234f('0x24')](_0x162275);}return null;};}function patchUpdates(_0x2f68cf){return function(_0x45b3c0){try{jsonpatch['apply'](_0x45b3c0,_0x2f68cf,!![]);}catch(_0x5e7edd){return BPromise[_0x234f('0x25')](_0x5e7edd);}return _0x45b3c0[_0x234f('0x26')]();};}function saveUpdates(_0x516c6e,_0x2539d9){return function(_0x4ca657){if(_0x4ca657){return _0x4ca657[_0x234f('0x27')](_0x516c6e)[_0x234f('0x28')](function(_0x17a23c){return _0x17a23c;});}return null;};}function removeEntity(_0x2acafc,_0x34cc19){return function(_0x434e9f){if(_0x434e9f){return _0x434e9f[_0x234f('0x29')]()[_0x234f('0x28')](function(){_0x2acafc[_0x234f('0x1c')](0xcc)[_0x234f('0x1d')]();});}};}function handleEntityNotFound(_0x758e8d,_0xd8ffbf){return function(_0x15de29){if(!_0x15de29){_0x758e8d[_0x234f('0x1b')](0x194);}return _0x15de29;};}function handleError(_0x3ce565,_0x371292){_0x371292=_0x371292||0x1f4;return function(_0x2b6641){logger[_0x234f('0x2a')](_0x2b6641[_0x234f('0x2b')]);if(_0x2b6641[_0x234f('0x2c')]){delete _0x2b6641[_0x234f('0x2c')];}_0x3ce565[_0x234f('0x1c')](_0x371292)[_0x234f('0x2d')](_0x2b6641);};}exports['show']=function(_0x1f6032,_0xffda12){var _0x1b3762={'raw':!![],'where':{'id':_0x1f6032[_0x234f('0x2e')]['id']}},_0x2522b1={};_0x2522b1[_0x234f('0x2f')]=_[_0x234f('0x30')](db[_0x234f('0x31')][_0x234f('0x32')]);_0x2522b1[_0x234f('0x33')]=_['keys'](_0x1f6032[_0x234f('0x33')]);_0x2522b1['filters']=_[_0x234f('0x34')](_0x2522b1[_0x234f('0x2f')],_0x2522b1[_0x234f('0x33')]);_0x1b3762[_0x234f('0x35')]=_['intersection'](_0x2522b1[_0x234f('0x2f')],qs[_0x234f('0x36')](_0x1f6032[_0x234f('0x33')]['fields']));_0x1b3762['attributes']=_0x1b3762[_0x234f('0x35')][_0x234f('0x37')]?_0x1b3762['attributes']:_0x2522b1['model'];if(_0x1f6032[_0x234f('0x33')]['includeAll']){_0x1b3762['include']=[{'all':!![]}];}_0x1b3762=_[_0x234f('0x38')]({},_0x1b3762,_0x1f6032['options']);return db[_0x234f('0x31')][_0x234f('0x39')](_0x1b3762)[_0x234f('0x28')](handleEntityNotFound(_0xffda12,null))[_0x234f('0x28')](respondWithResult(_0xffda12,null))[_0x234f('0x3a')](handleError(_0xffda12,null));};exports[_0x234f('0x3b')]=function(_0x8590f2,_0x1f923f){return db[_0x234f('0x31')]['create'](_0x8590f2[_0x234f('0x3c')],{})[_0x234f('0x28')](respondWithResult(_0x1f923f,0xc9))[_0x234f('0x3a')](handleError(_0x1f923f,null));};exports[_0x234f('0x27')]=function(_0x34567c,_0x156f25){if(_0x34567c[_0x234f('0x3c')]['id']){delete _0x34567c[_0x234f('0x3c')]['id'];}return db['ChatProactiveAction'][_0x234f('0x39')]({'where':{'id':_0x34567c[_0x234f('0x2e')]['id']}})[_0x234f('0x28')](handleEntityNotFound(_0x156f25,null))[_0x234f('0x28')](saveUpdates(_0x34567c['body'],null))['then'](respondWithResult(_0x156f25,null))['catch'](handleError(_0x156f25,null));};exports[_0x234f('0x29')]=function(_0x4adefe,_0x41e124){return db[_0x234f('0x31')][_0x234f('0x39')]({'where':{'id':_0x4adefe[_0x234f('0x2e')]['id']}})[_0x234f('0x28')](handleEntityNotFound(_0x41e124,null))[_0x234f('0x28')](removeEntity(_0x41e124,null))[_0x234f('0x3a')](handleError(_0x41e124,null));};