Built motion from commit d5e4af8c.|2.6.23
[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 _0xbacb=['params','model','ChatProactiveAction','rawAttributes','query','keys','filters','attributes','fields','include','merge','options','catch','create','body','find','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','limit','set','Content-Range','apply','reject','update','destroy','then','error','stack','name','send'];(function(_0x32111c,_0x2c2983){var _0x54a797=function(_0x2291a1){while(--_0x2291a1){_0x32111c['push'](_0x32111c['shift']());}};_0x54a797(++_0x2c2983);}(_0xbacb,0x1a6));var _0xbbac=function(_0x12db7d,_0x5b8bfc){_0x12db7d=_0x12db7d-0x0;var _0x5336ce=_0xbacb[_0x12db7d];return _0x5336ce;};'use strict';var emlformat=require(_0xbbac('0x0'));var rimraf=require(_0xbbac('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xbbac('0x2'));var rp=require(_0xbbac('0x3'));var moment=require(_0xbbac('0x4'));var BPromise=require(_0xbbac('0x5'));var Mustache=require(_0xbbac('0x6'));var util=require(_0xbbac('0x7'));var path=require('path');var sox=require('sox');var csv=require(_0xbbac('0x8'));var ejs=require(_0xbbac('0x9'));var fs=require('fs');var fs_extra=require(_0xbbac('0xa'));var _=require(_0xbbac('0xb'));var squel=require('squel');var crypto=require(_0xbbac('0xc'));var jsforce=require(_0xbbac('0xd'));var deskjs=require(_0xbbac('0xe'));var toCsv=require(_0xbbac('0x8'));var querystring=require(_0xbbac('0xf'));var Papa=require(_0xbbac('0x10'));var Redis=require('ioredis');var authService=require(_0xbbac('0x11'));var qs=require(_0xbbac('0x12'));var as=require(_0xbbac('0x13'));var hardwareService=require(_0xbbac('0x14'));var logger=require(_0xbbac('0x15'))('api');var utils=require('../../config/utils');var config=require(_0xbbac('0x16'));var licenseUtil=require(_0xbbac('0x17'));var db=require(_0xbbac('0x18'))['db'];function respondWithStatusCode(_0x480405,_0x8a7118){_0x8a7118=_0x8a7118||0xcc;return function(_0x5de0a7){if(_0x5de0a7){return _0x480405[_0xbbac('0x19')](_0x8a7118);}return _0x480405[_0xbbac('0x1a')](_0x8a7118)['end']();};}function respondWithResult(_0x304acc,_0x24123b){_0x24123b=_0x24123b||0xc8;return function(_0x487693){if(_0x487693){return _0x304acc[_0xbbac('0x1a')](_0x24123b)[_0xbbac('0x1b')](_0x487693);}};}function respondWithFilteredResult(_0x2d60b2,_0x131207){return function(_0x58d599){if(_0x58d599){var _0x25beac=typeof _0x131207[_0xbbac('0x1c')]===_0xbbac('0x1d')&&typeof _0x131207[_0xbbac('0x1e')]===_0xbbac('0x1d');var _0x597916=_0x58d599['count'];var _0x1ed67d=_0x25beac?0x0:_0x131207[_0xbbac('0x1c')];var _0x3e133c=_0x25beac?_0x58d599['count']:_0x131207['offset']+_0x131207[_0xbbac('0x1e')];var _0x39d6c7;if(_0x3e133c>=_0x597916){_0x3e133c=_0x597916;_0x39d6c7=0xc8;}else{_0x39d6c7=0xce;}_0x2d60b2[_0xbbac('0x1a')](_0x39d6c7);return _0x2d60b2[_0xbbac('0x1f')](_0xbbac('0x20'),_0x1ed67d+'-'+_0x3e133c+'/'+_0x597916)[_0xbbac('0x1b')](_0x58d599);}return null;};}function patchUpdates(_0x1de1e1){return function(_0x355543){try{jsonpatch[_0xbbac('0x21')](_0x355543,_0x1de1e1,!![]);}catch(_0x4cca95){return BPromise[_0xbbac('0x22')](_0x4cca95);}return _0x355543['save']();};}function saveUpdates(_0x389e73,_0x112376){return function(_0x5e1d58){if(_0x5e1d58){return _0x5e1d58[_0xbbac('0x23')](_0x389e73)['then'](function(_0x2ee598){return _0x2ee598;});}return null;};}function removeEntity(_0x25514d,_0x46e6ba){return function(_0x155d3b){if(_0x155d3b){return _0x155d3b[_0xbbac('0x24')]()[_0xbbac('0x25')](function(){_0x25514d[_0xbbac('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x11fdf4,_0x24a77f){return function(_0x3ead07){if(!_0x3ead07){_0x11fdf4[_0xbbac('0x19')](0x194);}return _0x3ead07;};}function handleError(_0x4bb179,_0x448ad5){_0x448ad5=_0x448ad5||0x1f4;return function(_0x19681c){logger[_0xbbac('0x26')](_0x19681c[_0xbbac('0x27')]);if(_0x19681c[_0xbbac('0x28')]){delete _0x19681c['name'];}_0x4bb179[_0xbbac('0x1a')](_0x448ad5)[_0xbbac('0x29')](_0x19681c);};}exports['show']=function(_0x4c1497,_0x15e60e){var _0x48e768={'raw':!![],'where':{'id':_0x4c1497[_0xbbac('0x2a')]['id']}},_0x10c4ae={};_0x10c4ae[_0xbbac('0x2b')]=_['keys'](db[_0xbbac('0x2c')][_0xbbac('0x2d')]);_0x10c4ae[_0xbbac('0x2e')]=_[_0xbbac('0x2f')](_0x4c1497[_0xbbac('0x2e')]);_0x10c4ae[_0xbbac('0x30')]=_['intersection'](_0x10c4ae['model'],_0x10c4ae[_0xbbac('0x2e')]);_0x48e768[_0xbbac('0x31')]=_['intersection'](_0x10c4ae[_0xbbac('0x2b')],qs[_0xbbac('0x32')](_0x4c1497['query'][_0xbbac('0x32')]));_0x48e768[_0xbbac('0x31')]=_0x48e768[_0xbbac('0x31')]['length']?_0x48e768[_0xbbac('0x31')]:_0x10c4ae[_0xbbac('0x2b')];if(_0x4c1497[_0xbbac('0x2e')]['includeAll']){_0x48e768[_0xbbac('0x33')]=[{'all':!![]}];}_0x48e768=_[_0xbbac('0x34')]({},_0x48e768,_0x4c1497[_0xbbac('0x35')]);return db['ChatProactiveAction']['find'](_0x48e768)['then'](handleEntityNotFound(_0x15e60e,null))[_0xbbac('0x25')](respondWithResult(_0x15e60e,null))[_0xbbac('0x36')](handleError(_0x15e60e,null));};exports[_0xbbac('0x37')]=function(_0x1682d4,_0x496a4b){return db['ChatProactiveAction'][_0xbbac('0x37')](_0x1682d4[_0xbbac('0x38')],{})[_0xbbac('0x25')](respondWithResult(_0x496a4b,0xc9))[_0xbbac('0x36')](handleError(_0x496a4b,null));};exports[_0xbbac('0x23')]=function(_0xc167fd,_0x295f30){if(_0xc167fd['body']['id']){delete _0xc167fd[_0xbbac('0x38')]['id'];}return db[_0xbbac('0x2c')]['find']({'where':{'id':_0xc167fd['params']['id']}})[_0xbbac('0x25')](handleEntityNotFound(_0x295f30,null))['then'](saveUpdates(_0xc167fd['body'],null))['then'](respondWithResult(_0x295f30,null))[_0xbbac('0x36')](handleError(_0x295f30,null));};exports[_0xbbac('0x24')]=function(_0x586e49,_0x2bfa0b){return db[_0xbbac('0x2c')][_0xbbac('0x39')]({'where':{'id':_0x586e49[_0xbbac('0x2a')]['id']}})[_0xbbac('0x25')](handleEntityNotFound(_0x2bfa0b,null))[_0xbbac('0x25')](removeEntity(_0x2bfa0b,null))[_0xbbac('0x36')](handleError(_0x2bfa0b,null));};