Built motion from commit (unavailable).|2.4.4
[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 _0x1d15=['request-promise','moment','mustache','path','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','sendStatus','status','count','offset','set','Content-Range','json','apply','reject','save','update','then','end','error','name','send','show','model','keys','ChatProactiveAction','rawAttributes','query','filters','intersection','attributes','fields','length','merge','catch','create','body','find','params','destroy','eml-format','zip-dir','fast-json-patch'];(function(_0x5af9b8,_0x2655f1){var _0x315e09=function(_0xe78853){while(--_0xe78853){_0x5af9b8['push'](_0x5af9b8['shift']());}};_0x315e09(++_0x2655f1);}(_0x1d15,0x1bd));var _0x51d1=function(_0x508e1a,_0x4e6318){_0x508e1a=_0x508e1a-0x0;var _0x3e23c0=_0x1d15[_0x508e1a];return _0x3e23c0;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x51d1('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x51d1('0x1'));var jsonpatch=require(_0x51d1('0x2'));var rp=require(_0x51d1('0x3'));var moment=require(_0x51d1('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x51d1('0x5'));var util=require('util');var path=require(_0x51d1('0x6'));var sox=require('sox');var csv=require(_0x51d1('0x7'));var ejs=require(_0x51d1('0x8'));var fs=require('fs');var _=require('lodash');var squel=require(_0x51d1('0x9'));var crypto=require(_0x51d1('0xa'));var jsforce=require(_0x51d1('0xb'));var deskjs=require(_0x51d1('0xc'));var toCsv=require(_0x51d1('0x7'));var querystring=require(_0x51d1('0xd'));var Papa=require(_0x51d1('0xe'));var Redis=require('ioredis');var authService=require(_0x51d1('0xf'));var qs=require(_0x51d1('0x10'));var hardwareService=require(_0x51d1('0x11'));var logger=require(_0x51d1('0x12'))(_0x51d1('0x13'));var utils=require(_0x51d1('0x14'));var config=require('../../config/environment');var db=require(_0x51d1('0x15'))['db'];function respondWithStatusCode(_0x411e47,_0x4a9e13){_0x4a9e13=_0x4a9e13||0xcc;return function(_0x179e66){if(_0x179e66){return _0x411e47[_0x51d1('0x16')](_0x4a9e13);}return _0x411e47[_0x51d1('0x17')](_0x4a9e13)['end']();};}function respondWithResult(_0x47ca12,_0x185a31){_0x185a31=_0x185a31||0xc8;return function(_0x3ede8c){if(_0x3ede8c){return _0x47ca12[_0x51d1('0x17')](_0x185a31)['json'](_0x3ede8c);}};}function respondWithFilteredResult(_0x39c3e3,_0x50a6ed){return function(_0x4f99cf){if(_0x4f99cf){var _0x1ac473=_0x4f99cf[_0x51d1('0x18')],_0x410c29=_0x50a6ed[_0x51d1('0x19')],_0x332d98=_0x50a6ed[_0x51d1('0x19')]+_0x50a6ed['limit'],_0x4e9d63;if(_0x332d98>=_0x1ac473){_0x332d98=_0x1ac473;_0x4e9d63=0xc8;}else{_0x4e9d63=0xce;}_0x39c3e3[_0x51d1('0x17')](_0x4e9d63);return _0x39c3e3[_0x51d1('0x1a')](_0x51d1('0x1b'),_0x410c29+'-'+_0x332d98+'/'+_0x1ac473)[_0x51d1('0x1c')](_0x4f99cf);}return null;};}function patchUpdates(_0x1e6acb){return function(_0x34c8c8){try{jsonpatch[_0x51d1('0x1d')](_0x34c8c8,_0x1e6acb,!![]);}catch(_0x5b3748){return BPromise[_0x51d1('0x1e')](_0x5b3748);}return _0x34c8c8[_0x51d1('0x1f')]();};}function saveUpdates(_0x1163f2,_0x14183b){return function(_0x12a7f7){if(_0x12a7f7){return _0x12a7f7[_0x51d1('0x20')](_0x1163f2)['then'](function(_0x1a4ba4){return _0x1a4ba4;});}return null;};}function removeEntity(_0x346374,_0x4079ca){return function(_0x28f5f4){if(_0x28f5f4){return _0x28f5f4['destroy']()[_0x51d1('0x21')](function(){_0x346374['status'](0xcc)[_0x51d1('0x22')]();});}};}function handleEntityNotFound(_0x4006d0,_0x2a2dcf){return function(_0x387624){if(!_0x387624){_0x4006d0[_0x51d1('0x16')](0x194);}return _0x387624;};}function handleError(_0x19833e,_0x2c63b7){_0x2c63b7=_0x2c63b7||0x1f4;return function(_0x46e8f3){logger[_0x51d1('0x23')](_0x46e8f3['stack']);if(_0x46e8f3[_0x51d1('0x24')]){delete _0x46e8f3['name'];}_0x19833e[_0x51d1('0x17')](_0x2c63b7)[_0x51d1('0x25')](_0x46e8f3);};}exports[_0x51d1('0x26')]=function(_0x1df125,_0xdb7b35){var _0x5c6c57={'raw':!![],'where':{'id':_0x1df125['params']['id']}},_0x5bd77b={};_0x5bd77b[_0x51d1('0x27')]=_[_0x51d1('0x28')](db[_0x51d1('0x29')][_0x51d1('0x2a')]);_0x5bd77b[_0x51d1('0x2b')]=_['keys'](_0x1df125[_0x51d1('0x2b')]);_0x5bd77b[_0x51d1('0x2c')]=_[_0x51d1('0x2d')](_0x5bd77b[_0x51d1('0x27')],_0x5bd77b['query']);_0x5c6c57[_0x51d1('0x2e')]=_[_0x51d1('0x2d')](_0x5bd77b[_0x51d1('0x27')],qs['fields'](_0x1df125['query'][_0x51d1('0x2f')]));_0x5c6c57[_0x51d1('0x2e')]=_0x5c6c57[_0x51d1('0x2e')][_0x51d1('0x30')]?_0x5c6c57['attributes']:_0x5bd77b[_0x51d1('0x27')];if(_0x1df125[_0x51d1('0x2b')]['includeAll']){_0x5c6c57['include']=[{'all':!![]}];}_0x5c6c57=_[_0x51d1('0x31')]({},_0x5c6c57,_0x1df125['options']);return db[_0x51d1('0x29')]['find'](_0x5c6c57)[_0x51d1('0x21')](handleEntityNotFound(_0xdb7b35,null))['then'](respondWithResult(_0xdb7b35,null))[_0x51d1('0x32')](handleError(_0xdb7b35,null));};exports[_0x51d1('0x33')]=function(_0x43fe89,_0x24a964){return db[_0x51d1('0x29')][_0x51d1('0x33')](_0x43fe89[_0x51d1('0x34')],{})[_0x51d1('0x21')](respondWithResult(_0x24a964,0xc9))[_0x51d1('0x32')](handleError(_0x24a964,null));};exports[_0x51d1('0x20')]=function(_0x3e0ba9,_0x269a07){if(_0x3e0ba9[_0x51d1('0x34')]['id']){delete _0x3e0ba9['body']['id'];}return db[_0x51d1('0x29')][_0x51d1('0x35')]({'where':{'id':_0x3e0ba9[_0x51d1('0x36')]['id']}})['then'](handleEntityNotFound(_0x269a07,null))[_0x51d1('0x21')](saveUpdates(_0x3e0ba9['body'],null))[_0x51d1('0x21')](respondWithResult(_0x269a07,null))[_0x51d1('0x32')](handleError(_0x269a07,null));};exports[_0x51d1('0x37')]=function(_0x385677,_0x12e5a3){return db['ChatProactiveAction'][_0x51d1('0x35')]({'where':{'id':_0x385677[_0x51d1('0x36')]['id']}})['then'](handleEntityNotFound(_0x12e5a3,null))[_0x51d1('0x21')](removeEntity(_0x12e5a3,null))['catch'](handleError(_0x12e5a3,null));};