d390a7edbe393eac9e52c7a5d575586847a616d9
[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 _0x9aee=['body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','ejs','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','update','destroy','end','error','name','send','params','model','keys','ChatProactiveAction','query','filters','intersection','attributes','fields','include','options','find','then','catch','create'];(function(_0x1d4ea9,_0x3f1d85){var _0x2cf5eb=function(_0x145f17){while(--_0x145f17){_0x1d4ea9['push'](_0x1d4ea9['shift']());}};_0x2cf5eb(++_0x3f1d85);}(_0x9aee,0x71));var _0xe9ae=function(_0x440f53,_0x58aa56){_0x440f53=_0x440f53-0x0;var _0x190b07=_0x9aee[_0x440f53];return _0x190b07;};'use strict';var emlformat=require(_0xe9ae('0x0'));var rimraf=require(_0xe9ae('0x1'));var zipdir=require(_0xe9ae('0x2'));var jsonpatch=require(_0xe9ae('0x3'));var rp=require(_0xe9ae('0x4'));var moment=require(_0xe9ae('0x5'));var BPromise=require(_0xe9ae('0x6'));var Mustache=require(_0xe9ae('0x7'));var util=require(_0xe9ae('0x8'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xe9ae('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0xe9ae('0xa'));var crypto=require('crypto');var jsforce=require(_0xe9ae('0xb'));var deskjs=require(_0xe9ae('0xc'));var toCsv=require('to-csv');var querystring=require(_0xe9ae('0xd'));var Papa=require(_0xe9ae('0xe'));var Redis=require(_0xe9ae('0xf'));var authService=require('../../components/auth/service');var qs=require(_0xe9ae('0x10'));var as=require(_0xe9ae('0x11'));var hardwareService=require(_0xe9ae('0x12'));var logger=require('../../config/logger')(_0xe9ae('0x13'));var utils=require('../../config/utils');var config=require(_0xe9ae('0x14'));var licenseUtil=require(_0xe9ae('0x15'));var db=require(_0xe9ae('0x16'))['db'];function respondWithStatusCode(_0x1833c9,_0x3f55e5){_0x3f55e5=_0x3f55e5||0xcc;return function(_0x1be4dd){if(_0x1be4dd){return _0x1833c9[_0xe9ae('0x17')](_0x3f55e5);}return _0x1833c9[_0xe9ae('0x18')](_0x3f55e5)['end']();};}function respondWithResult(_0x2f2c3b,_0x38b4af){_0x38b4af=_0x38b4af||0xc8;return function(_0x4e8869){if(_0x4e8869){return _0x2f2c3b[_0xe9ae('0x18')](_0x38b4af)[_0xe9ae('0x19')](_0x4e8869);}};}function respondWithFilteredResult(_0x44fa8c,_0x43963c){return function(_0x3ef25b){if(_0x3ef25b){var _0x1fd836=typeof _0x43963c[_0xe9ae('0x1a')]===_0xe9ae('0x1b')&&typeof _0x43963c[_0xe9ae('0x1c')]==='undefined';var _0x5b18ae=_0x3ef25b[_0xe9ae('0x1d')];var _0x4bae07=_0x1fd836?0x0:_0x43963c[_0xe9ae('0x1a')];var _0x32748a=_0x1fd836?_0x3ef25b[_0xe9ae('0x1d')]:_0x43963c[_0xe9ae('0x1a')]+_0x43963c['limit'];var _0x4e9e93;if(_0x32748a>=_0x5b18ae){_0x32748a=_0x5b18ae;_0x4e9e93=0xc8;}else{_0x4e9e93=0xce;}_0x44fa8c['status'](_0x4e9e93);return _0x44fa8c[_0xe9ae('0x1e')](_0xe9ae('0x1f'),_0x4bae07+'-'+_0x32748a+'/'+_0x5b18ae)['json'](_0x3ef25b);}return null;};}function patchUpdates(_0x1ad4d5){return function(_0x49fc40){try{jsonpatch[_0xe9ae('0x20')](_0x49fc40,_0x1ad4d5,!![]);}catch(_0x324de0){return BPromise[_0xe9ae('0x21')](_0x324de0);}return _0x49fc40['save']();};}function saveUpdates(_0x4a7568,_0x475b7a){return function(_0x206bd7){if(_0x206bd7){return _0x206bd7[_0xe9ae('0x22')](_0x4a7568)['then'](function(_0x36285a){return _0x36285a;});}return null;};}function removeEntity(_0x29d690,_0x31e94f){return function(_0x3fd466){if(_0x3fd466){return _0x3fd466[_0xe9ae('0x23')]()['then'](function(){_0x29d690[_0xe9ae('0x18')](0xcc)[_0xe9ae('0x24')]();});}};}function handleEntityNotFound(_0x9f1726,_0x209236){return function(_0x5cec8a){if(!_0x5cec8a){_0x9f1726[_0xe9ae('0x17')](0x194);}return _0x5cec8a;};}function handleError(_0x5195ce,_0x3e78ca){_0x3e78ca=_0x3e78ca||0x1f4;return function(_0x18e5b3){logger[_0xe9ae('0x25')](_0x18e5b3['stack']);if(_0x18e5b3[_0xe9ae('0x26')]){delete _0x18e5b3[_0xe9ae('0x26')];}_0x5195ce[_0xe9ae('0x18')](_0x3e78ca)[_0xe9ae('0x27')](_0x18e5b3);};}exports['show']=function(_0x266f36,_0x3db24e){var _0x483df4={'raw':!![],'where':{'id':_0x266f36[_0xe9ae('0x28')]['id']}},_0x4ac613={};_0x4ac613[_0xe9ae('0x29')]=_[_0xe9ae('0x2a')](db[_0xe9ae('0x2b')]['rawAttributes']);_0x4ac613[_0xe9ae('0x2c')]=_['keys'](_0x266f36[_0xe9ae('0x2c')]);_0x4ac613[_0xe9ae('0x2d')]=_[_0xe9ae('0x2e')](_0x4ac613[_0xe9ae('0x29')],_0x4ac613[_0xe9ae('0x2c')]);_0x483df4[_0xe9ae('0x2f')]=_['intersection'](_0x4ac613[_0xe9ae('0x29')],qs[_0xe9ae('0x30')](_0x266f36[_0xe9ae('0x2c')][_0xe9ae('0x30')]));_0x483df4[_0xe9ae('0x2f')]=_0x483df4[_0xe9ae('0x2f')]['length']?_0x483df4[_0xe9ae('0x2f')]:_0x4ac613[_0xe9ae('0x29')];if(_0x266f36[_0xe9ae('0x2c')]['includeAll']){_0x483df4[_0xe9ae('0x31')]=[{'all':!![]}];}_0x483df4=_['merge']({},_0x483df4,_0x266f36[_0xe9ae('0x32')]);return db[_0xe9ae('0x2b')][_0xe9ae('0x33')](_0x483df4)['then'](handleEntityNotFound(_0x3db24e,null))[_0xe9ae('0x34')](respondWithResult(_0x3db24e,null))[_0xe9ae('0x35')](handleError(_0x3db24e,null));};exports[_0xe9ae('0x36')]=function(_0x416bae,_0x161c77){return db[_0xe9ae('0x2b')]['create'](_0x416bae[_0xe9ae('0x37')],{})[_0xe9ae('0x34')](respondWithResult(_0x161c77,0xc9))['catch'](handleError(_0x161c77,null));};exports[_0xe9ae('0x22')]=function(_0x2813a0,_0x22c47c){if(_0x2813a0['body']['id']){delete _0x2813a0[_0xe9ae('0x37')]['id'];}return db['ChatProactiveAction'][_0xe9ae('0x33')]({'where':{'id':_0x2813a0[_0xe9ae('0x28')]['id']}})[_0xe9ae('0x34')](handleEntityNotFound(_0x22c47c,null))[_0xe9ae('0x34')](saveUpdates(_0x2813a0['body'],null))[_0xe9ae('0x34')](respondWithResult(_0x22c47c,null))['catch'](handleError(_0x22c47c,null));};exports[_0xe9ae('0x23')]=function(_0x50d500,_0x52e381){return db[_0xe9ae('0x2b')]['find']({'where':{'id':_0x50d500[_0xe9ae('0x28')]['id']}})[_0xe9ae('0x34')](handleEntityNotFound(_0x52e381,null))[_0xe9ae('0x34')](removeEntity(_0x52e381,null))[_0xe9ae('0x35')](handleError(_0x52e381,null));};