d66607d8b30bf77bba1f01e423d9058b4340acfd
[motion2.git] / server / api / mailApplication / mailApplication.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 _0x463f=['../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','set','Content-Range','apply','save','update','then','destroy','error','stack','name','send','show','params','keys','rawAttributes','query','filters','intersection','model','fields','attributes','includeAll','include','merge','options','MailApplication','catch','body','find','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','fs-extra','lodash','squel','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch'];(function(_0x586cd6,_0x3efec9){var _0x3a9533=function(_0x2b2796){while(--_0x2b2796){_0x586cd6['push'](_0x586cd6['shift']());}};_0x3a9533(++_0x3efec9);}(_0x463f,0x65));var _0xf463=function(_0x40a045,_0x516f0e){_0x40a045=_0x40a045-0x0;var _0x1a687c=_0x463f[_0x40a045];return _0x1a687c;};'use strict';var emlformat=require(_0xf463('0x0'));var rimraf=require(_0xf463('0x1'));var zipdir=require(_0xf463('0x2'));var jsonpatch=require(_0xf463('0x3'));var rp=require(_0xf463('0x4'));var moment=require(_0xf463('0x5'));var BPromise=require(_0xf463('0x6'));var Mustache=require('mustache');var util=require(_0xf463('0x7'));var path=require(_0xf463('0x8'));var sox=require(_0xf463('0x9'));var csv=require(_0xf463('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf463('0xb'));var _=require(_0xf463('0xc'));var squel=require(_0xf463('0xd'));var crypto=require('crypto');var jsforce=require(_0xf463('0xe'));var deskjs=require(_0xf463('0xf'));var toCsv=require(_0xf463('0xa'));var querystring=require(_0xf463('0x10'));var Papa=require('papaparse');var Redis=require(_0xf463('0x11'));var authService=require(_0xf463('0x12'));var qs=require(_0xf463('0x13'));var as=require(_0xf463('0x14'));var hardwareService=require(_0xf463('0x15'));var logger=require(_0xf463('0x16'))('api');var utils=require('../../config/utils');var config=require(_0xf463('0x17'));var licenseUtil=require(_0xf463('0x18'));var db=require(_0xf463('0x19'))['db'];function respondWithStatusCode(_0x411940,_0x422043){_0x422043=_0x422043||0xcc;return function(_0x5a334e){if(_0x5a334e){return _0x411940[_0xf463('0x1a')](_0x422043);}return _0x411940[_0xf463('0x1b')](_0x422043)[_0xf463('0x1c')]();};}function respondWithResult(_0x1a7c7a,_0x24e4be){_0x24e4be=_0x24e4be||0xc8;return function(_0x1b80a5){if(_0x1b80a5){return _0x1a7c7a[_0xf463('0x1b')](_0x24e4be)[_0xf463('0x1d')](_0x1b80a5);}};}function respondWithFilteredResult(_0xb6d1fa,_0x1a4048){return function(_0x4744e2){if(_0x4744e2){var _0xa7e8b8=_0x4744e2[_0xf463('0x1e')],_0x54be92=_0x1a4048['offset'],_0x41811e=_0x1a4048[_0xf463('0x1f')]+_0x1a4048['limit'],_0x149dc5;if(_0x41811e>=_0xa7e8b8){_0x41811e=_0xa7e8b8;_0x149dc5=0xc8;}else{_0x149dc5=0xce;}_0xb6d1fa[_0xf463('0x1b')](_0x149dc5);return _0xb6d1fa[_0xf463('0x20')](_0xf463('0x21'),_0x54be92+'-'+_0x41811e+'/'+_0xa7e8b8)['json'](_0x4744e2);}return null;};}function patchUpdates(_0x30d4bb){return function(_0x1be1d7){try{jsonpatch[_0xf463('0x22')](_0x1be1d7,_0x30d4bb,!![]);}catch(_0x1c1a33){return BPromise['reject'](_0x1c1a33);}return _0x1be1d7[_0xf463('0x23')]();};}function saveUpdates(_0x41f3ed,_0x22f624){return function(_0x18b539){if(_0x18b539){return _0x18b539[_0xf463('0x24')](_0x41f3ed)[_0xf463('0x25')](function(_0x137c5a){return _0x137c5a;});}return null;};}function removeEntity(_0x36d600,_0x4cef85){return function(_0x2f52fe){if(_0x2f52fe){return _0x2f52fe[_0xf463('0x26')]()[_0xf463('0x25')](function(){_0x36d600['status'](0xcc)[_0xf463('0x1c')]();});}};}function handleEntityNotFound(_0x250be3,_0x28a42d){return function(_0x1e2405){if(!_0x1e2405){_0x250be3[_0xf463('0x1a')](0x194);}return _0x1e2405;};}function handleError(_0x306f26,_0x146c6c){_0x146c6c=_0x146c6c||0x1f4;return function(_0x1fa8da){logger[_0xf463('0x27')](_0x1fa8da[_0xf463('0x28')]);if(_0x1fa8da[_0xf463('0x29')]){delete _0x1fa8da[_0xf463('0x29')];}_0x306f26['status'](_0x146c6c)[_0xf463('0x2a')](_0x1fa8da);};}exports[_0xf463('0x2b')]=function(_0x2f4cd0,_0x3d2112){var _0x4a1b1b={'raw':!![],'where':{'id':_0x2f4cd0[_0xf463('0x2c')]['id']}},_0x3776bc={};_0x3776bc['model']=_[_0xf463('0x2d')](db['MailApplication'][_0xf463('0x2e')]);_0x3776bc[_0xf463('0x2f')]=_['keys'](_0x2f4cd0[_0xf463('0x2f')]);_0x3776bc[_0xf463('0x30')]=_['intersection'](_0x3776bc['model'],_0x3776bc[_0xf463('0x2f')]);_0x4a1b1b['attributes']=_[_0xf463('0x31')](_0x3776bc[_0xf463('0x32')],qs['fields'](_0x2f4cd0[_0xf463('0x2f')][_0xf463('0x33')]));_0x4a1b1b[_0xf463('0x34')]=_0x4a1b1b[_0xf463('0x34')]['length']?_0x4a1b1b[_0xf463('0x34')]:_0x3776bc[_0xf463('0x32')];if(_0x2f4cd0[_0xf463('0x2f')][_0xf463('0x35')]){_0x4a1b1b[_0xf463('0x36')]=[{'all':!![]}];}_0x4a1b1b=_[_0xf463('0x37')]({},_0x4a1b1b,_0x2f4cd0[_0xf463('0x38')]);return db[_0xf463('0x39')]['find'](_0x4a1b1b)[_0xf463('0x25')](handleEntityNotFound(_0x3d2112,null))[_0xf463('0x25')](respondWithResult(_0x3d2112,null))[_0xf463('0x3a')](handleError(_0x3d2112,null));};exports[_0xf463('0x24')]=function(_0x757784,_0x334a38){if(_0x757784[_0xf463('0x3b')]['id']){delete _0x757784[_0xf463('0x3b')]['id'];}return db[_0xf463('0x39')]['find']({'where':{'id':_0x757784['params']['id']}})[_0xf463('0x25')](handleEntityNotFound(_0x334a38,null))[_0xf463('0x25')](saveUpdates(_0x757784['body'],null))[_0xf463('0x25')](respondWithResult(_0x334a38,null))[_0xf463('0x3a')](handleError(_0x334a38,null));};exports[_0xf463('0x26')]=function(_0xc882b8,_0x4b857c){return db[_0xf463('0x39')][_0xf463('0x3c')]({'where':{'id':_0xc882b8[_0xf463('0x2c')]['id']}})[_0xf463('0x25')](handleEntityNotFound(_0x4b857c,null))[_0xf463('0x25')](removeEntity(_0x4b857c,null))['catch'](handleError(_0x4b857c,null));};