1568e1281dd25f5deb862f7ca6aebe79d95982ea
[motion2.git] / server / api / chatOfflineMessage / chatOfflineMessage.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 _0x61f3=['include','find','create','body','params','Attachment','forEach','join','root','files','offline-chat','basename','remove','describe','rimraf','request-promise','moment','bluebird','mustache','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','limit','count','offset','Content-Range','reject','save','then','destroy','error','name','send','map','ChatOfflineMessage','rawAttributes','type','model','query','intersection','attributes','fields','hasOwnProperty','order','sort','where','filters','pick','filter','merge','VIRTUAL','options','findAll','rows','catch','show','keys','includeAll'];(function(_0xe3e0af,_0x4564ed){var _0x4828e9=function(_0x55c7a7){while(--_0x55c7a7){_0xe3e0af['push'](_0xe3e0af['shift']());}};_0x4828e9(++_0x4564ed);}(_0x61f3,0xac));var _0x361f=function(_0x3366c0,_0x239a3f){_0x3366c0=_0x3366c0-0x0;var _0xa7eaff=_0x61f3[_0x3366c0];return _0xa7eaff;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x361f('0x0'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x361f('0x1'));var moment=require(_0x361f('0x2'));var BPromise=require(_0x361f('0x3'));var Mustache=require(_0x361f('0x4'));var util=require('util');var path=require(_0x361f('0x5'));var sox=require('sox');var csv=require(_0x361f('0x6'));var ejs=require(_0x361f('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x361f('0x8'));var squel=require(_0x361f('0x9'));var crypto=require(_0x361f('0xa'));var jsforce=require(_0x361f('0xb'));var deskjs=require(_0x361f('0xc'));var toCsv=require(_0x361f('0x6'));var querystring=require(_0x361f('0xd'));var Papa=require(_0x361f('0xe'));var Redis=require(_0x361f('0xf'));var authService=require(_0x361f('0x10'));var qs=require(_0x361f('0x11'));var as=require(_0x361f('0x12'));var hardwareService=require(_0x361f('0x13'));var logger=require('../../config/logger')('api');var utils=require(_0x361f('0x14'));var config=require(_0x361f('0x15'));var licenseUtil=require(_0x361f('0x16'));var db=require(_0x361f('0x17'))['db'];function respondWithStatusCode(_0x5dced8,_0x5280f4){_0x5280f4=_0x5280f4||0xcc;return function(_0x90e690){if(_0x90e690){return _0x5dced8[_0x361f('0x18')](_0x5280f4);}return _0x5dced8[_0x361f('0x19')](_0x5280f4)[_0x361f('0x1a')]();};}function respondWithResult(_0x5b804c,_0x43db98){_0x43db98=_0x43db98||0xc8;return function(_0x210d09){if(_0x210d09){return _0x5b804c['status'](_0x43db98)[_0x361f('0x1b')](_0x210d09);}};}function respondWithFilteredResult(_0x5efb59,_0xd38376){return function(_0x26f07d){if(_0x26f07d){var _0x5f1d11=typeof _0xd38376['offset']===_0x361f('0x1c')&&typeof _0xd38376[_0x361f('0x1d')]===_0x361f('0x1c');var _0x25bbf6=_0x26f07d[_0x361f('0x1e')];var _0x4a5221=_0x5f1d11?0x0:_0xd38376['offset'];var _0x39cc69=_0x5f1d11?_0x26f07d[_0x361f('0x1e')]:_0xd38376[_0x361f('0x1f')]+_0xd38376[_0x361f('0x1d')];var _0x4666e8;if(_0x39cc69>=_0x25bbf6){_0x39cc69=_0x25bbf6;_0x4666e8=0xc8;}else{_0x4666e8=0xce;}_0x5efb59[_0x361f('0x19')](_0x4666e8);return _0x5efb59['set'](_0x361f('0x20'),_0x4a5221+'-'+_0x39cc69+'/'+_0x25bbf6)['json'](_0x26f07d);}return null;};}function patchUpdates(_0x2ff4b3){return function(_0xf60b67){try{jsonpatch['apply'](_0xf60b67,_0x2ff4b3,!![]);}catch(_0x6d7bcd){return BPromise[_0x361f('0x21')](_0x6d7bcd);}return _0xf60b67[_0x361f('0x22')]();};}function saveUpdates(_0x30cb9d,_0x29e1fa){return function(_0x46ddf9){if(_0x46ddf9){return _0x46ddf9['update'](_0x30cb9d)[_0x361f('0x23')](function(_0x4e25ed){return _0x4e25ed;});}return null;};}function removeEntity(_0x5cf0fa,_0x4ebe5d){return function(_0x583c0f){if(_0x583c0f){return _0x583c0f[_0x361f('0x24')]()['then'](function(){_0x5cf0fa[_0x361f('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x269368,_0x583cb6){return function(_0x286c07){if(!_0x286c07){_0x269368[_0x361f('0x18')](0x194);}return _0x286c07;};}function handleError(_0xff1895,_0x5a2262){_0x5a2262=_0x5a2262||0x1f4;return function(_0x3a9f55){logger[_0x361f('0x25')](_0x3a9f55['stack']);if(_0x3a9f55[_0x361f('0x26')]){delete _0x3a9f55[_0x361f('0x26')];}_0xff1895[_0x361f('0x19')](_0x5a2262)[_0x361f('0x27')](_0x3a9f55);};}exports['index']=function(_0x572f40,_0x470f60){var _0x46ca0c={},_0x2e75f8={},_0x15a82a={'count':0x0,'rows':[]};var _0x193472=_[_0x361f('0x28')](db[_0x361f('0x29')][_0x361f('0x2a')],function(_0x52fe7d){return{'name':_0x52fe7d['fieldName'],'type':_0x52fe7d[_0x361f('0x2b')]['key']};});_0x2e75f8[_0x361f('0x2c')]=_['map'](_0x193472,_0x361f('0x26'));_0x2e75f8[_0x361f('0x2d')]=_['keys'](_0x572f40[_0x361f('0x2d')]);_0x2e75f8['filters']=_[_0x361f('0x2e')](_0x2e75f8[_0x361f('0x2c')],_0x2e75f8[_0x361f('0x2d')]);_0x46ca0c[_0x361f('0x2f')]=_['intersection'](_0x2e75f8[_0x361f('0x2c')],qs[_0x361f('0x30')](_0x572f40['query'][_0x361f('0x30')]));_0x46ca0c['attributes']=_0x46ca0c[_0x361f('0x2f')]['length']?_0x46ca0c['attributes']:_0x2e75f8[_0x361f('0x2c')];if(!_0x572f40['query'][_0x361f('0x31')]('nolimit')){_0x46ca0c[_0x361f('0x1d')]=qs[_0x361f('0x1d')](_0x572f40[_0x361f('0x2d')][_0x361f('0x1d')]);_0x46ca0c[_0x361f('0x1f')]=qs[_0x361f('0x1f')](_0x572f40['query'][_0x361f('0x1f')]);}_0x46ca0c[_0x361f('0x32')]=qs['sort'](_0x572f40['query'][_0x361f('0x33')]);_0x46ca0c[_0x361f('0x34')]=qs[_0x361f('0x35')](_[_0x361f('0x36')](_0x572f40['query'],_0x2e75f8['filters']),_0x193472);if(_0x572f40['query'][_0x361f('0x37')]){_0x46ca0c[_0x361f('0x34')]=_[_0x361f('0x38')](_0x46ca0c[_0x361f('0x34')],{'$or':_[_0x361f('0x28')](_0x193472,function(_0x54c022){if(_0x54c022[_0x361f('0x2b')]!==_0x361f('0x39')){var _0xec5d12={};_0xec5d12[_0x54c022[_0x361f('0x26')]]={'$like':'%'+_0x572f40[_0x361f('0x2d')][_0x361f('0x37')]+'%'};return _0xec5d12;}})});}_0x46ca0c=_[_0x361f('0x38')]({},_0x46ca0c,_0x572f40[_0x361f('0x3a')]);var _0x564ed8={'where':_0x46ca0c['where']};return db[_0x361f('0x29')][_0x361f('0x1e')](_0x564ed8)[_0x361f('0x23')](function(_0x9726fa){_0x15a82a[_0x361f('0x1e')]=_0x9726fa;if(_0x572f40['query']['includeAll']){_0x46ca0c['include']=[{'all':!![]}];}return db[_0x361f('0x29')][_0x361f('0x3b')](_0x46ca0c);})[_0x361f('0x23')](function(_0x4796ad){_0x15a82a[_0x361f('0x3c')]=_0x4796ad;return _0x15a82a;})[_0x361f('0x23')](respondWithFilteredResult(_0x470f60,_0x46ca0c))[_0x361f('0x3d')](handleError(_0x470f60,null));};exports[_0x361f('0x3e')]=function(_0x2167be,_0x546823){var _0x14529c={'raw':!![],'where':{'id':_0x2167be['params']['id']}},_0x28680d={};_0x28680d[_0x361f('0x2c')]=_[_0x361f('0x3f')](db['ChatOfflineMessage'][_0x361f('0x2a')]);_0x28680d[_0x361f('0x2d')]=_[_0x361f('0x3f')](_0x2167be[_0x361f('0x2d')]);_0x28680d[_0x361f('0x35')]=_[_0x361f('0x2e')](_0x28680d[_0x361f('0x2c')],_0x28680d[_0x361f('0x2d')]);_0x14529c[_0x361f('0x2f')]=_['intersection'](_0x28680d[_0x361f('0x2c')],qs['fields'](_0x2167be['query'][_0x361f('0x30')]));_0x14529c[_0x361f('0x2f')]=_0x14529c[_0x361f('0x2f')]['length']?_0x14529c[_0x361f('0x2f')]:_0x28680d[_0x361f('0x2c')];if(_0x2167be['query'][_0x361f('0x40')]){_0x14529c[_0x361f('0x41')]=[{'all':!![]}];}_0x14529c=_[_0x361f('0x38')]({},_0x14529c,_0x2167be[_0x361f('0x3a')]);return db['ChatOfflineMessage'][_0x361f('0x42')](_0x14529c)[_0x361f('0x23')](handleEntityNotFound(_0x546823,null))['then'](respondWithResult(_0x546823,null))[_0x361f('0x3d')](handleError(_0x546823,null));};exports[_0x361f('0x43')]=function(_0x51ab41,_0xf87fb1){return db[_0x361f('0x29')]['create'](_0x51ab41[_0x361f('0x44')],{})[_0x361f('0x23')](respondWithResult(_0xf87fb1,0xc9))[_0x361f('0x3d')](handleError(_0xf87fb1,null));};exports['update']=function(_0x379696,_0x49c485){if(_0x379696[_0x361f('0x44')]['id']){delete _0x379696['body']['id'];}return db['ChatOfflineMessage'][_0x361f('0x42')]({'where':{'id':_0x379696[_0x361f('0x45')]['id']}})[_0x361f('0x23')](handleEntityNotFound(_0x49c485,null))['then'](saveUpdates(_0x379696[_0x361f('0x44')],null))[_0x361f('0x23')](respondWithResult(_0x49c485,null))[_0x361f('0x3d')](handleError(_0x49c485,null));};exports[_0x361f('0x24')]=function(_0x3c4361,_0x43696b){return db[_0x361f('0x46')]['findAll']({'where':{'ChatOfflineMessageId':_0x3c4361['params']['id']},'raw':!![]})['then'](function(_0x1efad3){_0x1efad3[_0x361f('0x47')](function(_0x246f8){var _0x2e4298=path[_0x361f('0x48')](config[_0x361f('0x49')],'server',_0x361f('0x4a'),'attachments',_0x361f('0x4b'),_0x246f8[_0x361f('0x4c')]);var _0x499e59=fs['existsSync'](_0x2e4298);if(_0x499e59)fs_extra[_0x361f('0x4d')](_0x2e4298);});})[_0x361f('0x23')](function(){return db[_0x361f('0x29')][_0x361f('0x42')]({'where':{'id':_0x3c4361[_0x361f('0x45')]['id']},'individualHooks':!![]});})[_0x361f('0x23')](handleEntityNotFound(_0x43696b,null))['then'](removeEntity(_0x43696b,null))[_0x361f('0x3d')](handleError(_0x43696b,null));};exports[_0x361f('0x4e')]=function(_0x40ca85,_0x308b63){return db[_0x361f('0x29')][_0x361f('0x4e')]()[_0x361f('0x23')](respondWithResult(_0x308b63,null))[_0x361f('0x3d')](handleError(_0x308b63,null));};