Built motion from commit (unavailable).|2.5.17
[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 _0xb30e=['filters','attributes','intersection','fields','include','merge','options','find','catch','body','eml-format','rimraf','zip-dir','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','crypto','jsforce','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/environment','../../mysqldb','status','end','offset','limit','set','Content-Range','json','reject','save','update','then','sendStatus','error','name','send','show','params','model','keys','ChatApplication','rawAttributes','query'];(function(_0x2fc8a7,_0x227128){var _0x14b454=function(_0xa2a066){while(--_0xa2a066){_0x2fc8a7['push'](_0x2fc8a7['shift']());}};_0x14b454(++_0x227128);}(_0xb30e,0x17d));var _0xeb30=function(_0x39eaa0,_0x2cea62){_0x39eaa0=_0x39eaa0-0x0;var _0x2402c5=_0xb30e[_0x39eaa0];return _0x2402c5;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xeb30('0x0'));var rimraf=require(_0xeb30('0x1'));var zipdir=require(_0xeb30('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xeb30('0x3'));var moment=require('moment');var BPromise=require(_0xeb30('0x4'));var Mustache=require(_0xeb30('0x5'));var util=require(_0xeb30('0x6'));var path=require(_0xeb30('0x7'));var sox=require(_0xeb30('0x8'));var csv=require(_0xeb30('0x9'));var ejs=require(_0xeb30('0xa'));var fs=require('fs');var _=require(_0xeb30('0xb'));var squel=require('squel');var crypto=require(_0xeb30('0xc'));var jsforce=require(_0xeb30('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xeb30('0xe'));var Papa=require(_0xeb30('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xeb30('0x10'));var as=require(_0xeb30('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xeb30('0x12'));var utils=require('../../config/utils');var config=require(_0xeb30('0x13'));var licenseUtil=require('../../config/license/util');var db=require(_0xeb30('0x14'))['db'];function respondWithStatusCode(_0x36f9a0,_0x10bfdb){_0x10bfdb=_0x10bfdb||0xcc;return function(_0x156b92){if(_0x156b92){return _0x36f9a0['sendStatus'](_0x10bfdb);}return _0x36f9a0[_0xeb30('0x15')](_0x10bfdb)[_0xeb30('0x16')]();};}function respondWithResult(_0x20326e,_0x4ac690){_0x4ac690=_0x4ac690||0xc8;return function(_0x185265){if(_0x185265){return _0x20326e[_0xeb30('0x15')](_0x4ac690)['json'](_0x185265);}};}function respondWithFilteredResult(_0x24a683,_0x1f95f4){return function(_0x511a9c){if(_0x511a9c){var _0x271cbf=_0x511a9c['count'],_0x2e48a9=_0x1f95f4[_0xeb30('0x17')],_0x272643=_0x1f95f4[_0xeb30('0x17')]+_0x1f95f4[_0xeb30('0x18')],_0x2ea0ad;if(_0x272643>=_0x271cbf){_0x272643=_0x271cbf;_0x2ea0ad=0xc8;}else{_0x2ea0ad=0xce;}_0x24a683['status'](_0x2ea0ad);return _0x24a683[_0xeb30('0x19')](_0xeb30('0x1a'),_0x2e48a9+'-'+_0x272643+'/'+_0x271cbf)[_0xeb30('0x1b')](_0x511a9c);}return null;};}function patchUpdates(_0xbe4b89){return function(_0x480517){try{jsonpatch['apply'](_0x480517,_0xbe4b89,!![]);}catch(_0x533ff5){return BPromise[_0xeb30('0x1c')](_0x533ff5);}return _0x480517[_0xeb30('0x1d')]();};}function saveUpdates(_0xdb3695,_0x4b66b1){return function(_0x3e42b4){if(_0x3e42b4){return _0x3e42b4[_0xeb30('0x1e')](_0xdb3695)['then'](function(_0x5b5cca){return _0x5b5cca;});}return null;};}function removeEntity(_0x1f8f6a,_0x4c85f1){return function(_0x3b0439){if(_0x3b0439){return _0x3b0439['destroy']()[_0xeb30('0x1f')](function(){_0x1f8f6a['status'](0xcc)[_0xeb30('0x16')]();});}};}function handleEntityNotFound(_0x1f81a5,_0x47cb7f){return function(_0x183c94){if(!_0x183c94){_0x1f81a5[_0xeb30('0x20')](0x194);}return _0x183c94;};}function handleError(_0x48a7d5,_0x843d7){_0x843d7=_0x843d7||0x1f4;return function(_0x4a23b7){logger[_0xeb30('0x21')](_0x4a23b7['stack']);if(_0x4a23b7[_0xeb30('0x22')]){delete _0x4a23b7[_0xeb30('0x22')];}_0x48a7d5[_0xeb30('0x15')](_0x843d7)[_0xeb30('0x23')](_0x4a23b7);};}exports[_0xeb30('0x24')]=function(_0x29938e,_0x8e1206){var _0xa6ec76={'raw':!![],'where':{'id':_0x29938e[_0xeb30('0x25')]['id']}},_0x5e40ca={};_0x5e40ca[_0xeb30('0x26')]=_[_0xeb30('0x27')](db[_0xeb30('0x28')][_0xeb30('0x29')]);_0x5e40ca[_0xeb30('0x2a')]=_[_0xeb30('0x27')](_0x29938e[_0xeb30('0x2a')]);_0x5e40ca[_0xeb30('0x2b')]=_['intersection'](_0x5e40ca[_0xeb30('0x26')],_0x5e40ca[_0xeb30('0x2a')]);_0xa6ec76[_0xeb30('0x2c')]=_[_0xeb30('0x2d')](_0x5e40ca['model'],qs[_0xeb30('0x2e')](_0x29938e[_0xeb30('0x2a')][_0xeb30('0x2e')]));_0xa6ec76[_0xeb30('0x2c')]=_0xa6ec76[_0xeb30('0x2c')]['length']?_0xa6ec76[_0xeb30('0x2c')]:_0x5e40ca['model'];if(_0x29938e[_0xeb30('0x2a')]['includeAll']){_0xa6ec76[_0xeb30('0x2f')]=[{'all':!![]}];}_0xa6ec76=_[_0xeb30('0x30')]({},_0xa6ec76,_0x29938e[_0xeb30('0x31')]);return db['ChatApplication'][_0xeb30('0x32')](_0xa6ec76)['then'](handleEntityNotFound(_0x8e1206,null))[_0xeb30('0x1f')](respondWithResult(_0x8e1206,null))[_0xeb30('0x33')](handleError(_0x8e1206,null));};exports['update']=function(_0x5272eb,_0x2f14d4){if(_0x5272eb[_0xeb30('0x34')]['id']){delete _0x5272eb[_0xeb30('0x34')]['id'];}return db[_0xeb30('0x28')][_0xeb30('0x32')]({'where':{'id':_0x5272eb[_0xeb30('0x25')]['id']}})[_0xeb30('0x1f')](handleEntityNotFound(_0x2f14d4,null))[_0xeb30('0x1f')](saveUpdates(_0x5272eb[_0xeb30('0x34')],null))[_0xeb30('0x1f')](respondWithResult(_0x2f14d4,null))[_0xeb30('0x33')](handleError(_0x2f14d4,null));};exports['destroy']=function(_0x431d9b,_0x4b2307){return db[_0xeb30('0x28')][_0xeb30('0x32')]({'where':{'id':_0x431d9b[_0xeb30('0x25')]['id']}})[_0xeb30('0x1f')](handleEntityNotFound(_0x4b2307,null))['then'](removeEntity(_0x4b2307,null))['catch'](handleError(_0x4b2307,null));};