Built motion from commit (unavailable).|2.5.5
[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 _0x222f=['set','Content-Range','json','apply','reject','update','then','destroy','error','stack','name','send','index','map','ChatOfflineMessage','rawAttributes','fieldName','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','filter','type','merge','options','count','include','findAll','rows','show','params','keys','find','catch','create','body','describe','html-pdf','eml-format','rimraf','zip-dir','moment','bluebird','mustache','util','sox','ejs','lodash','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','limit'];(function(_0x4aab3e,_0x532b62){var _0x24b94e=function(_0x5102d1){while(--_0x5102d1){_0x4aab3e['push'](_0x4aab3e['shift']());}};_0x24b94e(++_0x532b62);}(_0x222f,0x1a4));var _0xf222=function(_0x9b14ee,_0x574340){_0x9b14ee=_0x9b14ee-0x0;var _0xc3fa3c=_0x222f[_0x9b14ee];return _0xc3fa3c;};'use strict';var pdf=require(_0xf222('0x0'));var emlformat=require(_0xf222('0x1'));var rimraf=require(_0xf222('0x2'));var zipdir=require(_0xf222('0x3'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xf222('0x4'));var BPromise=require(_0xf222('0x5'));var Mustache=require(_0xf222('0x6'));var util=require(_0xf222('0x7'));var path=require('path');var sox=require(_0xf222('0x8'));var csv=require('to-csv');var ejs=require(_0xf222('0x9'));var fs=require('fs');var _=require(_0xf222('0xa'));var squel=require('squel');var crypto=require(_0xf222('0xb'));var jsforce=require(_0xf222('0xc'));var deskjs=require('desk.js');var toCsv=require(_0xf222('0xd'));var querystring=require(_0xf222('0xe'));var Papa=require(_0xf222('0xf'));var Redis=require(_0xf222('0x10'));var authService=require(_0xf222('0x11'));var qs=require(_0xf222('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf222('0x13'));var logger=require(_0xf222('0x14'))(_0xf222('0x15'));var utils=require(_0xf222('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0xf222('0x17'));var db=require(_0xf222('0x18'))['db'];function respondWithStatusCode(_0x2a6965,_0x3d3d29){_0x3d3d29=_0x3d3d29||0xcc;return function(_0x12f968){if(_0x12f968){return _0x2a6965[_0xf222('0x19')](_0x3d3d29);}return _0x2a6965[_0xf222('0x1a')](_0x3d3d29)[_0xf222('0x1b')]();};}function respondWithResult(_0x52a003,_0x5b8f97){_0x5b8f97=_0x5b8f97||0xc8;return function(_0x1feb86){if(_0x1feb86){return _0x52a003[_0xf222('0x1a')](_0x5b8f97)['json'](_0x1feb86);}};}function respondWithFilteredResult(_0x39be58,_0x43d35b){return function(_0x464f3e){if(_0x464f3e){var _0x4392a0=_0x464f3e['count'],_0x464060=_0x43d35b[_0xf222('0x1c')],_0x25e1c2=_0x43d35b[_0xf222('0x1c')]+_0x43d35b[_0xf222('0x1d')],_0x30b646;if(_0x25e1c2>=_0x4392a0){_0x25e1c2=_0x4392a0;_0x30b646=0xc8;}else{_0x30b646=0xce;}_0x39be58[_0xf222('0x1a')](_0x30b646);return _0x39be58[_0xf222('0x1e')](_0xf222('0x1f'),_0x464060+'-'+_0x25e1c2+'/'+_0x4392a0)[_0xf222('0x20')](_0x464f3e);}return null;};}function patchUpdates(_0x4b2847){return function(_0xf26a16){try{jsonpatch[_0xf222('0x21')](_0xf26a16,_0x4b2847,!![]);}catch(_0x2b0d92){return BPromise[_0xf222('0x22')](_0x2b0d92);}return _0xf26a16['save']();};}function saveUpdates(_0x5cd899,_0x398ff4){return function(_0x3e8875){if(_0x3e8875){return _0x3e8875[_0xf222('0x23')](_0x5cd899)[_0xf222('0x24')](function(_0x35539d){return _0x35539d;});}return null;};}function removeEntity(_0x151a89,_0x51b872){return function(_0x176b20){if(_0x176b20){return _0x176b20[_0xf222('0x25')]()[_0xf222('0x24')](function(){_0x151a89[_0xf222('0x1a')](0xcc)[_0xf222('0x1b')]();});}};}function handleEntityNotFound(_0x2d18ab,_0x4616de){return function(_0x144775){if(!_0x144775){_0x2d18ab['sendStatus'](0x194);}return _0x144775;};}function handleError(_0x145e2e,_0x5151d9){_0x5151d9=_0x5151d9||0x1f4;return function(_0x1883c1){logger[_0xf222('0x26')](_0x1883c1[_0xf222('0x27')]);if(_0x1883c1[_0xf222('0x28')]){delete _0x1883c1[_0xf222('0x28')];}_0x145e2e[_0xf222('0x1a')](_0x5151d9)[_0xf222('0x29')](_0x1883c1);};}exports[_0xf222('0x2a')]=function(_0x2a8310,_0x501f8e){var _0x14b2b1={},_0x1c5cd3={},_0x3d5508={'count':0x0,'rows':[]};var _0x2f04bf=_[_0xf222('0x2b')](db[_0xf222('0x2c')][_0xf222('0x2d')],function(_0x1b928b){return{'name':_0x1b928b[_0xf222('0x2e')],'type':_0x1b928b['type'][_0xf222('0x2f')]};});_0x1c5cd3[_0xf222('0x30')]=_[_0xf222('0x2b')](_0x2f04bf,'name');_0x1c5cd3[_0xf222('0x31')]=_['keys'](_0x2a8310[_0xf222('0x31')]);_0x1c5cd3[_0xf222('0x32')]=_[_0xf222('0x33')](_0x1c5cd3[_0xf222('0x30')],_0x1c5cd3[_0xf222('0x31')]);_0x14b2b1[_0xf222('0x34')]=_[_0xf222('0x33')](_0x1c5cd3['model'],qs['fields'](_0x2a8310[_0xf222('0x31')][_0xf222('0x35')]));_0x14b2b1[_0xf222('0x34')]=_0x14b2b1[_0xf222('0x34')][_0xf222('0x36')]?_0x14b2b1[_0xf222('0x34')]:_0x1c5cd3['model'];if(!_0x2a8310[_0xf222('0x31')][_0xf222('0x37')](_0xf222('0x38'))){_0x14b2b1['limit']=qs[_0xf222('0x1d')](_0x2a8310[_0xf222('0x31')][_0xf222('0x1d')]);_0x14b2b1['offset']=qs[_0xf222('0x1c')](_0x2a8310[_0xf222('0x31')][_0xf222('0x1c')]);}_0x14b2b1['order']=qs[_0xf222('0x39')](_0x2a8310[_0xf222('0x31')][_0xf222('0x39')]);_0x14b2b1[_0xf222('0x3a')]=qs[_0xf222('0x32')](_['pick'](_0x2a8310[_0xf222('0x31')],_0x1c5cd3['filters']),_0x2f04bf);if(_0x2a8310[_0xf222('0x31')][_0xf222('0x3b')]){_0x14b2b1[_0xf222('0x3a')]=_['merge'](_0x14b2b1[_0xf222('0x3a')],{'$or':_[_0xf222('0x2b')](_0x2f04bf,function(_0x54a10d){if(_0x54a10d[_0xf222('0x3c')]!=='VIRTUAL'){var _0x3a766b={};_0x3a766b[_0x54a10d[_0xf222('0x28')]]={'$like':'%'+_0x2a8310[_0xf222('0x31')]['filter']+'%'};return _0x3a766b;}})});}_0x14b2b1=_[_0xf222('0x3d')]({},_0x14b2b1,_0x2a8310[_0xf222('0x3e')]);var _0x2c1e49={'where':_0x14b2b1[_0xf222('0x3a')]};return db[_0xf222('0x2c')][_0xf222('0x3f')](_0x2c1e49)['then'](function(_0x1ae1d4){_0x3d5508[_0xf222('0x3f')]=_0x1ae1d4;if(_0x2a8310['query']['includeAll']){_0x14b2b1[_0xf222('0x40')]=[{'all':!![]}];}return db['ChatOfflineMessage'][_0xf222('0x41')](_0x14b2b1);})[_0xf222('0x24')](function(_0x1d8ab1){_0x3d5508[_0xf222('0x42')]=_0x1d8ab1;return _0x3d5508;})['then'](respondWithFilteredResult(_0x501f8e,_0x14b2b1))['catch'](handleError(_0x501f8e,null));};exports[_0xf222('0x43')]=function(_0x545464,_0x522a9e){var _0x2ae437={'raw':!![],'where':{'id':_0x545464[_0xf222('0x44')]['id']}},_0x278fb8={};_0x278fb8[_0xf222('0x30')]=_[_0xf222('0x45')](db[_0xf222('0x2c')]['rawAttributes']);_0x278fb8[_0xf222('0x31')]=_[_0xf222('0x45')](_0x545464['query']);_0x278fb8[_0xf222('0x32')]=_[_0xf222('0x33')](_0x278fb8['model'],_0x278fb8[_0xf222('0x31')]);_0x2ae437['attributes']=_[_0xf222('0x33')](_0x278fb8[_0xf222('0x30')],qs[_0xf222('0x35')](_0x545464[_0xf222('0x31')][_0xf222('0x35')]));_0x2ae437[_0xf222('0x34')]=_0x2ae437[_0xf222('0x34')][_0xf222('0x36')]?_0x2ae437[_0xf222('0x34')]:_0x278fb8[_0xf222('0x30')];if(_0x545464[_0xf222('0x31')]['includeAll']){_0x2ae437['include']=[{'all':!![]}];}_0x2ae437=_['merge']({},_0x2ae437,_0x545464[_0xf222('0x3e')]);return db[_0xf222('0x2c')][_0xf222('0x46')](_0x2ae437)[_0xf222('0x24')](handleEntityNotFound(_0x522a9e,null))['then'](respondWithResult(_0x522a9e,null))[_0xf222('0x47')](handleError(_0x522a9e,null));};exports[_0xf222('0x48')]=function(_0x18d9f7,_0x2841a2){return db['ChatOfflineMessage'][_0xf222('0x48')](_0x18d9f7[_0xf222('0x49')],{})[_0xf222('0x24')](respondWithResult(_0x2841a2,0xc9))[_0xf222('0x47')](handleError(_0x2841a2,null));};exports[_0xf222('0x23')]=function(_0x14710f,_0x8fc65e){if(_0x14710f[_0xf222('0x49')]['id']){delete _0x14710f[_0xf222('0x49')]['id'];}return db[_0xf222('0x2c')]['find']({'where':{'id':_0x14710f['params']['id']}})[_0xf222('0x24')](handleEntityNotFound(_0x8fc65e,null))['then'](saveUpdates(_0x14710f[_0xf222('0x49')],null))['then'](respondWithResult(_0x8fc65e,null))[_0xf222('0x47')](handleError(_0x8fc65e,null));};exports['destroy']=function(_0x2d8a04,_0xb679b6){return db[_0xf222('0x2c')][_0xf222('0x46')]({'where':{'id':_0x2d8a04['params']['id']}})[_0xf222('0x24')](handleEntityNotFound(_0xb679b6,null))[_0xf222('0x24')](removeEntity(_0xb679b6,null))[_0xf222('0x47')](handleError(_0xb679b6,null));};exports[_0xf222('0x4a')]=function(_0x14458b,_0x427691){return db[_0xf222('0x2c')][_0xf222('0x4a')]()[_0xf222('0x24')](respondWithResult(_0x427691,null))[_0xf222('0x47')](handleError(_0x427691,null));};