Built motion from commit bbec7235.|2.6.20
[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 _0xc7ea=['request-promise','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','limit','undefined','count','set','Content-Range','apply','save','update','then','destroy','name','send','show','params','model','ChatApplication','rawAttributes','query','filters','intersection','attributes','fields','includeAll','include','merge','options','find','catch','body','eml-format','rimraf','fast-json-patch'];(function(_0x55e5cb,_0x3d0213){var _0x4a8ea1=function(_0xab0a29){while(--_0xab0a29){_0x55e5cb['push'](_0x55e5cb['shift']());}};_0x4a8ea1(++_0x3d0213);}(_0xc7ea,0x171));var _0xac7e=function(_0x562cc9,_0x1cb01e){_0x562cc9=_0x562cc9-0x0;var _0x5ddbf8=_0xc7ea[_0x562cc9];return _0x5ddbf8;};'use strict';var emlformat=require(_0xac7e('0x0'));var rimraf=require(_0xac7e('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xac7e('0x2'));var rp=require(_0xac7e('0x3'));var moment=require(_0xac7e('0x4'));var BPromise=require(_0xac7e('0x5'));var Mustache=require('mustache');var util=require(_0xac7e('0x6'));var path=require(_0xac7e('0x7'));var sox=require(_0xac7e('0x8'));var csv=require(_0xac7e('0x9'));var ejs=require(_0xac7e('0xa'));var fs=require('fs');var fs_extra=require(_0xac7e('0xb'));var _=require(_0xac7e('0xc'));var squel=require(_0xac7e('0xd'));var crypto=require(_0xac7e('0xe'));var jsforce=require(_0xac7e('0xf'));var deskjs=require('desk.js');var toCsv=require(_0xac7e('0x9'));var querystring=require(_0xac7e('0x10'));var Papa=require(_0xac7e('0x11'));var Redis=require(_0xac7e('0x12'));var authService=require(_0xac7e('0x13'));var qs=require(_0xac7e('0x14'));var as=require(_0xac7e('0x15'));var hardwareService=require(_0xac7e('0x16'));var logger=require(_0xac7e('0x17'))(_0xac7e('0x18'));var utils=require(_0xac7e('0x19'));var config=require(_0xac7e('0x1a'));var licenseUtil=require('../../config/license/util');var db=require(_0xac7e('0x1b'))['db'];function respondWithStatusCode(_0x13e126,_0x5d4537){_0x5d4537=_0x5d4537||0xcc;return function(_0x617cf9){if(_0x617cf9){return _0x13e126[_0xac7e('0x1c')](_0x5d4537);}return _0x13e126[_0xac7e('0x1d')](_0x5d4537)[_0xac7e('0x1e')]();};}function respondWithResult(_0x31a8e7,_0x52be09){_0x52be09=_0x52be09||0xc8;return function(_0x3486ac){if(_0x3486ac){return _0x31a8e7[_0xac7e('0x1d')](_0x52be09)[_0xac7e('0x1f')](_0x3486ac);}};}function respondWithFilteredResult(_0x41c055,_0x333436){return function(_0x232ce5){if(_0x232ce5){var _0x7ee114=typeof _0x333436[_0xac7e('0x20')]==='undefined'&&typeof _0x333436[_0xac7e('0x21')]===_0xac7e('0x22');var _0x95f21c=_0x232ce5[_0xac7e('0x23')];var _0x242889=_0x7ee114?0x0:_0x333436['offset'];var _0x2be7d7=_0x7ee114?_0x232ce5['count']:_0x333436[_0xac7e('0x20')]+_0x333436['limit'];var _0xa048e9;if(_0x2be7d7>=_0x95f21c){_0x2be7d7=_0x95f21c;_0xa048e9=0xc8;}else{_0xa048e9=0xce;}_0x41c055[_0xac7e('0x1d')](_0xa048e9);return _0x41c055[_0xac7e('0x24')](_0xac7e('0x25'),_0x242889+'-'+_0x2be7d7+'/'+_0x95f21c)[_0xac7e('0x1f')](_0x232ce5);}return null;};}function patchUpdates(_0x2ad784){return function(_0x4d23f9){try{jsonpatch[_0xac7e('0x26')](_0x4d23f9,_0x2ad784,!![]);}catch(_0x3c177d){return BPromise['reject'](_0x3c177d);}return _0x4d23f9[_0xac7e('0x27')]();};}function saveUpdates(_0x2ebc78,_0x2c3b6e){return function(_0x3ce3cc){if(_0x3ce3cc){return _0x3ce3cc[_0xac7e('0x28')](_0x2ebc78)[_0xac7e('0x29')](function(_0x45f7b6){return _0x45f7b6;});}return null;};}function removeEntity(_0x57abe8,_0x2b5f43){return function(_0x32ef52){if(_0x32ef52){return _0x32ef52[_0xac7e('0x2a')]()['then'](function(){_0x57abe8['status'](0xcc)[_0xac7e('0x1e')]();});}};}function handleEntityNotFound(_0x1ae3b4,_0x4620da){return function(_0x50b1e5){if(!_0x50b1e5){_0x1ae3b4[_0xac7e('0x1c')](0x194);}return _0x50b1e5;};}function handleError(_0x1de558,_0x2cafcb){_0x2cafcb=_0x2cafcb||0x1f4;return function(_0x3e0f1a){logger['error'](_0x3e0f1a['stack']);if(_0x3e0f1a[_0xac7e('0x2b')]){delete _0x3e0f1a['name'];}_0x1de558['status'](_0x2cafcb)[_0xac7e('0x2c')](_0x3e0f1a);};}exports[_0xac7e('0x2d')]=function(_0x3ecfc1,_0x4864d1){var _0x224259={'raw':!![],'where':{'id':_0x3ecfc1[_0xac7e('0x2e')]['id']}},_0x376247={};_0x376247[_0xac7e('0x2f')]=_['keys'](db[_0xac7e('0x30')][_0xac7e('0x31')]);_0x376247[_0xac7e('0x32')]=_['keys'](_0x3ecfc1[_0xac7e('0x32')]);_0x376247[_0xac7e('0x33')]=_[_0xac7e('0x34')](_0x376247[_0xac7e('0x2f')],_0x376247['query']);_0x224259[_0xac7e('0x35')]=_['intersection'](_0x376247[_0xac7e('0x2f')],qs[_0xac7e('0x36')](_0x3ecfc1[_0xac7e('0x32')]['fields']));_0x224259[_0xac7e('0x35')]=_0x224259[_0xac7e('0x35')]['length']?_0x224259['attributes']:_0x376247[_0xac7e('0x2f')];if(_0x3ecfc1[_0xac7e('0x32')][_0xac7e('0x37')]){_0x224259[_0xac7e('0x38')]=[{'all':!![]}];}_0x224259=_[_0xac7e('0x39')]({},_0x224259,_0x3ecfc1[_0xac7e('0x3a')]);return db[_0xac7e('0x30')][_0xac7e('0x3b')](_0x224259)[_0xac7e('0x29')](handleEntityNotFound(_0x4864d1,null))['then'](respondWithResult(_0x4864d1,null))[_0xac7e('0x3c')](handleError(_0x4864d1,null));};exports[_0xac7e('0x28')]=function(_0x1e3cc4,_0x38d61e){if(_0x1e3cc4[_0xac7e('0x3d')]['id']){delete _0x1e3cc4[_0xac7e('0x3d')]['id'];}return db['ChatApplication']['find']({'where':{'id':_0x1e3cc4[_0xac7e('0x2e')]['id']}})[_0xac7e('0x29')](handleEntityNotFound(_0x38d61e,null))[_0xac7e('0x29')](saveUpdates(_0x1e3cc4[_0xac7e('0x3d')],null))[_0xac7e('0x29')](respondWithResult(_0x38d61e,null))[_0xac7e('0x3c')](handleError(_0x38d61e,null));};exports[_0xac7e('0x2a')]=function(_0x2160cd,_0xacc6b9){return db['ChatApplication'][_0xac7e('0x3b')]({'where':{'id':_0x2160cd[_0xac7e('0x2e')]['id']}})['then'](handleEntityNotFound(_0xacc6b9,null))[_0xac7e('0x29')](removeEntity(_0xacc6b9,null))[_0xac7e('0x3c')](handleError(_0xacc6b9,null));};