Built motion from commit (unavailable).|2.4.4
[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 _0xfbf7=['../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','count','offset','set','Content-Range','apply','reject','save','update','then','destroy','end','error','stack','name','send','index','ChatOfflineMessage','model','query','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','sort','where','pick','filters','merge','key','VIRTUAL','field','filter','options','includeAll','include','findAll','rows','catch','show','keys','rawAttributes','find','create','body','params','describe','html-pdf','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','lodash','squel','crypto','jsforce','ioredis','../../components/auth/service'];(function(_0x148028,_0x8f4e9){var _0xb0ec6=function(_0x502efd){while(--_0x502efd){_0x148028['push'](_0x148028['shift']());}};_0xb0ec6(++_0x8f4e9);}(_0xfbf7,0x113));var _0x7fbf=function(_0x3d0f43,_0x42be34){_0x3d0f43=_0x3d0f43-0x0;var _0x55e4c1=_0xfbf7[_0x3d0f43];return _0x55e4c1;};'use strict';var pdf=require(_0x7fbf('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x7fbf('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x7fbf('0x2'));var rp=require(_0x7fbf('0x3'));var moment=require(_0x7fbf('0x4'));var BPromise=require(_0x7fbf('0x5'));var Mustache=require(_0x7fbf('0x6'));var util=require(_0x7fbf('0x7'));var path=require(_0x7fbf('0x8'));var sox=require(_0x7fbf('0x9'));var csv=require(_0x7fbf('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x7fbf('0xb'));var squel=require(_0x7fbf('0xc'));var crypto=require(_0x7fbf('0xd'));var jsforce=require(_0x7fbf('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x7fbf('0xa'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x7fbf('0xf'));var authService=require(_0x7fbf('0x10'));var qs=require('../../components/parsers/qs');var hardwareService=require(_0x7fbf('0x11'));var logger=require(_0x7fbf('0x12'))('api');var utils=require(_0x7fbf('0x13'));var config=require(_0x7fbf('0x14'));var db=require(_0x7fbf('0x15'))['db'];function respondWithStatusCode(_0x264eba,_0x1d1791){_0x1d1791=_0x1d1791||0xcc;return function(_0x42f11b){if(_0x42f11b){return _0x264eba[_0x7fbf('0x16')](_0x1d1791);}return _0x264eba[_0x7fbf('0x17')](_0x1d1791)['end']();};}function respondWithResult(_0x3262a9,_0x5a6f73){_0x5a6f73=_0x5a6f73||0xc8;return function(_0x2d52b4){if(_0x2d52b4){return _0x3262a9['status'](_0x5a6f73)['json'](_0x2d52b4);}};}function respondWithFilteredResult(_0x4dc995,_0x485f30){return function(_0x4fd0ff){if(_0x4fd0ff){var _0xff3af9=_0x4fd0ff[_0x7fbf('0x18')],_0x20acca=_0x485f30['offset'],_0x81a575=_0x485f30[_0x7fbf('0x19')]+_0x485f30['limit'],_0x13f749;if(_0x81a575>=_0xff3af9){_0x81a575=_0xff3af9;_0x13f749=0xc8;}else{_0x13f749=0xce;}_0x4dc995['status'](_0x13f749);return _0x4dc995[_0x7fbf('0x1a')](_0x7fbf('0x1b'),_0x20acca+'-'+_0x81a575+'/'+_0xff3af9)['json'](_0x4fd0ff);}return null;};}function patchUpdates(_0x2a129b){return function(_0xabb19c){try{jsonpatch[_0x7fbf('0x1c')](_0xabb19c,_0x2a129b,!![]);}catch(_0x9f3c60){return BPromise[_0x7fbf('0x1d')](_0x9f3c60);}return _0xabb19c[_0x7fbf('0x1e')]();};}function saveUpdates(_0x2047d8,_0x12164a){return function(_0x5865d3){if(_0x5865d3){return _0x5865d3[_0x7fbf('0x1f')](_0x2047d8)[_0x7fbf('0x20')](function(_0x429eaf){return _0x429eaf;});}return null;};}function removeEntity(_0xc09356,_0xdb2136){return function(_0x47bc19){if(_0x47bc19){return _0x47bc19[_0x7fbf('0x21')]()[_0x7fbf('0x20')](function(){_0xc09356[_0x7fbf('0x17')](0xcc)[_0x7fbf('0x22')]();});}};}function handleEntityNotFound(_0x469876,_0x351690){return function(_0x436ea0){if(!_0x436ea0){_0x469876[_0x7fbf('0x16')](0x194);}return _0x436ea0;};}function handleError(_0x9c9f11,_0x50e5a3){_0x50e5a3=_0x50e5a3||0x1f4;return function(_0xa2c2c){logger[_0x7fbf('0x23')](_0xa2c2c[_0x7fbf('0x24')]);if(_0xa2c2c[_0x7fbf('0x25')]){delete _0xa2c2c[_0x7fbf('0x25')];}_0x9c9f11[_0x7fbf('0x17')](_0x50e5a3)[_0x7fbf('0x26')](_0xa2c2c);};}exports[_0x7fbf('0x27')]=function(_0x451809,_0x42a680){var _0x23aa7c={},_0x2b66e4={},_0x233cc6={'count':0x0,'rows':[]};var _0x1adeb3=db[_0x7fbf('0x28')]['rawAttributes'];_0x2b66e4[_0x7fbf('0x29')]=_['keys'](_0x1adeb3);_0x2b66e4[_0x7fbf('0x2a')]=_['keys'](_0x451809[_0x7fbf('0x2a')]);_0x2b66e4['filters']=_[_0x7fbf('0x2b')](_0x2b66e4[_0x7fbf('0x29')],_0x2b66e4[_0x7fbf('0x2a')]);_0x23aa7c[_0x7fbf('0x2c')]=_[_0x7fbf('0x2b')](_0x2b66e4['model'],qs[_0x7fbf('0x2d')](_0x451809['query'][_0x7fbf('0x2d')]));_0x23aa7c[_0x7fbf('0x2c')]=_0x23aa7c[_0x7fbf('0x2c')][_0x7fbf('0x2e')]?_0x23aa7c[_0x7fbf('0x2c')]:_0x2b66e4[_0x7fbf('0x29')];if(!_0x451809['query'][_0x7fbf('0x2f')](_0x7fbf('0x30'))){_0x23aa7c[_0x7fbf('0x31')]=qs[_0x7fbf('0x31')](_0x451809[_0x7fbf('0x2a')][_0x7fbf('0x31')]);_0x23aa7c[_0x7fbf('0x19')]=qs['offset'](_0x451809['query'][_0x7fbf('0x19')]);}_0x23aa7c['order']=qs[_0x7fbf('0x32')](_0x451809[_0x7fbf('0x2a')][_0x7fbf('0x32')]);_0x23aa7c[_0x7fbf('0x33')]=qs['filters'](_[_0x7fbf('0x34')](_0x451809[_0x7fbf('0x2a')],_0x2b66e4[_0x7fbf('0x35')]));if(_0x451809[_0x7fbf('0x2a')]['filter']){_0x23aa7c['where']=_[_0x7fbf('0x36')](_0x23aa7c[_0x7fbf('0x33')],{'$or':_['map'](_0x1adeb3,function(_0x3c5fa2){if(_0x3c5fa2['type'][_0x7fbf('0x37')]!==_0x7fbf('0x38')){var _0x1df40f={};_0x1df40f[_0x3c5fa2[_0x7fbf('0x39')]]={'$like':'%'+_0x451809[_0x7fbf('0x2a')][_0x7fbf('0x3a')]+'%'};return _0x1df40f;}})});}_0x23aa7c=_[_0x7fbf('0x36')]({},_0x23aa7c,_0x451809[_0x7fbf('0x3b')]);var _0x5035a0={'where':_0x23aa7c[_0x7fbf('0x33')]};return db[_0x7fbf('0x28')]['count'](_0x5035a0)[_0x7fbf('0x20')](function(_0x3d6358){_0x233cc6[_0x7fbf('0x18')]=_0x3d6358;if(_0x451809[_0x7fbf('0x2a')][_0x7fbf('0x3c')]){_0x23aa7c[_0x7fbf('0x3d')]=[{'all':!![]}];}return db[_0x7fbf('0x28')][_0x7fbf('0x3e')](_0x23aa7c);})[_0x7fbf('0x20')](function(_0x1923d2){_0x233cc6[_0x7fbf('0x3f')]=_0x1923d2;return _0x233cc6;})[_0x7fbf('0x20')](respondWithFilteredResult(_0x42a680,_0x23aa7c))[_0x7fbf('0x40')](handleError(_0x42a680,null));};exports[_0x7fbf('0x41')]=function(_0x150f10,_0x2337c2){var _0xef310b={'raw':!![],'where':{'id':_0x150f10['params']['id']}},_0x1ab893={};_0x1ab893['model']=_[_0x7fbf('0x42')](db[_0x7fbf('0x28')][_0x7fbf('0x43')]);_0x1ab893[_0x7fbf('0x2a')]=_['keys'](_0x150f10[_0x7fbf('0x2a')]);_0x1ab893[_0x7fbf('0x35')]=_[_0x7fbf('0x2b')](_0x1ab893[_0x7fbf('0x29')],_0x1ab893[_0x7fbf('0x2a')]);_0xef310b[_0x7fbf('0x2c')]=_['intersection'](_0x1ab893[_0x7fbf('0x29')],qs[_0x7fbf('0x2d')](_0x150f10[_0x7fbf('0x2a')][_0x7fbf('0x2d')]));_0xef310b[_0x7fbf('0x2c')]=_0xef310b[_0x7fbf('0x2c')][_0x7fbf('0x2e')]?_0xef310b['attributes']:_0x1ab893[_0x7fbf('0x29')];if(_0x150f10[_0x7fbf('0x2a')][_0x7fbf('0x3c')]){_0xef310b['include']=[{'all':!![]}];}_0xef310b=_[_0x7fbf('0x36')]({},_0xef310b,_0x150f10[_0x7fbf('0x3b')]);return db[_0x7fbf('0x28')][_0x7fbf('0x44')](_0xef310b)[_0x7fbf('0x20')](handleEntityNotFound(_0x2337c2,null))[_0x7fbf('0x20')](respondWithResult(_0x2337c2,null))[_0x7fbf('0x40')](handleError(_0x2337c2,null));};exports[_0x7fbf('0x45')]=function(_0x55eff0,_0x4e8912){return db[_0x7fbf('0x28')]['create'](_0x55eff0[_0x7fbf('0x46')],{})[_0x7fbf('0x20')](respondWithResult(_0x4e8912,0xc9))['catch'](handleError(_0x4e8912,null));};exports[_0x7fbf('0x1f')]=function(_0x282953,_0x461cdd){if(_0x282953[_0x7fbf('0x46')]['id']){delete _0x282953[_0x7fbf('0x46')]['id'];}return db['ChatOfflineMessage'][_0x7fbf('0x44')]({'where':{'id':_0x282953[_0x7fbf('0x47')]['id']}})['then'](handleEntityNotFound(_0x461cdd,null))[_0x7fbf('0x20')](saveUpdates(_0x282953[_0x7fbf('0x46')],null))[_0x7fbf('0x20')](respondWithResult(_0x461cdd,null))[_0x7fbf('0x40')](handleError(_0x461cdd,null));};exports[_0x7fbf('0x21')]=function(_0x333ad6,_0x38a5ba){return db[_0x7fbf('0x28')][_0x7fbf('0x44')]({'where':{'id':_0x333ad6['params']['id']}})[_0x7fbf('0x20')](handleEntityNotFound(_0x38a5ba,null))[_0x7fbf('0x20')](removeEntity(_0x38a5ba,null))[_0x7fbf('0x40')](handleError(_0x38a5ba,null));};exports[_0x7fbf('0x48')]=function(_0x566305,_0x5600fb){return db['ChatOfflineMessage']['describe']()[_0x7fbf('0x20')](respondWithResult(_0x5600fb,null))[_0x7fbf('0x40')](handleError(_0x5600fb,null));};