Built motion from commit (unavailable).|2.2.5
[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 _0x0f73=['body','catch','html-pdf','eml-format','rimraf','request-promise','moment','bluebird','mustache','util','sox','lodash','squel','crypto','jsforce','to-csv','querystring','ioredis','api','../../config/utils','../../config/environment','../../mysqldb','status','end','count','offset','limit','set','Content-Range','json','apply','reject','save','update','then','destroy','sendStatus','error','stack','name','send','params','keys','MailApplication','query','filters','intersection','model','attributes','fields','length','includeAll','include','find'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x0f73,0x146));var _0x30f7=function(_0x1e31cf,_0x2d9cfd){_0x1e31cf=_0x1e31cf-0x0;var _0x1969ae=_0x0f73[_0x1e31cf];return _0x1969ae;};'use strict';var pdf=require(_0x30f7('0x0'));var emlformat=require(_0x30f7('0x1'));var rimraf=require(_0x30f7('0x2'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x30f7('0x3'));var moment=require(_0x30f7('0x4'));var BPromise=require(_0x30f7('0x5'));var Mustache=require(_0x30f7('0x6'));var util=require(_0x30f7('0x7'));var path=require('path');var sox=require(_0x30f7('0x8'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0x30f7('0x9'));var squel=require(_0x30f7('0xa'));var crypto=require(_0x30f7('0xb'));var jsforce=require(_0x30f7('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x30f7('0xd'));var querystring=require(_0x30f7('0xe'));var Papa=require('papaparse');var Redis=require(_0x30f7('0xf'));var qs=require('../../components/parsers/qs');var logger=require('../../config/logger')(_0x30f7('0x10'));var utils=require(_0x30f7('0x11'));var config=require(_0x30f7('0x12'));var db=require(_0x30f7('0x13'))['db'];function respondWithStatusCode(_0x4a8dde,_0x38bc7a){_0x38bc7a=_0x38bc7a||0xcc;return function(_0x2d36f8){if(_0x2d36f8){return _0x4a8dde['sendStatus'](_0x38bc7a);}return _0x4a8dde[_0x30f7('0x14')](_0x38bc7a)[_0x30f7('0x15')]();};}function respondWithResult(_0xb9752c,_0x5a2223){_0x5a2223=_0x5a2223||0xc8;return function(_0x1959e2){if(_0x1959e2){return _0xb9752c[_0x30f7('0x14')](_0x5a2223)['json'](_0x1959e2);}};}function respondWithFilteredResult(_0x1ad086,_0xfc31c5){return function(_0x383a7f){if(_0x383a7f){var _0x3e3c86=_0x383a7f[_0x30f7('0x16')],_0x2b5a47=_0xfc31c5[_0x30f7('0x17')],_0x579e7a=_0xfc31c5[_0x30f7('0x17')]+_0xfc31c5[_0x30f7('0x18')],_0x49fccb;if(_0x579e7a>=_0x3e3c86){_0x579e7a=_0x3e3c86;_0x49fccb=0xc8;}else{_0x49fccb=0xce;}_0x1ad086['status'](_0x49fccb);return _0x1ad086[_0x30f7('0x19')](_0x30f7('0x1a'),_0x2b5a47+'-'+_0x579e7a+'/'+_0x3e3c86)[_0x30f7('0x1b')](_0x383a7f);}return null;};}function patchUpdates(_0x1083e3){return function(_0x1e7777){try{jsonpatch[_0x30f7('0x1c')](_0x1e7777,_0x1083e3,!![]);}catch(_0x37aab2){return BPromise[_0x30f7('0x1d')](_0x37aab2);}return _0x1e7777[_0x30f7('0x1e')]();};}function saveUpdates(_0x4d2d8d,_0x293e31){return function(_0x3feee7){if(_0x3feee7){return _0x3feee7[_0x30f7('0x1f')](_0x4d2d8d)[_0x30f7('0x20')](function(_0x37d7d5){return _0x37d7d5;});}return null;};}function removeEntity(_0x3380e1,_0x5745d7){return function(_0x9dfa89){if(_0x9dfa89){return _0x9dfa89[_0x30f7('0x21')]()['then'](function(){_0x3380e1['status'](0xcc)[_0x30f7('0x15')]();});}};}function handleEntityNotFound(_0x57d2ee,_0x500b07){return function(_0x4c6009){if(!_0x4c6009){_0x57d2ee[_0x30f7('0x22')](0x194);}return _0x4c6009;};}function handleError(_0x261116,_0x4c686d){_0x4c686d=_0x4c686d||0x1f4;return function(_0x4b77ec){logger[_0x30f7('0x23')](_0x4b77ec[_0x30f7('0x24')]);if(_0x4b77ec['name']){delete _0x4b77ec[_0x30f7('0x25')];}_0x261116[_0x30f7('0x14')](_0x4c686d)[_0x30f7('0x26')](_0x4b77ec);};}exports['show']=function(_0x206583,_0x4407ed){var _0x540caf={'raw':!![],'where':{'id':_0x206583[_0x30f7('0x27')]['id']}},_0x2f6443={};_0x2f6443['model']=_[_0x30f7('0x28')](db[_0x30f7('0x29')]['rawAttributes']);_0x2f6443[_0x30f7('0x2a')]=_['keys'](_0x206583[_0x30f7('0x2a')]);_0x2f6443[_0x30f7('0x2b')]=_[_0x30f7('0x2c')](_0x2f6443[_0x30f7('0x2d')],_0x2f6443[_0x30f7('0x2a')]);_0x540caf[_0x30f7('0x2e')]=_[_0x30f7('0x2c')](_0x2f6443[_0x30f7('0x2d')],qs[_0x30f7('0x2f')](_0x206583[_0x30f7('0x2a')]['fields']));_0x540caf[_0x30f7('0x2e')]=_0x540caf['attributes'][_0x30f7('0x30')]?_0x540caf['attributes']:_0x2f6443[_0x30f7('0x2d')];if(_0x206583[_0x30f7('0x2a')][_0x30f7('0x31')]){_0x540caf[_0x30f7('0x32')]=[{'all':!![]}];}_0x540caf=_['merge']({},_0x540caf,_0x206583['options']);return db[_0x30f7('0x29')][_0x30f7('0x33')](_0x540caf)[_0x30f7('0x20')](handleEntityNotFound(_0x4407ed,null))[_0x30f7('0x20')](respondWithResult(_0x4407ed,null))['catch'](handleError(_0x4407ed,null));};exports[_0x30f7('0x1f')]=function(_0x3090dd,_0x86134c){if(_0x3090dd[_0x30f7('0x34')]['id']){delete _0x3090dd[_0x30f7('0x34')]['id'];}return db[_0x30f7('0x29')][_0x30f7('0x33')]({'where':{'id':_0x3090dd[_0x30f7('0x27')]['id']}})[_0x30f7('0x20')](handleEntityNotFound(_0x86134c,null))['then'](saveUpdates(_0x3090dd[_0x30f7('0x34')],null))[_0x30f7('0x20')](respondWithResult(_0x86134c,null))[_0x30f7('0x35')](handleError(_0x86134c,null));};exports[_0x30f7('0x21')]=function(_0x579f46,_0x9aef1e){return db[_0x30f7('0x29')][_0x30f7('0x33')]({'where':{'id':_0x579f46['params']['id']}})[_0x30f7('0x20')](handleEntityNotFound(_0x9aef1e,null))[_0x30f7('0x20')](removeEntity(_0x9aef1e,null))[_0x30f7('0x35')](handleError(_0x9aef1e,null));};