624d8109189093065a66bc0b3f13590f997cb1de
[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 _0xf2ca=['fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','lodash','crypto','jsforce','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../mysqldb','status','end','json','count','offset','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','index','map','ChatOfflineMessage','fieldName','type','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','sort','pick','merge','where','VIRTUAL','options','includeAll','include','rows','catch','show','params','rawAttributes','keys','find','create','body','describe','html-pdf','eml-format','rimraf'];(function(_0x68c979,_0x431cff){var _0x4f0001=function(_0xa7595d){while(--_0xa7595d){_0x68c979['push'](_0x68c979['shift']());}};_0x4f0001(++_0x431cff);}(_0xf2ca,0x16a));var _0xaf2c=function(_0x80bea0,_0x4c30f4){_0x80bea0=_0x80bea0-0x0;var _0x50fb90=_0xf2ca[_0x80bea0];return _0x50fb90;};'use strict';var pdf=require(_0xaf2c('0x0'));var emlformat=require(_0xaf2c('0x1'));var rimraf=require(_0xaf2c('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0xaf2c('0x3'));var rp=require(_0xaf2c('0x4'));var moment=require(_0xaf2c('0x5'));var BPromise=require(_0xaf2c('0x6'));var Mustache=require(_0xaf2c('0x7'));var util=require(_0xaf2c('0x8'));var path=require('path');var sox=require(_0xaf2c('0x9'));var csv=require(_0xaf2c('0xa'));var ejs=require(_0xaf2c('0xb'));var fs=require('fs');var _=require(_0xaf2c('0xc'));var squel=require('squel');var crypto=require(_0xaf2c('0xd'));var jsforce=require(_0xaf2c('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xaf2c('0xa'));var querystring=require('querystring');var Papa=require(_0xaf2c('0xf'));var Redis=require('ioredis');var authService=require(_0xaf2c('0x10'));var qs=require(_0xaf2c('0x11'));var as=require(_0xaf2c('0x12'));var hardwareService=require(_0xaf2c('0x13'));var logger=require('../../config/logger')('api');var utils=require(_0xaf2c('0x14'));var config=require(_0xaf2c('0x15'));var db=require(_0xaf2c('0x16'))['db'];function respondWithStatusCode(_0xd56a5d,_0x285dac){_0x285dac=_0x285dac||0xcc;return function(_0x59a59b){if(_0x59a59b){return _0xd56a5d['sendStatus'](_0x285dac);}return _0xd56a5d[_0xaf2c('0x17')](_0x285dac)[_0xaf2c('0x18')]();};}function respondWithResult(_0x935959,_0x18a8a5){_0x18a8a5=_0x18a8a5||0xc8;return function(_0x293ca6){if(_0x293ca6){return _0x935959[_0xaf2c('0x17')](_0x18a8a5)[_0xaf2c('0x19')](_0x293ca6);}};}function respondWithFilteredResult(_0x3c1088,_0x2119c8){return function(_0x1d0633){if(_0x1d0633){var _0x6ac8e=_0x1d0633[_0xaf2c('0x1a')],_0x2b4d13=_0x2119c8['offset'],_0x26bf7b=_0x2119c8[_0xaf2c('0x1b')]+_0x2119c8['limit'],_0x3432e4;if(_0x26bf7b>=_0x6ac8e){_0x26bf7b=_0x6ac8e;_0x3432e4=0xc8;}else{_0x3432e4=0xce;}_0x3c1088[_0xaf2c('0x17')](_0x3432e4);return _0x3c1088[_0xaf2c('0x1c')](_0xaf2c('0x1d'),_0x2b4d13+'-'+_0x26bf7b+'/'+_0x6ac8e)['json'](_0x1d0633);}return null;};}function patchUpdates(_0x28ae7b){return function(_0x297bcd){try{jsonpatch[_0xaf2c('0x1e')](_0x297bcd,_0x28ae7b,!![]);}catch(_0x20000b){return BPromise[_0xaf2c('0x1f')](_0x20000b);}return _0x297bcd[_0xaf2c('0x20')]();};}function saveUpdates(_0x531609,_0x35e712){return function(_0x164bcb){if(_0x164bcb){return _0x164bcb[_0xaf2c('0x21')](_0x531609)[_0xaf2c('0x22')](function(_0x237318){return _0x237318;});}return null;};}function removeEntity(_0x486de2,_0x396646){return function(_0xbf6f62){if(_0xbf6f62){return _0xbf6f62[_0xaf2c('0x23')]()['then'](function(){_0x486de2['status'](0xcc)[_0xaf2c('0x18')]();});}};}function handleEntityNotFound(_0x303546,_0x1cafad){return function(_0x99f78d){if(!_0x99f78d){_0x303546['sendStatus'](0x194);}return _0x99f78d;};}function handleError(_0x2b8f1a,_0xf1a7cf){_0xf1a7cf=_0xf1a7cf||0x1f4;return function(_0x3a0145){logger[_0xaf2c('0x24')](_0x3a0145[_0xaf2c('0x25')]);if(_0x3a0145[_0xaf2c('0x26')]){delete _0x3a0145[_0xaf2c('0x26')];}_0x2b8f1a['status'](_0xf1a7cf)[_0xaf2c('0x27')](_0x3a0145);};}exports[_0xaf2c('0x28')]=function(_0x36f37c,_0x410536){var _0x4b7cf2={},_0x3fb190={},_0x589d47={'count':0x0,'rows':[]};var _0x38db1b=_[_0xaf2c('0x29')](db[_0xaf2c('0x2a')]['rawAttributes'],function(_0x2747bb){return{'name':_0x2747bb[_0xaf2c('0x2b')],'type':_0x2747bb[_0xaf2c('0x2c')]['key']};});_0x3fb190[_0xaf2c('0x2d')]=_[_0xaf2c('0x29')](_0x38db1b,_0xaf2c('0x26'));_0x3fb190[_0xaf2c('0x2e')]=_['keys'](_0x36f37c[_0xaf2c('0x2e')]);_0x3fb190[_0xaf2c('0x2f')]=_[_0xaf2c('0x30')](_0x3fb190['model'],_0x3fb190['query']);_0x4b7cf2[_0xaf2c('0x31')]=_['intersection'](_0x3fb190[_0xaf2c('0x2d')],qs['fields'](_0x36f37c[_0xaf2c('0x2e')][_0xaf2c('0x32')]));_0x4b7cf2['attributes']=_0x4b7cf2[_0xaf2c('0x31')][_0xaf2c('0x33')]?_0x4b7cf2['attributes']:_0x3fb190[_0xaf2c('0x2d')];if(!_0x36f37c[_0xaf2c('0x2e')][_0xaf2c('0x34')](_0xaf2c('0x35'))){_0x4b7cf2[_0xaf2c('0x36')]=qs[_0xaf2c('0x36')](_0x36f37c['query'][_0xaf2c('0x36')]);_0x4b7cf2['offset']=qs[_0xaf2c('0x1b')](_0x36f37c['query'][_0xaf2c('0x1b')]);}_0x4b7cf2['order']=qs[_0xaf2c('0x37')](_0x36f37c['query'][_0xaf2c('0x37')]);_0x4b7cf2['where']=qs[_0xaf2c('0x2f')](_[_0xaf2c('0x38')](_0x36f37c[_0xaf2c('0x2e')],_0x3fb190[_0xaf2c('0x2f')]),_0x38db1b);if(_0x36f37c[_0xaf2c('0x2e')]['filter']){_0x4b7cf2['where']=_[_0xaf2c('0x39')](_0x4b7cf2[_0xaf2c('0x3a')],{'$or':_[_0xaf2c('0x29')](_0x38db1b,function(_0xa44813){if(_0xa44813[_0xaf2c('0x2c')]!==_0xaf2c('0x3b')){var _0x573db3={};_0x573db3[_0xa44813[_0xaf2c('0x26')]]={'$like':'%'+_0x36f37c[_0xaf2c('0x2e')]['filter']+'%'};return _0x573db3;}})});}_0x4b7cf2=_[_0xaf2c('0x39')]({},_0x4b7cf2,_0x36f37c[_0xaf2c('0x3c')]);var _0x25bebd={'where':_0x4b7cf2[_0xaf2c('0x3a')]};return db[_0xaf2c('0x2a')][_0xaf2c('0x1a')](_0x25bebd)[_0xaf2c('0x22')](function(_0x310d3b){_0x589d47[_0xaf2c('0x1a')]=_0x310d3b;if(_0x36f37c[_0xaf2c('0x2e')][_0xaf2c('0x3d')]){_0x4b7cf2[_0xaf2c('0x3e')]=[{'all':!![]}];}return db[_0xaf2c('0x2a')]['findAll'](_0x4b7cf2);})['then'](function(_0x4db7d0){_0x589d47[_0xaf2c('0x3f')]=_0x4db7d0;return _0x589d47;})[_0xaf2c('0x22')](respondWithFilteredResult(_0x410536,_0x4b7cf2))[_0xaf2c('0x40')](handleError(_0x410536,null));};exports[_0xaf2c('0x41')]=function(_0x715f39,_0x29460c){var _0x51c441={'raw':!![],'where':{'id':_0x715f39[_0xaf2c('0x42')]['id']}},_0x1d58bd={};_0x1d58bd[_0xaf2c('0x2d')]=_['keys'](db['ChatOfflineMessage'][_0xaf2c('0x43')]);_0x1d58bd['query']=_[_0xaf2c('0x44')](_0x715f39[_0xaf2c('0x2e')]);_0x1d58bd[_0xaf2c('0x2f')]=_[_0xaf2c('0x30')](_0x1d58bd['model'],_0x1d58bd[_0xaf2c('0x2e')]);_0x51c441['attributes']=_[_0xaf2c('0x30')](_0x1d58bd[_0xaf2c('0x2d')],qs['fields'](_0x715f39[_0xaf2c('0x2e')]['fields']));_0x51c441[_0xaf2c('0x31')]=_0x51c441[_0xaf2c('0x31')][_0xaf2c('0x33')]?_0x51c441[_0xaf2c('0x31')]:_0x1d58bd[_0xaf2c('0x2d')];if(_0x715f39[_0xaf2c('0x2e')][_0xaf2c('0x3d')]){_0x51c441[_0xaf2c('0x3e')]=[{'all':!![]}];}_0x51c441=_[_0xaf2c('0x39')]({},_0x51c441,_0x715f39['options']);return db['ChatOfflineMessage'][_0xaf2c('0x45')](_0x51c441)['then'](handleEntityNotFound(_0x29460c,null))['then'](respondWithResult(_0x29460c,null))['catch'](handleError(_0x29460c,null));};exports[_0xaf2c('0x46')]=function(_0x964b76,_0x3cabd4){return db[_0xaf2c('0x2a')]['create'](_0x964b76[_0xaf2c('0x47')],{})['then'](respondWithResult(_0x3cabd4,0xc9))[_0xaf2c('0x40')](handleError(_0x3cabd4,null));};exports['update']=function(_0x166c26,_0x133e8c){if(_0x166c26[_0xaf2c('0x47')]['id']){delete _0x166c26[_0xaf2c('0x47')]['id'];}return db[_0xaf2c('0x2a')]['find']({'where':{'id':_0x166c26[_0xaf2c('0x42')]['id']}})[_0xaf2c('0x22')](handleEntityNotFound(_0x133e8c,null))['then'](saveUpdates(_0x166c26['body'],null))[_0xaf2c('0x22')](respondWithResult(_0x133e8c,null))['catch'](handleError(_0x133e8c,null));};exports[_0xaf2c('0x23')]=function(_0x23642b,_0x17b9ec){return db[_0xaf2c('0x2a')][_0xaf2c('0x45')]({'where':{'id':_0x23642b[_0xaf2c('0x42')]['id']}})[_0xaf2c('0x22')](handleEntityNotFound(_0x17b9ec,null))[_0xaf2c('0x22')](removeEntity(_0x17b9ec,null))[_0xaf2c('0x40')](handleError(_0x17b9ec,null));};exports[_0xaf2c('0x48')]=function(_0x371486,_0x5bf349){return db[_0xaf2c('0x2a')][_0xaf2c('0x48')]()['then'](respondWithResult(_0x5bf349,null))['catch'](handleError(_0x5bf349,null));};