512533466243c4db76c2d8dcad516e4eb6764e47
[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 _0xc99a=['includeAll','include','merge','options','find','catch','body','ChatApplication','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','reject','save','update','then','destroy','error','name','params','query','keys','model','intersection','fields','attributes','length'];(function(_0x25d386,_0x108d0d){var _0x857f4a=function(_0x3eb98d){while(--_0x3eb98d){_0x25d386['push'](_0x25d386['shift']());}};_0x857f4a(++_0x108d0d);}(_0xc99a,0x7c));var _0xac99=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0xc99a[_0x321bb2];return _0x9c12ed;};'use strict';var emlformat=require(_0xac99('0x0'));var rimraf=require(_0xac99('0x1'));var zipdir=require(_0xac99('0x2'));var jsonpatch=require(_0xac99('0x3'));var rp=require(_0xac99('0x4'));var moment=require(_0xac99('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xac99('0x6'));var util=require(_0xac99('0x7'));var path=require(_0xac99('0x8'));var sox=require(_0xac99('0x9'));var csv=require(_0xac99('0xa'));var ejs=require(_0xac99('0xb'));var fs=require('fs');var fs_extra=require(_0xac99('0xc'));var _=require(_0xac99('0xd'));var squel=require(_0xac99('0xe'));var crypto=require(_0xac99('0xf'));var jsforce=require(_0xac99('0x10'));var deskjs=require(_0xac99('0x11'));var toCsv=require('to-csv');var querystring=require(_0xac99('0x12'));var Papa=require(_0xac99('0x13'));var Redis=require('ioredis');var authService=require(_0xac99('0x14'));var qs=require(_0xac99('0x15'));var as=require(_0xac99('0x16'));var hardwareService=require(_0xac99('0x17'));var logger=require('../../config/logger')(_0xac99('0x18'));var utils=require(_0xac99('0x19'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1e0c3f,_0x4e51f4){_0x4e51f4=_0x4e51f4||0xcc;return function(_0x1ae389){if(_0x1ae389){return _0x1e0c3f[_0xac99('0x1a')](_0x4e51f4);}return _0x1e0c3f[_0xac99('0x1b')](_0x4e51f4)[_0xac99('0x1c')]();};}function respondWithResult(_0x2a0d81,_0x454f0a){_0x454f0a=_0x454f0a||0xc8;return function(_0x534eb1){if(_0x534eb1){return _0x2a0d81[_0xac99('0x1b')](_0x454f0a)['json'](_0x534eb1);}};}function respondWithFilteredResult(_0x4e77fd,_0x1ea483){return function(_0xd327f4){if(_0xd327f4){var _0x5cd3fd=typeof _0x1ea483[_0xac99('0x1d')]===_0xac99('0x1e')&&typeof _0x1ea483[_0xac99('0x1f')]==='undefined';var _0x5a94bd=_0xd327f4[_0xac99('0x20')];var _0x2d5a20=_0x5cd3fd?0x0:_0x1ea483[_0xac99('0x1d')];var _0x24b408=_0x5cd3fd?_0xd327f4[_0xac99('0x20')]:_0x1ea483[_0xac99('0x1d')]+_0x1ea483[_0xac99('0x1f')];var _0x47bcd1;if(_0x24b408>=_0x5a94bd){_0x24b408=_0x5a94bd;_0x47bcd1=0xc8;}else{_0x47bcd1=0xce;}_0x4e77fd['status'](_0x47bcd1);return _0x4e77fd[_0xac99('0x21')](_0xac99('0x22'),_0x2d5a20+'-'+_0x24b408+'/'+_0x5a94bd)['json'](_0xd327f4);}return null;};}function patchUpdates(_0x1cb8fc){return function(_0x258eb1){try{jsonpatch['apply'](_0x258eb1,_0x1cb8fc,!![]);}catch(_0x4b862b){return BPromise[_0xac99('0x23')](_0x4b862b);}return _0x258eb1[_0xac99('0x24')]();};}function saveUpdates(_0x38917d,_0x154f4b){return function(_0x2b7e52){if(_0x2b7e52){return _0x2b7e52[_0xac99('0x25')](_0x38917d)[_0xac99('0x26')](function(_0x1a39fd){return _0x1a39fd;});}return null;};}function removeEntity(_0x3330df,_0x50866e){return function(_0x45c3c6){if(_0x45c3c6){return _0x45c3c6[_0xac99('0x27')]()[_0xac99('0x26')](function(){_0x3330df[_0xac99('0x1b')](0xcc)[_0xac99('0x1c')]();});}};}function handleEntityNotFound(_0x2d3b43,_0x53bcb5){return function(_0xb8e570){if(!_0xb8e570){_0x2d3b43[_0xac99('0x1a')](0x194);}return _0xb8e570;};}function handleError(_0x27598c,_0x33b0d9){_0x33b0d9=_0x33b0d9||0x1f4;return function(_0x586fd3){logger[_0xac99('0x28')](_0x586fd3['stack']);if(_0x586fd3[_0xac99('0x29')]){delete _0x586fd3[_0xac99('0x29')];}_0x27598c[_0xac99('0x1b')](_0x33b0d9)['send'](_0x586fd3);};}exports['show']=function(_0x353630,_0x4f2e8b){var _0x519816={'raw':!![],'where':{'id':_0x353630[_0xac99('0x2a')]['id']}},_0xa4b35e={};_0xa4b35e['model']=_['keys'](db['ChatApplication']['rawAttributes']);_0xa4b35e[_0xac99('0x2b')]=_[_0xac99('0x2c')](_0x353630[_0xac99('0x2b')]);_0xa4b35e['filters']=_['intersection'](_0xa4b35e[_0xac99('0x2d')],_0xa4b35e[_0xac99('0x2b')]);_0x519816['attributes']=_[_0xac99('0x2e')](_0xa4b35e[_0xac99('0x2d')],qs[_0xac99('0x2f')](_0x353630[_0xac99('0x2b')][_0xac99('0x2f')]));_0x519816[_0xac99('0x30')]=_0x519816[_0xac99('0x30')][_0xac99('0x31')]?_0x519816['attributes']:_0xa4b35e[_0xac99('0x2d')];if(_0x353630['query'][_0xac99('0x32')]){_0x519816[_0xac99('0x33')]=[{'all':!![]}];}_0x519816=_[_0xac99('0x34')]({},_0x519816,_0x353630[_0xac99('0x35')]);return db['ChatApplication'][_0xac99('0x36')](_0x519816)['then'](handleEntityNotFound(_0x4f2e8b,null))[_0xac99('0x26')](respondWithResult(_0x4f2e8b,null))[_0xac99('0x37')](handleError(_0x4f2e8b,null));};exports[_0xac99('0x25')]=function(_0x52d438,_0x45fdbd){if(_0x52d438[_0xac99('0x38')]['id']){delete _0x52d438[_0xac99('0x38')]['id'];}return db['ChatApplication']['find']({'where':{'id':_0x52d438[_0xac99('0x2a')]['id']}})['then'](handleEntityNotFound(_0x45fdbd,null))[_0xac99('0x26')](saveUpdates(_0x52d438[_0xac99('0x38')],null))[_0xac99('0x26')](respondWithResult(_0x45fdbd,null))[_0xac99('0x37')](handleError(_0x45fdbd,null));};exports[_0xac99('0x27')]=function(_0x469036,_0x3b2829){return db[_0xac99('0x39')]['find']({'where':{'id':_0x469036[_0xac99('0x2a')]['id']}})[_0xac99('0x26')](handleEntityNotFound(_0x3b2829,null))['then'](removeEntity(_0x3b2829,null))['catch'](handleError(_0x3b2829,null));};