Built motion from commit (unavailable).|2.5.0
[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 _0x6c7b=['limit','set','Content-Range','apply','reject','save','update','then','error','name','send','index','map','ChatOfflineMessage','type','key','model','query','keys','filters','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','findAll','rows','show','rawAttributes','find','catch','create','body','params','destroy','describe','html-pdf','fast-json-patch','moment','bluebird','mustache','path','sox','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','count','offset'];(function(_0x5d1d99,_0x10ca23){var _0x2957ec=function(_0x4f4ba){while(--_0x4f4ba){_0x5d1d99['push'](_0x5d1d99['shift']());}};_0x2957ec(++_0x10ca23);}(_0x6c7b,0x10b));var _0xb6c7=function(_0x9097e4,_0x1b0349){_0x9097e4=_0x9097e4-0x0;var _0x2aad48=_0x6c7b[_0x9097e4];return _0x2aad48;};'use strict';var pdf=require(_0xb6c7('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xb6c7('0x1'));var rp=require('request-promise');var moment=require(_0xb6c7('0x2'));var BPromise=require(_0xb6c7('0x3'));var Mustache=require(_0xb6c7('0x4'));var util=require('util');var path=require(_0xb6c7('0x5'));var sox=require(_0xb6c7('0x6'));var csv=require(_0xb6c7('0x7'));var ejs=require(_0xb6c7('0x8'));var fs=require('fs');var _=require(_0xb6c7('0x9'));var squel=require('squel');var crypto=require(_0xb6c7('0xa'));var jsforce=require(_0xb6c7('0xb'));var deskjs=require(_0xb6c7('0xc'));var toCsv=require(_0xb6c7('0x7'));var querystring=require(_0xb6c7('0xd'));var Papa=require(_0xb6c7('0xe'));var Redis=require(_0xb6c7('0xf'));var authService=require(_0xb6c7('0x10'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xb6c7('0x11'));var logger=require(_0xb6c7('0x12'))(_0xb6c7('0x13'));var utils=require(_0xb6c7('0x14'));var config=require(_0xb6c7('0x15'));var db=require(_0xb6c7('0x16'))['db'];function respondWithStatusCode(_0x1b5199,_0x50c2de){_0x50c2de=_0x50c2de||0xcc;return function(_0x9b32b7){if(_0x9b32b7){return _0x1b5199[_0xb6c7('0x17')](_0x50c2de);}return _0x1b5199[_0xb6c7('0x18')](_0x50c2de)[_0xb6c7('0x19')]();};}function respondWithResult(_0x4086a1,_0x383ac5){_0x383ac5=_0x383ac5||0xc8;return function(_0x147e4a){if(_0x147e4a){return _0x4086a1['status'](_0x383ac5)[_0xb6c7('0x1a')](_0x147e4a);}};}function respondWithFilteredResult(_0x4e4c3f,_0x480d9a){return function(_0x5d5428){if(_0x5d5428){var _0x19c145=_0x5d5428[_0xb6c7('0x1b')],_0x48b7ec=_0x480d9a[_0xb6c7('0x1c')],_0x45f1a3=_0x480d9a[_0xb6c7('0x1c')]+_0x480d9a[_0xb6c7('0x1d')],_0x1a2bc9;if(_0x45f1a3>=_0x19c145){_0x45f1a3=_0x19c145;_0x1a2bc9=0xc8;}else{_0x1a2bc9=0xce;}_0x4e4c3f[_0xb6c7('0x18')](_0x1a2bc9);return _0x4e4c3f[_0xb6c7('0x1e')](_0xb6c7('0x1f'),_0x48b7ec+'-'+_0x45f1a3+'/'+_0x19c145)[_0xb6c7('0x1a')](_0x5d5428);}return null;};}function patchUpdates(_0xef5eb1){return function(_0x3f133f){try{jsonpatch[_0xb6c7('0x20')](_0x3f133f,_0xef5eb1,!![]);}catch(_0x5b5022){return BPromise[_0xb6c7('0x21')](_0x5b5022);}return _0x3f133f[_0xb6c7('0x22')]();};}function saveUpdates(_0x599b49,_0x25ca5d){return function(_0x5a1c0a){if(_0x5a1c0a){return _0x5a1c0a[_0xb6c7('0x23')](_0x599b49)['then'](function(_0x141db2){return _0x141db2;});}return null;};}function removeEntity(_0x4f2960,_0x24c0b3){return function(_0x146dd4){if(_0x146dd4){return _0x146dd4['destroy']()[_0xb6c7('0x24')](function(){_0x4f2960[_0xb6c7('0x18')](0xcc)[_0xb6c7('0x19')]();});}};}function handleEntityNotFound(_0x4232b6,_0xd33675){return function(_0x1ee45d){if(!_0x1ee45d){_0x4232b6['sendStatus'](0x194);}return _0x1ee45d;};}function handleError(_0x4109c3,_0x1f4e06){_0x1f4e06=_0x1f4e06||0x1f4;return function(_0x209a21){logger[_0xb6c7('0x25')](_0x209a21['stack']);if(_0x209a21[_0xb6c7('0x26')]){delete _0x209a21[_0xb6c7('0x26')];}_0x4109c3['status'](_0x1f4e06)[_0xb6c7('0x27')](_0x209a21);};}exports[_0xb6c7('0x28')]=function(_0x1de00f,_0x32cd6b){var _0x4fb79f={},_0x30eeb4={},_0x54373f={'count':0x0,'rows':[]};var _0x31e014=_[_0xb6c7('0x29')](db[_0xb6c7('0x2a')]['rawAttributes'],function(_0x47acab){return{'name':_0x47acab['fieldName'],'type':_0x47acab[_0xb6c7('0x2b')][_0xb6c7('0x2c')]};});_0x30eeb4[_0xb6c7('0x2d')]=_[_0xb6c7('0x29')](_0x31e014,_0xb6c7('0x26'));_0x30eeb4[_0xb6c7('0x2e')]=_[_0xb6c7('0x2f')](_0x1de00f[_0xb6c7('0x2e')]);_0x30eeb4[_0xb6c7('0x30')]=_[_0xb6c7('0x31')](_0x30eeb4['model'],_0x30eeb4[_0xb6c7('0x2e')]);_0x4fb79f['attributes']=_[_0xb6c7('0x31')](_0x30eeb4[_0xb6c7('0x2d')],qs[_0xb6c7('0x32')](_0x1de00f[_0xb6c7('0x2e')][_0xb6c7('0x32')]));_0x4fb79f['attributes']=_0x4fb79f['attributes']['length']?_0x4fb79f[_0xb6c7('0x33')]:_0x30eeb4[_0xb6c7('0x2d')];if(!_0x1de00f['query'][_0xb6c7('0x34')](_0xb6c7('0x35'))){_0x4fb79f['limit']=qs[_0xb6c7('0x1d')](_0x1de00f[_0xb6c7('0x2e')][_0xb6c7('0x1d')]);_0x4fb79f[_0xb6c7('0x1c')]=qs[_0xb6c7('0x1c')](_0x1de00f[_0xb6c7('0x2e')]['offset']);}_0x4fb79f[_0xb6c7('0x36')]=qs[_0xb6c7('0x37')](_0x1de00f[_0xb6c7('0x2e')][_0xb6c7('0x37')]);_0x4fb79f[_0xb6c7('0x38')]=qs[_0xb6c7('0x30')](_[_0xb6c7('0x39')](_0x1de00f['query'],_0x30eeb4['filters']),_0x31e014);if(_0x1de00f[_0xb6c7('0x2e')][_0xb6c7('0x3a')]){_0x4fb79f[_0xb6c7('0x38')]=_[_0xb6c7('0x3b')](_0x4fb79f[_0xb6c7('0x38')],{'$or':_[_0xb6c7('0x29')](_0x31e014,function(_0x170965){if(_0x170965[_0xb6c7('0x2b')]!==_0xb6c7('0x3c')){var _0x2f6193={};_0x2f6193[_0x170965['name']]={'$like':'%'+_0x1de00f[_0xb6c7('0x2e')]['filter']+'%'};return _0x2f6193;}})});}_0x4fb79f=_['merge']({},_0x4fb79f,_0x1de00f[_0xb6c7('0x3d')]);var _0x527c7e={'where':_0x4fb79f[_0xb6c7('0x38')]};return db[_0xb6c7('0x2a')]['count'](_0x527c7e)[_0xb6c7('0x24')](function(_0x22f5b2){_0x54373f[_0xb6c7('0x1b')]=_0x22f5b2;if(_0x1de00f[_0xb6c7('0x2e')][_0xb6c7('0x3e')]){_0x4fb79f['include']=[{'all':!![]}];}return db['ChatOfflineMessage'][_0xb6c7('0x3f')](_0x4fb79f);})[_0xb6c7('0x24')](function(_0xb7f85b){_0x54373f[_0xb6c7('0x40')]=_0xb7f85b;return _0x54373f;})['then'](respondWithFilteredResult(_0x32cd6b,_0x4fb79f))['catch'](handleError(_0x32cd6b,null));};exports[_0xb6c7('0x41')]=function(_0x4019c,_0x205301){var _0x214d04={'raw':!![],'where':{'id':_0x4019c['params']['id']}},_0x793060={};_0x793060['model']=_['keys'](db[_0xb6c7('0x2a')][_0xb6c7('0x42')]);_0x793060[_0xb6c7('0x2e')]=_['keys'](_0x4019c[_0xb6c7('0x2e')]);_0x793060[_0xb6c7('0x30')]=_['intersection'](_0x793060[_0xb6c7('0x2d')],_0x793060[_0xb6c7('0x2e')]);_0x214d04[_0xb6c7('0x33')]=_[_0xb6c7('0x31')](_0x793060[_0xb6c7('0x2d')],qs['fields'](_0x4019c[_0xb6c7('0x2e')][_0xb6c7('0x32')]));_0x214d04[_0xb6c7('0x33')]=_0x214d04['attributes']['length']?_0x214d04[_0xb6c7('0x33')]:_0x793060[_0xb6c7('0x2d')];if(_0x4019c[_0xb6c7('0x2e')]['includeAll']){_0x214d04['include']=[{'all':!![]}];}_0x214d04=_['merge']({},_0x214d04,_0x4019c[_0xb6c7('0x3d')]);return db[_0xb6c7('0x2a')][_0xb6c7('0x43')](_0x214d04)[_0xb6c7('0x24')](handleEntityNotFound(_0x205301,null))[_0xb6c7('0x24')](respondWithResult(_0x205301,null))[_0xb6c7('0x44')](handleError(_0x205301,null));};exports[_0xb6c7('0x45')]=function(_0x594207,_0x22b21b){return db[_0xb6c7('0x2a')][_0xb6c7('0x45')](_0x594207[_0xb6c7('0x46')],{})[_0xb6c7('0x24')](respondWithResult(_0x22b21b,0xc9))['catch'](handleError(_0x22b21b,null));};exports[_0xb6c7('0x23')]=function(_0x40bbff,_0x40292c){if(_0x40bbff[_0xb6c7('0x46')]['id']){delete _0x40bbff[_0xb6c7('0x46')]['id'];}return db[_0xb6c7('0x2a')]['find']({'where':{'id':_0x40bbff[_0xb6c7('0x47')]['id']}})[_0xb6c7('0x24')](handleEntityNotFound(_0x40292c,null))[_0xb6c7('0x24')](saveUpdates(_0x40bbff[_0xb6c7('0x46')],null))[_0xb6c7('0x24')](respondWithResult(_0x40292c,null))[_0xb6c7('0x44')](handleError(_0x40292c,null));};exports[_0xb6c7('0x48')]=function(_0x4cc0f6,_0x5218af){return db['ChatOfflineMessage'][_0xb6c7('0x43')]({'where':{'id':_0x4cc0f6[_0xb6c7('0x47')]['id']}})[_0xb6c7('0x24')](handleEntityNotFound(_0x5218af,null))[_0xb6c7('0x24')](removeEntity(_0x5218af,null))[_0xb6c7('0x44')](handleError(_0x5218af,null));};exports[_0xb6c7('0x49')]=function(_0x581da8,_0x4f5c99){return db[_0xb6c7('0x2a')]['describe']()[_0xb6c7('0x24')](respondWithResult(_0x4f5c99,null))[_0xb6c7('0x44')](handleError(_0x4f5c99,null));};