8fa35c5f3f01a7d2385b09d433b064b9a2b68ed9
[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 _0xbcc7=['find','create','body','catch','eml-format','rimraf','fast-json-patch','bluebird','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','../../components/auth/service','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','count','set','Content-Range','reject','save','update','then','destroy','stack','name','send','show','params','keys','ChatProactiveAction','filters','intersection','model','query','fields','attributes','length','includeAll','include','merge','options'];(function(_0x360678,_0xaf7688){var _0x1b127c=function(_0x1bdebf){while(--_0x1bdebf){_0x360678['push'](_0x360678['shift']());}};_0x1b127c(++_0xaf7688);}(_0xbcc7,0x19a));var _0x7bcc=function(_0x5a4d9c,_0x4f8c2b){_0x5a4d9c=_0x5a4d9c-0x0;var _0xbe8518=_0xbcc7[_0x5a4d9c];return _0xbe8518;};'use strict';var emlformat=require(_0x7bcc('0x0'));var rimraf=require(_0x7bcc('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x7bcc('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x7bcc('0x3'));var Mustache=require('mustache');var util=require(_0x7bcc('0x4'));var path=require(_0x7bcc('0x5'));var sox=require('sox');var csv=require(_0x7bcc('0x6'));var ejs=require(_0x7bcc('0x7'));var fs=require('fs');var fs_extra=require(_0x7bcc('0x8'));var _=require(_0x7bcc('0x9'));var squel=require(_0x7bcc('0xa'));var crypto=require(_0x7bcc('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x7bcc('0xc'));var toCsv=require('to-csv');var querystring=require(_0x7bcc('0xd'));var Papa=require(_0x7bcc('0xe'));var Redis=require('ioredis');var authService=require(_0x7bcc('0xf'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x7bcc('0x10'))(_0x7bcc('0x11'));var utils=require(_0x7bcc('0x12'));var config=require(_0x7bcc('0x13'));var licenseUtil=require(_0x7bcc('0x14'));var db=require(_0x7bcc('0x15'))['db'];function respondWithStatusCode(_0xae46e8,_0x51b0e8){_0x51b0e8=_0x51b0e8||0xcc;return function(_0x3e3580){if(_0x3e3580){return _0xae46e8[_0x7bcc('0x16')](_0x51b0e8);}return _0xae46e8[_0x7bcc('0x17')](_0x51b0e8)[_0x7bcc('0x18')]();};}function respondWithResult(_0x39f912,_0x217896){_0x217896=_0x217896||0xc8;return function(_0x4a2539){if(_0x4a2539){return _0x39f912[_0x7bcc('0x17')](_0x217896)[_0x7bcc('0x19')](_0x4a2539);}};}function respondWithFilteredResult(_0x148618,_0x461ff7){return function(_0x30caa2){if(_0x30caa2){var _0x134d55=typeof _0x461ff7[_0x7bcc('0x1a')]==='undefined'&&typeof _0x461ff7[_0x7bcc('0x1b')]==='undefined';var _0x3156f3=_0x30caa2[_0x7bcc('0x1c')];var _0x340bd6=_0x134d55?0x0:_0x461ff7[_0x7bcc('0x1a')];var _0x49168c=_0x134d55?_0x30caa2['count']:_0x461ff7[_0x7bcc('0x1a')]+_0x461ff7[_0x7bcc('0x1b')];var _0x1a1b7f;if(_0x49168c>=_0x3156f3){_0x49168c=_0x3156f3;_0x1a1b7f=0xc8;}else{_0x1a1b7f=0xce;}_0x148618[_0x7bcc('0x17')](_0x1a1b7f);return _0x148618[_0x7bcc('0x1d')](_0x7bcc('0x1e'),_0x340bd6+'-'+_0x49168c+'/'+_0x3156f3)[_0x7bcc('0x19')](_0x30caa2);}return null;};}function patchUpdates(_0x3d0719){return function(_0x15b2c3){try{jsonpatch['apply'](_0x15b2c3,_0x3d0719,!![]);}catch(_0x553865){return BPromise[_0x7bcc('0x1f')](_0x553865);}return _0x15b2c3[_0x7bcc('0x20')]();};}function saveUpdates(_0x34ee2a,_0x3050cf){return function(_0x201f40){if(_0x201f40){return _0x201f40[_0x7bcc('0x21')](_0x34ee2a)[_0x7bcc('0x22')](function(_0x345671){return _0x345671;});}return null;};}function removeEntity(_0x32b3ea,_0x54c611){return function(_0x2d25b8){if(_0x2d25b8){return _0x2d25b8[_0x7bcc('0x23')]()[_0x7bcc('0x22')](function(){_0x32b3ea[_0x7bcc('0x17')](0xcc)[_0x7bcc('0x18')]();});}};}function handleEntityNotFound(_0x1d085c,_0x4f8562){return function(_0x48b296){if(!_0x48b296){_0x1d085c[_0x7bcc('0x16')](0x194);}return _0x48b296;};}function handleError(_0x4a91d0,_0x4db3c0){_0x4db3c0=_0x4db3c0||0x1f4;return function(_0xd3ca3b){logger['error'](_0xd3ca3b[_0x7bcc('0x24')]);if(_0xd3ca3b[_0x7bcc('0x25')]){delete _0xd3ca3b[_0x7bcc('0x25')];}_0x4a91d0['status'](_0x4db3c0)[_0x7bcc('0x26')](_0xd3ca3b);};}exports[_0x7bcc('0x27')]=function(_0x2e92e1,_0x319943){var _0x20c458={'raw':!![],'where':{'id':_0x2e92e1[_0x7bcc('0x28')]['id']}},_0x1ecf95={};_0x1ecf95['model']=_[_0x7bcc('0x29')](db[_0x7bcc('0x2a')]['rawAttributes']);_0x1ecf95['query']=_[_0x7bcc('0x29')](_0x2e92e1['query']);_0x1ecf95[_0x7bcc('0x2b')]=_[_0x7bcc('0x2c')](_0x1ecf95[_0x7bcc('0x2d')],_0x1ecf95[_0x7bcc('0x2e')]);_0x20c458['attributes']=_[_0x7bcc('0x2c')](_0x1ecf95[_0x7bcc('0x2d')],qs[_0x7bcc('0x2f')](_0x2e92e1['query'][_0x7bcc('0x2f')]));_0x20c458[_0x7bcc('0x30')]=_0x20c458[_0x7bcc('0x30')][_0x7bcc('0x31')]?_0x20c458[_0x7bcc('0x30')]:_0x1ecf95[_0x7bcc('0x2d')];if(_0x2e92e1[_0x7bcc('0x2e')][_0x7bcc('0x32')]){_0x20c458[_0x7bcc('0x33')]=[{'all':!![]}];}_0x20c458=_[_0x7bcc('0x34')]({},_0x20c458,_0x2e92e1[_0x7bcc('0x35')]);return db['ChatProactiveAction'][_0x7bcc('0x36')](_0x20c458)[_0x7bcc('0x22')](handleEntityNotFound(_0x319943,null))[_0x7bcc('0x22')](respondWithResult(_0x319943,null))['catch'](handleError(_0x319943,null));};exports['create']=function(_0x409ff4,_0x1ef50b){return db[_0x7bcc('0x2a')][_0x7bcc('0x37')](_0x409ff4[_0x7bcc('0x38')],{})[_0x7bcc('0x22')](respondWithResult(_0x1ef50b,0xc9))[_0x7bcc('0x39')](handleError(_0x1ef50b,null));};exports['update']=function(_0x5bbb4b,_0x5584f6){if(_0x5bbb4b['body']['id']){delete _0x5bbb4b[_0x7bcc('0x38')]['id'];}return db[_0x7bcc('0x2a')][_0x7bcc('0x36')]({'where':{'id':_0x5bbb4b['params']['id']}})[_0x7bcc('0x22')](handleEntityNotFound(_0x5584f6,null))[_0x7bcc('0x22')](saveUpdates(_0x5bbb4b[_0x7bcc('0x38')],null))['then'](respondWithResult(_0x5584f6,null))['catch'](handleError(_0x5584f6,null));};exports[_0x7bcc('0x23')]=function(_0xca6ce3,_0x1d9c06){return db['ChatProactiveAction']['find']({'where':{'id':_0xca6ce3[_0x7bcc('0x28')]['id']}})[_0x7bcc('0x22')](handleEntityNotFound(_0x1d9c06,null))[_0x7bcc('0x22')](removeEntity(_0x1d9c06,null))['catch'](handleError(_0x1d9c06,null));};