Built motion from commit 0415ced0.|2.6.28
[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 _0xc36d=['query','filters','intersection','attributes','model','fields','length','includeAll','include','ChatApplication','find','catch','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../mysqldb','status','end','json','limit','undefined','count','offset','Content-Range','apply','save','update','then','destroy','stack','name','send','show','params','rawAttributes'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xc36d,0x7d));var _0xdc36=function(_0x4e1a49,_0x4da738){_0x4e1a49=_0x4e1a49-0x0;var _0x136aae=_0xc36d[_0x4e1a49];return _0x136aae;};'use strict';var emlformat=require(_0xdc36('0x0'));var rimraf=require(_0xdc36('0x1'));var zipdir=require(_0xdc36('0x2'));var jsonpatch=require(_0xdc36('0x3'));var rp=require(_0xdc36('0x4'));var moment=require(_0xdc36('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xdc36('0x6'));var util=require(_0xdc36('0x7'));var path=require('path');var sox=require(_0xdc36('0x8'));var csv=require(_0xdc36('0x9'));var ejs=require(_0xdc36('0xa'));var fs=require('fs');var fs_extra=require(_0xdc36('0xb'));var _=require(_0xdc36('0xc'));var squel=require('squel');var crypto=require(_0xdc36('0xd'));var jsforce=require(_0xdc36('0xe'));var deskjs=require(_0xdc36('0xf'));var toCsv=require(_0xdc36('0x9'));var querystring=require('querystring');var Papa=require(_0xdc36('0x10'));var Redis=require(_0xdc36('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xdc36('0x12'));var as=require(_0xdc36('0x13'));var hardwareService=require(_0xdc36('0x14'));var logger=require('../../config/logger')(_0xdc36('0x15'));var utils=require(_0xdc36('0x16'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xdc36('0x17'))['db'];function respondWithStatusCode(_0x276692,_0x519fa5){_0x519fa5=_0x519fa5||0xcc;return function(_0x5d62ee){if(_0x5d62ee){return _0x276692['sendStatus'](_0x519fa5);}return _0x276692[_0xdc36('0x18')](_0x519fa5)[_0xdc36('0x19')]();};}function respondWithResult(_0x243d54,_0xae6ad3){_0xae6ad3=_0xae6ad3||0xc8;return function(_0x30803d){if(_0x30803d){return _0x243d54[_0xdc36('0x18')](_0xae6ad3)[_0xdc36('0x1a')](_0x30803d);}};}function respondWithFilteredResult(_0x809cf0,_0x57ebde){return function(_0x155cce){if(_0x155cce){var _0x526ac8=typeof _0x57ebde['offset']==='undefined'&&typeof _0x57ebde[_0xdc36('0x1b')]===_0xdc36('0x1c');var _0x5a498f=_0x155cce[_0xdc36('0x1d')];var _0x219a73=_0x526ac8?0x0:_0x57ebde[_0xdc36('0x1e')];var _0x225878=_0x526ac8?_0x155cce[_0xdc36('0x1d')]:_0x57ebde[_0xdc36('0x1e')]+_0x57ebde['limit'];var _0x3d4c4c;if(_0x225878>=_0x5a498f){_0x225878=_0x5a498f;_0x3d4c4c=0xc8;}else{_0x3d4c4c=0xce;}_0x809cf0[_0xdc36('0x18')](_0x3d4c4c);return _0x809cf0['set'](_0xdc36('0x1f'),_0x219a73+'-'+_0x225878+'/'+_0x5a498f)[_0xdc36('0x1a')](_0x155cce);}return null;};}function patchUpdates(_0x3f25f0){return function(_0x5f15ef){try{jsonpatch[_0xdc36('0x20')](_0x5f15ef,_0x3f25f0,!![]);}catch(_0x235a39){return BPromise['reject'](_0x235a39);}return _0x5f15ef[_0xdc36('0x21')]();};}function saveUpdates(_0x480277,_0x5a6e35){return function(_0x12f9d8){if(_0x12f9d8){return _0x12f9d8[_0xdc36('0x22')](_0x480277)[_0xdc36('0x23')](function(_0xda916b){return _0xda916b;});}return null;};}function removeEntity(_0x2d83c0,_0x34d261){return function(_0x14b595){if(_0x14b595){return _0x14b595[_0xdc36('0x24')]()['then'](function(){_0x2d83c0[_0xdc36('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2338d7,_0x38bd73){return function(_0x15e686){if(!_0x15e686){_0x2338d7['sendStatus'](0x194);}return _0x15e686;};}function handleError(_0xbc4322,_0x6e3906){_0x6e3906=_0x6e3906||0x1f4;return function(_0x337091){logger['error'](_0x337091[_0xdc36('0x25')]);if(_0x337091[_0xdc36('0x26')]){delete _0x337091[_0xdc36('0x26')];}_0xbc4322['status'](_0x6e3906)[_0xdc36('0x27')](_0x337091);};}exports[_0xdc36('0x28')]=function(_0x4b15b4,_0x3fe57f){var _0x12fed2={'raw':!![],'where':{'id':_0x4b15b4[_0xdc36('0x29')]['id']}},_0x4ea2ad={};_0x4ea2ad['model']=_['keys'](db['ChatApplication'][_0xdc36('0x2a')]);_0x4ea2ad[_0xdc36('0x2b')]=_['keys'](_0x4b15b4[_0xdc36('0x2b')]);_0x4ea2ad[_0xdc36('0x2c')]=_[_0xdc36('0x2d')](_0x4ea2ad['model'],_0x4ea2ad[_0xdc36('0x2b')]);_0x12fed2[_0xdc36('0x2e')]=_[_0xdc36('0x2d')](_0x4ea2ad[_0xdc36('0x2f')],qs[_0xdc36('0x30')](_0x4b15b4[_0xdc36('0x2b')][_0xdc36('0x30')]));_0x12fed2['attributes']=_0x12fed2[_0xdc36('0x2e')][_0xdc36('0x31')]?_0x12fed2['attributes']:_0x4ea2ad['model'];if(_0x4b15b4[_0xdc36('0x2b')][_0xdc36('0x32')]){_0x12fed2[_0xdc36('0x33')]=[{'all':!![]}];}_0x12fed2=_['merge']({},_0x12fed2,_0x4b15b4['options']);return db[_0xdc36('0x34')][_0xdc36('0x35')](_0x12fed2)[_0xdc36('0x23')](handleEntityNotFound(_0x3fe57f,null))[_0xdc36('0x23')](respondWithResult(_0x3fe57f,null))[_0xdc36('0x36')](handleError(_0x3fe57f,null));};exports[_0xdc36('0x22')]=function(_0xf80dc3,_0x16303c){if(_0xf80dc3[_0xdc36('0x37')]['id']){delete _0xf80dc3[_0xdc36('0x37')]['id'];}return db[_0xdc36('0x34')]['find']({'where':{'id':_0xf80dc3[_0xdc36('0x29')]['id']}})[_0xdc36('0x23')](handleEntityNotFound(_0x16303c,null))[_0xdc36('0x23')](saveUpdates(_0xf80dc3[_0xdc36('0x37')],null))['then'](respondWithResult(_0x16303c,null))[_0xdc36('0x36')](handleError(_0x16303c,null));};exports[_0xdc36('0x24')]=function(_0x27e86c,_0x476eb3){return db['ChatApplication'][_0xdc36('0x35')]({'where':{'id':_0x27e86c['params']['id']}})['then'](handleEntityNotFound(_0x476eb3,null))[_0xdc36('0x23')](removeEntity(_0x476eb3,null))[_0xdc36('0x36')](handleError(_0x476eb3,null));};