c74036f6558fa417c987b9a8a401082725dc7f10
[motion2.git] / server / api / chatApplication / chatApplication.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 _0xbf6e=['save','update','then','destroy','error','name','send','show','model','keys','rawAttributes','query','filters','intersection','attributes','fields','includeAll','include','merge','ChatApplication','find','body','params','catch','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0xbf6e,0x149));var _0xebf6=function(_0x1b1cf1,_0x252de7){_0x1b1cf1=_0x1b1cf1-0x0;var _0x383298=_0xbf6e[_0x1b1cf1];return _0x383298;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xebf6('0x0'));var jsonpatch=require(_0xebf6('0x1'));var rp=require(_0xebf6('0x2'));var moment=require(_0xebf6('0x3'));var BPromise=require(_0xebf6('0x4'));var Mustache=require(_0xebf6('0x5'));var util=require(_0xebf6('0x6'));var path=require('path');var sox=require(_0xebf6('0x7'));var csv=require(_0xebf6('0x8'));var ejs=require(_0xebf6('0x9'));var fs=require('fs');var fs_extra=require(_0xebf6('0xa'));var _=require(_0xebf6('0xb'));var squel=require(_0xebf6('0xc'));var crypto=require(_0xebf6('0xd'));var jsforce=require('jsforce');var deskjs=require(_0xebf6('0xe'));var toCsv=require(_0xebf6('0x8'));var querystring=require(_0xebf6('0xf'));var Papa=require('papaparse');var Redis=require(_0xebf6('0x10'));var authService=require(_0xebf6('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xebf6('0x12'));var hardwareService=require(_0xebf6('0x13'));var logger=require(_0xebf6('0x14'))(_0xebf6('0x15'));var utils=require(_0xebf6('0x16'));var config=require(_0xebf6('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0xebf6('0x18'))['db'];function respondWithStatusCode(_0xedc361,_0x4919f1){_0x4919f1=_0x4919f1||0xcc;return function(_0x332ca0){if(_0x332ca0){return _0xedc361[_0xebf6('0x19')](_0x4919f1);}return _0xedc361[_0xebf6('0x1a')](_0x4919f1)[_0xebf6('0x1b')]();};}function respondWithResult(_0x3f69e6,_0x4dbf51){_0x4dbf51=_0x4dbf51||0xc8;return function(_0x4c01f4){if(_0x4c01f4){return _0x3f69e6['status'](_0x4dbf51)[_0xebf6('0x1c')](_0x4c01f4);}};}function respondWithFilteredResult(_0x1ae2f7,_0x50d80f){return function(_0x35570e){if(_0x35570e){var _0x2c980f=typeof _0x50d80f[_0xebf6('0x1d')]===_0xebf6('0x1e')&&typeof _0x50d80f[_0xebf6('0x1f')]===_0xebf6('0x1e');var _0x219621=_0x35570e[_0xebf6('0x20')];var _0x2d3984=_0x2c980f?0x0:_0x50d80f[_0xebf6('0x1d')];var _0x55fa31=_0x2c980f?_0x35570e['count']:_0x50d80f[_0xebf6('0x1d')]+_0x50d80f[_0xebf6('0x1f')];var _0x10051e;if(_0x55fa31>=_0x219621){_0x55fa31=_0x219621;_0x10051e=0xc8;}else{_0x10051e=0xce;}_0x1ae2f7[_0xebf6('0x1a')](_0x10051e);return _0x1ae2f7[_0xebf6('0x21')](_0xebf6('0x22'),_0x2d3984+'-'+_0x55fa31+'/'+_0x219621)[_0xebf6('0x1c')](_0x35570e);}return null;};}function patchUpdates(_0x80f523){return function(_0x4fb497){try{jsonpatch[_0xebf6('0x23')](_0x4fb497,_0x80f523,!![]);}catch(_0x81fdb3){return BPromise[_0xebf6('0x24')](_0x81fdb3);}return _0x4fb497[_0xebf6('0x25')]();};}function saveUpdates(_0x6303ac,_0x14c8ac){return function(_0x2f419e){if(_0x2f419e){return _0x2f419e[_0xebf6('0x26')](_0x6303ac)[_0xebf6('0x27')](function(_0x2e32c6){return _0x2e32c6;});}return null;};}function removeEntity(_0x232074,_0x2dd2ed){return function(_0x43c4e2){if(_0x43c4e2){return _0x43c4e2[_0xebf6('0x28')]()[_0xebf6('0x27')](function(){_0x232074[_0xebf6('0x1a')](0xcc)[_0xebf6('0x1b')]();});}};}function handleEntityNotFound(_0x1534b2,_0x3b58cb){return function(_0x4dadf7){if(!_0x4dadf7){_0x1534b2['sendStatus'](0x194);}return _0x4dadf7;};}function handleError(_0x2605a2,_0x4dc5be){_0x4dc5be=_0x4dc5be||0x1f4;return function(_0x230d84){logger[_0xebf6('0x29')](_0x230d84['stack']);if(_0x230d84['name']){delete _0x230d84[_0xebf6('0x2a')];}_0x2605a2[_0xebf6('0x1a')](_0x4dc5be)[_0xebf6('0x2b')](_0x230d84);};}exports[_0xebf6('0x2c')]=function(_0xedaaeb,_0x2dc0cf){var _0x7976d={'raw':!![],'where':{'id':_0xedaaeb['params']['id']}},_0x7551ce={};_0x7551ce[_0xebf6('0x2d')]=_[_0xebf6('0x2e')](db['ChatApplication'][_0xebf6('0x2f')]);_0x7551ce[_0xebf6('0x30')]=_['keys'](_0xedaaeb[_0xebf6('0x30')]);_0x7551ce[_0xebf6('0x31')]=_[_0xebf6('0x32')](_0x7551ce[_0xebf6('0x2d')],_0x7551ce[_0xebf6('0x30')]);_0x7976d[_0xebf6('0x33')]=_['intersection'](_0x7551ce[_0xebf6('0x2d')],qs[_0xebf6('0x34')](_0xedaaeb['query']['fields']));_0x7976d[_0xebf6('0x33')]=_0x7976d[_0xebf6('0x33')]['length']?_0x7976d[_0xebf6('0x33')]:_0x7551ce[_0xebf6('0x2d')];if(_0xedaaeb['query'][_0xebf6('0x35')]){_0x7976d[_0xebf6('0x36')]=[{'all':!![]}];}_0x7976d=_[_0xebf6('0x37')]({},_0x7976d,_0xedaaeb['options']);return db[_0xebf6('0x38')][_0xebf6('0x39')](_0x7976d)[_0xebf6('0x27')](handleEntityNotFound(_0x2dc0cf,null))[_0xebf6('0x27')](respondWithResult(_0x2dc0cf,null))['catch'](handleError(_0x2dc0cf,null));};exports['update']=function(_0x262af2,_0x46ef2d){if(_0x262af2['body']['id']){delete _0x262af2[_0xebf6('0x3a')]['id'];}return db[_0xebf6('0x38')]['find']({'where':{'id':_0x262af2[_0xebf6('0x3b')]['id']}})[_0xebf6('0x27')](handleEntityNotFound(_0x46ef2d,null))[_0xebf6('0x27')](saveUpdates(_0x262af2[_0xebf6('0x3a')],null))[_0xebf6('0x27')](respondWithResult(_0x46ef2d,null))['catch'](handleError(_0x46ef2d,null));};exports[_0xebf6('0x28')]=function(_0x48943e,_0x3a09fe){return db['ChatApplication'][_0xebf6('0x39')]({'where':{'id':_0x48943e[_0xebf6('0x3b')]['id']}})[_0xebf6('0x27')](handleEntityNotFound(_0x3a09fe,null))[_0xebf6('0x27')](removeEntity(_0x3a09fe,null))[_0xebf6('0x3c')](handleError(_0x3a09fe,null));};