e4c191606310c530bab5f9004a0b602969b9034d
[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 _0xf2ca=['ejs','fs-extra','lodash','crypto','jsforce','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','set','Content-Range','apply','reject','then','error','stack','name','send','show','params','keys','ChatProactiveAction','rawAttributes','query','filters','intersection','attributes','model','fields','length','includeAll','include','merge','options','find','create','catch','update','body','destroy','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','to-csv'];(function(_0x2a56ad,_0x2b94bf){var _0x425175=function(_0x342f20){while(--_0x342f20){_0x2a56ad['push'](_0x2a56ad['shift']());}};_0x425175(++_0x2b94bf);}(_0xf2ca,0x16a));var _0xaf2c=function(_0x50b1c5,_0x1cf2a9){_0x50b1c5=_0x50b1c5-0x0;var _0x344f99=_0xf2ca[_0x50b1c5];return _0x344f99;};'use strict';var emlformat=require(_0xaf2c('0x0'));var rimraf=require(_0xaf2c('0x1'));var zipdir=require(_0xaf2c('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xaf2c('0x3'));var moment=require(_0xaf2c('0x4'));var BPromise=require(_0xaf2c('0x5'));var Mustache=require(_0xaf2c('0x6'));var util=require(_0xaf2c('0x7'));var path=require(_0xaf2c('0x8'));var sox=require('sox');var csv=require(_0xaf2c('0x9'));var ejs=require(_0xaf2c('0xa'));var fs=require('fs');var fs_extra=require(_0xaf2c('0xb'));var _=require(_0xaf2c('0xc'));var squel=require('squel');var crypto=require(_0xaf2c('0xd'));var jsforce=require(_0xaf2c('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xaf2c('0x9'));var querystring=require('querystring');var Papa=require(_0xaf2c('0xf'));var Redis=require('ioredis');var authService=require(_0xaf2c('0x10'));var qs=require(_0xaf2c('0x11'));var as=require(_0xaf2c('0x12'));var hardwareService=require(_0xaf2c('0x13'));var logger=require('../../config/logger')('api');var utils=require(_0xaf2c('0x14'));var config=require(_0xaf2c('0x15'));var licenseUtil=require(_0xaf2c('0x16'));var db=require(_0xaf2c('0x17'))['db'];function respondWithStatusCode(_0x285dac,_0x59a59b){_0x59a59b=_0x59a59b||0xcc;return function(_0x590126){if(_0x590126){return _0x285dac[_0xaf2c('0x18')](_0x59a59b);}return _0x285dac[_0xaf2c('0x19')](_0x59a59b)[_0xaf2c('0x1a')]();};}function respondWithResult(_0x18a8a5,_0x293ca6){_0x293ca6=_0x293ca6||0xc8;return function(_0x152c73){if(_0x152c73){return _0x18a8a5[_0xaf2c('0x19')](_0x293ca6)[_0xaf2c('0x1b')](_0x152c73);}};}function respondWithFilteredResult(_0x2119c8,_0x1d0633){return function(_0x6ac8e){if(_0x6ac8e){var _0x2b4d13=typeof _0x1d0633[_0xaf2c('0x1c')]===_0xaf2c('0x1d')&&typeof _0x1d0633[_0xaf2c('0x1e')]==='undefined';var _0x3ca650=_0x6ac8e['count'];var _0x278a28=_0x2b4d13?0x0:_0x1d0633[_0xaf2c('0x1c')];var _0x1d544a=_0x2b4d13?_0x6ac8e['count']:_0x1d0633[_0xaf2c('0x1c')]+_0x1d0633[_0xaf2c('0x1e')];var _0x1fec4c;if(_0x1d544a>=_0x3ca650){_0x1d544a=_0x3ca650;_0x1fec4c=0xc8;}else{_0x1fec4c=0xce;}_0x2119c8[_0xaf2c('0x19')](_0x1fec4c);return _0x2119c8[_0xaf2c('0x1f')](_0xaf2c('0x20'),_0x278a28+'-'+_0x1d544a+'/'+_0x3ca650)['json'](_0x6ac8e);}return null;};}function patchUpdates(_0x35e712){return function(_0x164bcb){try{jsonpatch[_0xaf2c('0x21')](_0x164bcb,_0x35e712,!![]);}catch(_0x3bfd3f){return BPromise[_0xaf2c('0x22')](_0x3bfd3f);}return _0x164bcb['save']();};}function saveUpdates(_0x396646,_0xbf6f62){return function(_0x18153c){if(_0x18153c){return _0x18153c['update'](_0x396646)['then'](function(_0x29cbdf){return _0x29cbdf;});}return null;};}function removeEntity(_0x303546,_0x1cafad){return function(_0x99f78d){if(_0x99f78d){return _0x99f78d['destroy']()[_0xaf2c('0x23')](function(){_0x303546[_0xaf2c('0x19')](0xcc)[_0xaf2c('0x1a')]();});}};}function handleEntityNotFound(_0x3c1ae6,_0xe929b5){return function(_0xff396f){if(!_0xff396f){_0x3c1ae6[_0xaf2c('0x18')](0x194);}return _0xff396f;};}function handleError(_0x4a8dd8,_0x29f8b0){_0x29f8b0=_0x29f8b0||0x1f4;return function(_0x2051be){logger[_0xaf2c('0x24')](_0x2051be[_0xaf2c('0x25')]);if(_0x2051be['name']){delete _0x2051be[_0xaf2c('0x26')];}_0x4a8dd8['status'](_0x29f8b0)[_0xaf2c('0x27')](_0x2051be);};}exports[_0xaf2c('0x28')]=function(_0x15466b,_0x5d685a){var _0x2747bb={'raw':!![],'where':{'id':_0x15466b[_0xaf2c('0x29')]['id']}},_0x2ea490={};_0x2ea490['model']=_[_0xaf2c('0x2a')](db[_0xaf2c('0x2b')][_0xaf2c('0x2c')]);_0x2ea490[_0xaf2c('0x2d')]=_['keys'](_0x15466b[_0xaf2c('0x2d')]);_0x2ea490[_0xaf2c('0x2e')]=_[_0xaf2c('0x2f')](_0x2ea490['model'],_0x2ea490['query']);_0x2747bb[_0xaf2c('0x30')]=_['intersection'](_0x2ea490[_0xaf2c('0x31')],qs['fields'](_0x15466b[_0xaf2c('0x2d')][_0xaf2c('0x32')]));_0x2747bb['attributes']=_0x2747bb[_0xaf2c('0x30')][_0xaf2c('0x33')]?_0x2747bb['attributes']:_0x2ea490[_0xaf2c('0x31')];if(_0x15466b[_0xaf2c('0x2d')][_0xaf2c('0x34')]){_0x2747bb[_0xaf2c('0x35')]=[{'all':!![]}];}_0x2747bb=_[_0xaf2c('0x36')]({},_0x2747bb,_0x15466b[_0xaf2c('0x37')]);return db['ChatProactiveAction'][_0xaf2c('0x38')](_0x2747bb)['then'](handleEntityNotFound(_0x5d685a,null))[_0xaf2c('0x23')](respondWithResult(_0x5d685a,null))['catch'](handleError(_0x5d685a,null));};exports[_0xaf2c('0x39')]=function(_0x59f686,_0x2f3d16){return db['ChatProactiveAction'][_0xaf2c('0x39')](_0x59f686['body'],{})[_0xaf2c('0x23')](respondWithResult(_0x2f3d16,0xc9))[_0xaf2c('0x3a')](handleError(_0x2f3d16,null));};exports[_0xaf2c('0x3b')]=function(_0x14ec58,_0x470aff){if(_0x14ec58['body']['id']){delete _0x14ec58['body']['id'];}return db[_0xaf2c('0x2b')][_0xaf2c('0x38')]({'where':{'id':_0x14ec58[_0xaf2c('0x29')]['id']}})[_0xaf2c('0x23')](handleEntityNotFound(_0x470aff,null))[_0xaf2c('0x23')](saveUpdates(_0x14ec58[_0xaf2c('0x3c')],null))['then'](respondWithResult(_0x470aff,null))[_0xaf2c('0x3a')](handleError(_0x470aff,null));};exports[_0xaf2c('0x3d')]=function(_0x4fdc8b,_0x36081a){return db[_0xaf2c('0x2b')][_0xaf2c('0x38')]({'where':{'id':_0x4fdc8b[_0xaf2c('0x29')]['id']}})[_0xaf2c('0x23')](handleEntityNotFound(_0x36081a,null))[_0xaf2c('0x23')](removeEntity(_0x36081a,null))[_0xaf2c('0x3a')](handleError(_0x36081a,null));};