Built motion from commit da617fac.|2.6.6
[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 _0x57cf=['include','merge','options','find','catch','create','body','update','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','fs-extra','crypto','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/license/util','sendStatus','end','status','json','undefined','offset','count','set','apply','reject','save','then','error','stack','name','send','params','model','keys','ChatProactiveAction','rawAttributes','query','filters','attributes','fields'];(function(_0x4e4001,_0x3486ef){var _0x30923e=function(_0x591d10){while(--_0x591d10){_0x4e4001['push'](_0x4e4001['shift']());}};_0x30923e(++_0x3486ef);}(_0x57cf,0x11b));var _0xf57c=function(_0x1e3c16,_0x372caa){_0x1e3c16=_0x1e3c16-0x0;var _0x47a0c9=_0x57cf[_0x1e3c16];return _0x47a0c9;};'use strict';var emlformat=require(_0xf57c('0x0'));var rimraf=require(_0xf57c('0x1'));var zipdir=require(_0xf57c('0x2'));var jsonpatch=require(_0xf57c('0x3'));var rp=require(_0xf57c('0x4'));var moment=require(_0xf57c('0x5'));var BPromise=require(_0xf57c('0x6'));var Mustache=require(_0xf57c('0x7'));var util=require(_0xf57c('0x8'));var path=require(_0xf57c('0x9'));var sox=require('sox');var csv=require(_0xf57c('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf57c('0xb'));var _=require('lodash');var squel=require('squel');var crypto=require(_0xf57c('0xc'));var jsforce=require('jsforce');var deskjs=require(_0xf57c('0xd'));var toCsv=require(_0xf57c('0xa'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xf57c('0xe'));var authService=require(_0xf57c('0xf'));var qs=require(_0xf57c('0x10'));var as=require(_0xf57c('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf57c('0x12'))(_0xf57c('0x13'));var utils=require(_0xf57c('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0xf57c('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x27de1b,_0x15e264){_0x15e264=_0x15e264||0xcc;return function(_0x4cc38b){if(_0x4cc38b){return _0x27de1b[_0xf57c('0x16')](_0x15e264);}return _0x27de1b['status'](_0x15e264)[_0xf57c('0x17')]();};}function respondWithResult(_0x598342,_0x23c2b5){_0x23c2b5=_0x23c2b5||0xc8;return function(_0xc56c5){if(_0xc56c5){return _0x598342[_0xf57c('0x18')](_0x23c2b5)[_0xf57c('0x19')](_0xc56c5);}};}function respondWithFilteredResult(_0x168f5c,_0x3d12a0){return function(_0x1fb5f5){if(_0x1fb5f5){var _0x3163eb=typeof _0x3d12a0['offset']===_0xf57c('0x1a')&&typeof _0x3d12a0['limit']===_0xf57c('0x1a');var _0x2d8386=_0x1fb5f5['count'];var _0x385a4f=_0x3163eb?0x0:_0x3d12a0[_0xf57c('0x1b')];var _0x3eb951=_0x3163eb?_0x1fb5f5[_0xf57c('0x1c')]:_0x3d12a0[_0xf57c('0x1b')]+_0x3d12a0['limit'];var _0x3c6e33;if(_0x3eb951>=_0x2d8386){_0x3eb951=_0x2d8386;_0x3c6e33=0xc8;}else{_0x3c6e33=0xce;}_0x168f5c[_0xf57c('0x18')](_0x3c6e33);return _0x168f5c[_0xf57c('0x1d')]('Content-Range',_0x385a4f+'-'+_0x3eb951+'/'+_0x2d8386)['json'](_0x1fb5f5);}return null;};}function patchUpdates(_0x3ac299){return function(_0x1f8a65){try{jsonpatch[_0xf57c('0x1e')](_0x1f8a65,_0x3ac299,!![]);}catch(_0x23a827){return BPromise[_0xf57c('0x1f')](_0x23a827);}return _0x1f8a65[_0xf57c('0x20')]();};}function saveUpdates(_0xea8ee8,_0x396e18){return function(_0xf3baee){if(_0xf3baee){return _0xf3baee['update'](_0xea8ee8)[_0xf57c('0x21')](function(_0x177e74){return _0x177e74;});}return null;};}function removeEntity(_0x551cf0,_0x5ad03e){return function(_0x3c4923){if(_0x3c4923){return _0x3c4923['destroy']()[_0xf57c('0x21')](function(){_0x551cf0[_0xf57c('0x18')](0xcc)[_0xf57c('0x17')]();});}};}function handleEntityNotFound(_0x584bc3,_0xc70f3e){return function(_0x195ae5){if(!_0x195ae5){_0x584bc3['sendStatus'](0x194);}return _0x195ae5;};}function handleError(_0x387d7c,_0x2ac666){_0x2ac666=_0x2ac666||0x1f4;return function(_0x1b12ff){logger[_0xf57c('0x22')](_0x1b12ff[_0xf57c('0x23')]);if(_0x1b12ff[_0xf57c('0x24')]){delete _0x1b12ff[_0xf57c('0x24')];}_0x387d7c[_0xf57c('0x18')](_0x2ac666)[_0xf57c('0x25')](_0x1b12ff);};}exports['show']=function(_0x35e6f8,_0x1f5f3b){var _0x56726f={'raw':!![],'where':{'id':_0x35e6f8[_0xf57c('0x26')]['id']}},_0x2e69e9={};_0x2e69e9[_0xf57c('0x27')]=_[_0xf57c('0x28')](db[_0xf57c('0x29')][_0xf57c('0x2a')]);_0x2e69e9[_0xf57c('0x2b')]=_[_0xf57c('0x28')](_0x35e6f8[_0xf57c('0x2b')]);_0x2e69e9[_0xf57c('0x2c')]=_['intersection'](_0x2e69e9[_0xf57c('0x27')],_0x2e69e9[_0xf57c('0x2b')]);_0x56726f[_0xf57c('0x2d')]=_['intersection'](_0x2e69e9['model'],qs['fields'](_0x35e6f8[_0xf57c('0x2b')][_0xf57c('0x2e')]));_0x56726f[_0xf57c('0x2d')]=_0x56726f[_0xf57c('0x2d')]['length']?_0x56726f[_0xf57c('0x2d')]:_0x2e69e9[_0xf57c('0x27')];if(_0x35e6f8[_0xf57c('0x2b')]['includeAll']){_0x56726f[_0xf57c('0x2f')]=[{'all':!![]}];}_0x56726f=_[_0xf57c('0x30')]({},_0x56726f,_0x35e6f8[_0xf57c('0x31')]);return db[_0xf57c('0x29')][_0xf57c('0x32')](_0x56726f)[_0xf57c('0x21')](handleEntityNotFound(_0x1f5f3b,null))['then'](respondWithResult(_0x1f5f3b,null))[_0xf57c('0x33')](handleError(_0x1f5f3b,null));};exports[_0xf57c('0x34')]=function(_0x4da04a,_0x533795){return db[_0xf57c('0x29')]['create'](_0x4da04a[_0xf57c('0x35')],{})['then'](respondWithResult(_0x533795,0xc9))[_0xf57c('0x33')](handleError(_0x533795,null));};exports[_0xf57c('0x36')]=function(_0x17e8dc,_0x136304){if(_0x17e8dc['body']['id']){delete _0x17e8dc[_0xf57c('0x35')]['id'];}return db['ChatProactiveAction'][_0xf57c('0x32')]({'where':{'id':_0x17e8dc[_0xf57c('0x26')]['id']}})[_0xf57c('0x21')](handleEntityNotFound(_0x136304,null))[_0xf57c('0x21')](saveUpdates(_0x17e8dc[_0xf57c('0x35')],null))[_0xf57c('0x21')](respondWithResult(_0x136304,null))['catch'](handleError(_0x136304,null));};exports['destroy']=function(_0x1d5bf9,_0x26a65b){return db[_0xf57c('0x29')]['find']({'where':{'id':_0x1d5bf9[_0xf57c('0x26')]['id']}})['then'](handleEntityNotFound(_0x26a65b,null))[_0xf57c('0x21')](removeEntity(_0x26a65b,null))[_0xf57c('0x33')](handleError(_0x26a65b,null));};