df485635be7cb96495f695f831b0b58e1389d29f
[motion2.git] / server / api / mailSubstatus / mailSubstatus.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 _0xf5f8=['bluebird','mustache','util','path','sox','ejs','fs-extra','squel','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','sendStatus','end','json','undefined','count','limit','status','set','Content-Range','save','update','then','destroy','error','name','send','MailSubstatus','rawAttributes','fieldName','type','key','model','map','query','filters','attributes','intersection','fields','length','nolimit','offset','order','sort','where','pick','filter','merge','VIRTUAL','options','findAll','rows','show','params','keys','includeAll','include','find','create','catch','body','eml-format','rimraf','zip-dir','fast-json-patch','moment'];(function(_0x47aa64,_0xfb8a07){var _0x549c7a=function(_0x266165){while(--_0x266165){_0x47aa64['push'](_0x47aa64['shift']());}};_0x549c7a(++_0xfb8a07);}(_0xf5f8,0x1c9));var _0x8f5f=function(_0x34a071,_0x56392){_0x34a071=_0x34a071-0x0;var _0x11649b=_0xf5f8[_0x34a071];return _0x11649b;};'use strict';var emlformat=require(_0x8f5f('0x0'));var rimraf=require(_0x8f5f('0x1'));var zipdir=require(_0x8f5f('0x2'));var jsonpatch=require(_0x8f5f('0x3'));var rp=require('request-promise');var moment=require(_0x8f5f('0x4'));var BPromise=require(_0x8f5f('0x5'));var Mustache=require(_0x8f5f('0x6'));var util=require(_0x8f5f('0x7'));var path=require(_0x8f5f('0x8'));var sox=require(_0x8f5f('0x9'));var csv=require('to-csv');var ejs=require(_0x8f5f('0xa'));var fs=require('fs');var fs_extra=require(_0x8f5f('0xb'));var _=require('lodash');var squel=require(_0x8f5f('0xc'));var crypto=require('crypto');var jsforce=require(_0x8f5f('0xd'));var deskjs=require(_0x8f5f('0xe'));var toCsv=require(_0x8f5f('0xf'));var querystring=require(_0x8f5f('0x10'));var Papa=require(_0x8f5f('0x11'));var Redis=require(_0x8f5f('0x12'));var authService=require(_0x8f5f('0x13'));var qs=require(_0x8f5f('0x14'));var as=require(_0x8f5f('0x15'));var hardwareService=require(_0x8f5f('0x16'));var logger=require(_0x8f5f('0x17'))(_0x8f5f('0x18'));var utils=require(_0x8f5f('0x19'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x8f5f('0x1a'))['db'];function respondWithStatusCode(_0x1f5b31,_0x19de3f){_0x19de3f=_0x19de3f||0xcc;return function(_0x3d959e){if(_0x3d959e){return _0x1f5b31[_0x8f5f('0x1b')](_0x19de3f);}return _0x1f5b31['status'](_0x19de3f)[_0x8f5f('0x1c')]();};}function respondWithResult(_0xead25d,_0x20e8d9){_0x20e8d9=_0x20e8d9||0xc8;return function(_0x8a200b){if(_0x8a200b){return _0xead25d['status'](_0x20e8d9)[_0x8f5f('0x1d')](_0x8a200b);}};}function respondWithFilteredResult(_0x2e4bb1,_0x47fe7c){return function(_0x398a74){if(_0x398a74){var _0x187934=typeof _0x47fe7c['offset']===_0x8f5f('0x1e')&&typeof _0x47fe7c['limit']==='undefined';var _0x15727a=_0x398a74[_0x8f5f('0x1f')];var _0x3d4680=_0x187934?0x0:_0x47fe7c['offset'];var _0x2eea3e=_0x187934?_0x398a74['count']:_0x47fe7c['offset']+_0x47fe7c[_0x8f5f('0x20')];var _0x58b170;if(_0x2eea3e>=_0x15727a){_0x2eea3e=_0x15727a;_0x58b170=0xc8;}else{_0x58b170=0xce;}_0x2e4bb1[_0x8f5f('0x21')](_0x58b170);return _0x2e4bb1[_0x8f5f('0x22')](_0x8f5f('0x23'),_0x3d4680+'-'+_0x2eea3e+'/'+_0x15727a)[_0x8f5f('0x1d')](_0x398a74);}return null;};}function patchUpdates(_0x10f9cb){return function(_0x3a30ff){try{jsonpatch['apply'](_0x3a30ff,_0x10f9cb,!![]);}catch(_0x15088e){return BPromise['reject'](_0x15088e);}return _0x3a30ff[_0x8f5f('0x24')]();};}function saveUpdates(_0x151c3f,_0x22362e){return function(_0x2bcd47){if(_0x2bcd47){return _0x2bcd47[_0x8f5f('0x25')](_0x151c3f)[_0x8f5f('0x26')](function(_0x31b334){return _0x31b334;});}return null;};}function removeEntity(_0x2337b,_0x70c954){return function(_0x100c80){if(_0x100c80){return _0x100c80[_0x8f5f('0x27')]()[_0x8f5f('0x26')](function(){_0x2337b[_0x8f5f('0x21')](0xcc)['end']();});}};}function handleEntityNotFound(_0x274d74,_0x4e4bff){return function(_0xdb1730){if(!_0xdb1730){_0x274d74[_0x8f5f('0x1b')](0x194);}return _0xdb1730;};}function handleError(_0x1198cc,_0x1f2bb5){_0x1f2bb5=_0x1f2bb5||0x1f4;return function(_0x3eb487){logger[_0x8f5f('0x28')](_0x3eb487['stack']);if(_0x3eb487[_0x8f5f('0x29')]){delete _0x3eb487[_0x8f5f('0x29')];}_0x1198cc[_0x8f5f('0x21')](_0x1f2bb5)[_0x8f5f('0x2a')](_0x3eb487);};}exports['index']=function(_0x577648,_0x1c6912){var _0x5646ec={},_0x47966f={},_0x301303={'count':0x0,'rows':[]};var _0x582d0f=_['map'](db[_0x8f5f('0x2b')][_0x8f5f('0x2c')],function(_0x5eb578){return{'name':_0x5eb578[_0x8f5f('0x2d')],'type':_0x5eb578[_0x8f5f('0x2e')][_0x8f5f('0x2f')]};});_0x47966f[_0x8f5f('0x30')]=_[_0x8f5f('0x31')](_0x582d0f,_0x8f5f('0x29'));_0x47966f[_0x8f5f('0x32')]=_['keys'](_0x577648[_0x8f5f('0x32')]);_0x47966f[_0x8f5f('0x33')]=_['intersection'](_0x47966f[_0x8f5f('0x30')],_0x47966f[_0x8f5f('0x32')]);_0x5646ec[_0x8f5f('0x34')]=_[_0x8f5f('0x35')](_0x47966f[_0x8f5f('0x30')],qs[_0x8f5f('0x36')](_0x577648[_0x8f5f('0x32')]['fields']));_0x5646ec[_0x8f5f('0x34')]=_0x5646ec[_0x8f5f('0x34')][_0x8f5f('0x37')]?_0x5646ec[_0x8f5f('0x34')]:_0x47966f[_0x8f5f('0x30')];if(!_0x577648[_0x8f5f('0x32')]['hasOwnProperty'](_0x8f5f('0x38'))){_0x5646ec['limit']=qs[_0x8f5f('0x20')](_0x577648['query'][_0x8f5f('0x20')]);_0x5646ec[_0x8f5f('0x39')]=qs[_0x8f5f('0x39')](_0x577648['query'][_0x8f5f('0x39')]);}_0x5646ec[_0x8f5f('0x3a')]=qs[_0x8f5f('0x3b')](_0x577648[_0x8f5f('0x32')][_0x8f5f('0x3b')]);_0x5646ec[_0x8f5f('0x3c')]=qs[_0x8f5f('0x33')](_[_0x8f5f('0x3d')](_0x577648[_0x8f5f('0x32')],_0x47966f['filters']),_0x582d0f);if(_0x577648['query'][_0x8f5f('0x3e')]){_0x5646ec['where']=_[_0x8f5f('0x3f')](_0x5646ec[_0x8f5f('0x3c')],{'$or':_[_0x8f5f('0x31')](_0x582d0f,function(_0x8aa0fb){if(_0x8aa0fb[_0x8f5f('0x2e')]!==_0x8f5f('0x40')){var _0x55ab43={};_0x55ab43[_0x8aa0fb[_0x8f5f('0x29')]]={'$like':'%'+_0x577648[_0x8f5f('0x32')][_0x8f5f('0x3e')]+'%'};return _0x55ab43;}})});}_0x5646ec=_[_0x8f5f('0x3f')]({},_0x5646ec,_0x577648[_0x8f5f('0x41')]);var _0x5abb6f={'where':_0x5646ec[_0x8f5f('0x3c')]};return db[_0x8f5f('0x2b')][_0x8f5f('0x1f')](_0x5abb6f)['then'](function(_0x3fa9c9){_0x301303[_0x8f5f('0x1f')]=_0x3fa9c9;if(_0x577648[_0x8f5f('0x32')]['includeAll']){_0x5646ec['include']=[{'all':!![]}];}return db[_0x8f5f('0x2b')][_0x8f5f('0x42')](_0x5646ec);})[_0x8f5f('0x26')](function(_0x536345){_0x301303[_0x8f5f('0x43')]=_0x536345;return _0x301303;})[_0x8f5f('0x26')](respondWithFilteredResult(_0x1c6912,_0x5646ec))['catch'](handleError(_0x1c6912,null));};exports[_0x8f5f('0x44')]=function(_0x922119,_0x1240a1){var _0x5ce421={'raw':!![],'where':{'id':_0x922119[_0x8f5f('0x45')]['id']}},_0x404c70={};_0x404c70[_0x8f5f('0x30')]=_[_0x8f5f('0x46')](db[_0x8f5f('0x2b')][_0x8f5f('0x2c')]);_0x404c70[_0x8f5f('0x32')]=_[_0x8f5f('0x46')](_0x922119[_0x8f5f('0x32')]);_0x404c70[_0x8f5f('0x33')]=_[_0x8f5f('0x35')](_0x404c70['model'],_0x404c70[_0x8f5f('0x32')]);_0x5ce421[_0x8f5f('0x34')]=_[_0x8f5f('0x35')](_0x404c70[_0x8f5f('0x30')],qs[_0x8f5f('0x36')](_0x922119['query'][_0x8f5f('0x36')]));_0x5ce421[_0x8f5f('0x34')]=_0x5ce421['attributes'][_0x8f5f('0x37')]?_0x5ce421['attributes']:_0x404c70['model'];if(_0x922119['query'][_0x8f5f('0x47')]){_0x5ce421[_0x8f5f('0x48')]=[{'all':!![]}];}_0x5ce421=_[_0x8f5f('0x3f')]({},_0x5ce421,_0x922119[_0x8f5f('0x41')]);return db['MailSubstatus'][_0x8f5f('0x49')](_0x5ce421)['then'](handleEntityNotFound(_0x1240a1,null))['then'](respondWithResult(_0x1240a1,null))['catch'](handleError(_0x1240a1,null));};exports[_0x8f5f('0x4a')]=function(_0x33d20e,_0x11d575){return db['MailSubstatus'][_0x8f5f('0x4a')](_0x33d20e['body'],{})[_0x8f5f('0x26')](respondWithResult(_0x11d575,0xc9))[_0x8f5f('0x4b')](handleError(_0x11d575,null));};exports['update']=function(_0x5ab6d7,_0xd093d2){if(_0x5ab6d7['body']['id']){delete _0x5ab6d7[_0x8f5f('0x4c')]['id'];}return db[_0x8f5f('0x2b')][_0x8f5f('0x49')]({'where':{'id':_0x5ab6d7[_0x8f5f('0x45')]['id']}})[_0x8f5f('0x26')](handleEntityNotFound(_0xd093d2,null))[_0x8f5f('0x26')](saveUpdates(_0x5ab6d7[_0x8f5f('0x4c')],null))[_0x8f5f('0x26')](respondWithResult(_0xd093d2,null))[_0x8f5f('0x4b')](handleError(_0xd093d2,null));};exports[_0x8f5f('0x27')]=function(_0x443ca1,_0x9a107d){return db['MailSubstatus']['find']({'where':{'id':_0x443ca1[_0x8f5f('0x45')]['id']}})[_0x8f5f('0x26')](handleEntityNotFound(_0x9a107d,null))['then'](removeEntity(_0x9a107d,null))[_0x8f5f('0x4b')](handleError(_0x9a107d,null));};exports['describe']=function(_0x53ed2c,_0x1ad571){return db[_0x8f5f('0x2b')]['describe']()[_0x8f5f('0x26')](respondWithResult(_0x1ad571,null))['catch'](handleError(_0x1ad571,null));};