Built motion from commit (unavailable).|2.5.26
[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 _0xaf7b=['describe','rimraf','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','jsforce','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/license/util','../../mysqldb','sendStatus','status','offset','limit','json','reject','save','then','end','error','name','send','index','map','rawAttributes','fieldName','key','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','filter','MailSubstatus','count','includeAll','include','findAll','catch','show','params','options','create','body','update','find'];(function(_0x4cb5a8,_0x3a517a){var _0x447cdd=function(_0x191531){while(--_0x191531){_0x4cb5a8['push'](_0x4cb5a8['shift']());}};_0x447cdd(++_0x3a517a);}(_0xaf7b,0x101));var _0xbaf7=function(_0x2dafbe,_0x5d04de){_0x2dafbe=_0x2dafbe-0x0;var _0x58a45a=_0xaf7b[_0x2dafbe];return _0x58a45a;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xbaf7('0x0'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xbaf7('0x1'));var BPromise=require(_0xbaf7('0x2'));var Mustache=require(_0xbaf7('0x3'));var util=require('util');var path=require(_0xbaf7('0x4'));var sox=require(_0xbaf7('0x5'));var csv=require(_0xbaf7('0x6'));var ejs=require(_0xbaf7('0x7'));var fs=require('fs');var fs_extra=require(_0xbaf7('0x8'));var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xbaf7('0x9'));var deskjs=require('desk.js');var toCsv=require(_0xbaf7('0x6'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xbaf7('0xa'));var qs=require(_0xbaf7('0xb'));var as=require(_0xbaf7('0xc'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xbaf7('0xd'))(_0xbaf7('0xe'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0xbaf7('0xf'));var db=require(_0xbaf7('0x10'))['db'];function respondWithStatusCode(_0x1d264e,_0x437a0e){_0x437a0e=_0x437a0e||0xcc;return function(_0x149ae3){if(_0x149ae3){return _0x1d264e[_0xbaf7('0x11')](_0x437a0e);}return _0x1d264e[_0xbaf7('0x12')](_0x437a0e)['end']();};}function respondWithResult(_0x55417c,_0x15be89){_0x15be89=_0x15be89||0xc8;return function(_0x89d295){if(_0x89d295){return _0x55417c[_0xbaf7('0x12')](_0x15be89)['json'](_0x89d295);}};}function respondWithFilteredResult(_0x46b2a3,_0x30592f){return function(_0x28c2e6){if(_0x28c2e6){var _0x4ee2bd=_0x28c2e6['count'],_0x28b3bb=_0x30592f['offset'],_0x36b89f=_0x30592f[_0xbaf7('0x13')]+_0x30592f[_0xbaf7('0x14')],_0x4293e6;if(_0x36b89f>=_0x4ee2bd){_0x36b89f=_0x4ee2bd;_0x4293e6=0xc8;}else{_0x4293e6=0xce;}_0x46b2a3[_0xbaf7('0x12')](_0x4293e6);return _0x46b2a3['set']('Content-Range',_0x28b3bb+'-'+_0x36b89f+'/'+_0x4ee2bd)[_0xbaf7('0x15')](_0x28c2e6);}return null;};}function patchUpdates(_0x437d22){return function(_0x5259fd){try{jsonpatch['apply'](_0x5259fd,_0x437d22,!![]);}catch(_0x4b1aff){return BPromise[_0xbaf7('0x16')](_0x4b1aff);}return _0x5259fd[_0xbaf7('0x17')]();};}function saveUpdates(_0x5a179b,_0x103c21){return function(_0x4ed4dc){if(_0x4ed4dc){return _0x4ed4dc['update'](_0x5a179b)[_0xbaf7('0x18')](function(_0x2670d3){return _0x2670d3;});}return null;};}function removeEntity(_0x4477de,_0x1edf93){return function(_0x5167ce){if(_0x5167ce){return _0x5167ce['destroy']()['then'](function(){_0x4477de[_0xbaf7('0x12')](0xcc)[_0xbaf7('0x19')]();});}};}function handleEntityNotFound(_0x13d57b,_0x40f6f2){return function(_0x73e72a){if(!_0x73e72a){_0x13d57b['sendStatus'](0x194);}return _0x73e72a;};}function handleError(_0x571583,_0x3ebeaf){_0x3ebeaf=_0x3ebeaf||0x1f4;return function(_0x262f2a){logger[_0xbaf7('0x1a')](_0x262f2a['stack']);if(_0x262f2a[_0xbaf7('0x1b')]){delete _0x262f2a[_0xbaf7('0x1b')];}_0x571583[_0xbaf7('0x12')](_0x3ebeaf)[_0xbaf7('0x1c')](_0x262f2a);};}exports[_0xbaf7('0x1d')]=function(_0x59e8d8,_0x3c78f2){var _0x59fdea={},_0xe811fb={},_0x567666={'count':0x0,'rows':[]};var _0x35e980=_[_0xbaf7('0x1e')](db['MailSubstatus'][_0xbaf7('0x1f')],function(_0x2efed9){return{'name':_0x2efed9[_0xbaf7('0x20')],'type':_0x2efed9['type'][_0xbaf7('0x21')]};});_0xe811fb['model']=_[_0xbaf7('0x1e')](_0x35e980,_0xbaf7('0x1b'));_0xe811fb[_0xbaf7('0x22')]=_[_0xbaf7('0x23')](_0x59e8d8[_0xbaf7('0x22')]);_0xe811fb[_0xbaf7('0x24')]=_[_0xbaf7('0x25')](_0xe811fb[_0xbaf7('0x26')],_0xe811fb[_0xbaf7('0x22')]);_0x59fdea[_0xbaf7('0x27')]=_['intersection'](_0xe811fb['model'],qs[_0xbaf7('0x28')](_0x59e8d8[_0xbaf7('0x22')][_0xbaf7('0x28')]));_0x59fdea['attributes']=_0x59fdea[_0xbaf7('0x27')][_0xbaf7('0x29')]?_0x59fdea['attributes']:_0xe811fb['model'];if(!_0x59e8d8[_0xbaf7('0x22')][_0xbaf7('0x2a')](_0xbaf7('0x2b'))){_0x59fdea[_0xbaf7('0x14')]=qs[_0xbaf7('0x14')](_0x59e8d8[_0xbaf7('0x22')][_0xbaf7('0x14')]);_0x59fdea[_0xbaf7('0x13')]=qs['offset'](_0x59e8d8[_0xbaf7('0x22')][_0xbaf7('0x13')]);}_0x59fdea[_0xbaf7('0x2c')]=qs[_0xbaf7('0x2d')](_0x59e8d8[_0xbaf7('0x22')]['sort']);_0x59fdea[_0xbaf7('0x2e')]=qs[_0xbaf7('0x24')](_[_0xbaf7('0x2f')](_0x59e8d8[_0xbaf7('0x22')],_0xe811fb[_0xbaf7('0x24')]),_0x35e980);if(_0x59e8d8[_0xbaf7('0x22')]['filter']){_0x59fdea['where']=_[_0xbaf7('0x30')](_0x59fdea[_0xbaf7('0x2e')],{'$or':_['map'](_0x35e980,function(_0x4b0cb3){if(_0x4b0cb3['type']!=='VIRTUAL'){var _0x3f83bb={};_0x3f83bb[_0x4b0cb3[_0xbaf7('0x1b')]]={'$like':'%'+_0x59e8d8[_0xbaf7('0x22')][_0xbaf7('0x31')]+'%'};return _0x3f83bb;}})});}_0x59fdea=_[_0xbaf7('0x30')]({},_0x59fdea,_0x59e8d8['options']);var _0x3f3091={'where':_0x59fdea[_0xbaf7('0x2e')]};return db[_0xbaf7('0x32')][_0xbaf7('0x33')](_0x3f3091)['then'](function(_0x575cc6){_0x567666[_0xbaf7('0x33')]=_0x575cc6;if(_0x59e8d8[_0xbaf7('0x22')][_0xbaf7('0x34')]){_0x59fdea[_0xbaf7('0x35')]=[{'all':!![]}];}return db['MailSubstatus'][_0xbaf7('0x36')](_0x59fdea);})[_0xbaf7('0x18')](function(_0x1cb6e4){_0x567666['rows']=_0x1cb6e4;return _0x567666;})[_0xbaf7('0x18')](respondWithFilteredResult(_0x3c78f2,_0x59fdea))[_0xbaf7('0x37')](handleError(_0x3c78f2,null));};exports[_0xbaf7('0x38')]=function(_0x368e24,_0x3dbff1){var _0x3b1b80={'raw':!![],'where':{'id':_0x368e24[_0xbaf7('0x39')]['id']}},_0x5d0934={};_0x5d0934['model']=_[_0xbaf7('0x23')](db[_0xbaf7('0x32')]['rawAttributes']);_0x5d0934[_0xbaf7('0x22')]=_['keys'](_0x368e24['query']);_0x5d0934[_0xbaf7('0x24')]=_['intersection'](_0x5d0934[_0xbaf7('0x26')],_0x5d0934['query']);_0x3b1b80[_0xbaf7('0x27')]=_[_0xbaf7('0x25')](_0x5d0934[_0xbaf7('0x26')],qs[_0xbaf7('0x28')](_0x368e24['query'][_0xbaf7('0x28')]));_0x3b1b80[_0xbaf7('0x27')]=_0x3b1b80[_0xbaf7('0x27')][_0xbaf7('0x29')]?_0x3b1b80[_0xbaf7('0x27')]:_0x5d0934['model'];if(_0x368e24[_0xbaf7('0x22')][_0xbaf7('0x34')]){_0x3b1b80[_0xbaf7('0x35')]=[{'all':!![]}];}_0x3b1b80=_[_0xbaf7('0x30')]({},_0x3b1b80,_0x368e24[_0xbaf7('0x3a')]);return db[_0xbaf7('0x32')]['find'](_0x3b1b80)[_0xbaf7('0x18')](handleEntityNotFound(_0x3dbff1,null))[_0xbaf7('0x18')](respondWithResult(_0x3dbff1,null))[_0xbaf7('0x37')](handleError(_0x3dbff1,null));};exports['create']=function(_0x56d226,_0x35be5a){return db['MailSubstatus'][_0xbaf7('0x3b')](_0x56d226[_0xbaf7('0x3c')],{})[_0xbaf7('0x18')](respondWithResult(_0x35be5a,0xc9))[_0xbaf7('0x37')](handleError(_0x35be5a,null));};exports[_0xbaf7('0x3d')]=function(_0x29704c,_0x15cbfe){if(_0x29704c[_0xbaf7('0x3c')]['id']){delete _0x29704c[_0xbaf7('0x3c')]['id'];}return db[_0xbaf7('0x32')][_0xbaf7('0x3e')]({'where':{'id':_0x29704c['params']['id']}})[_0xbaf7('0x18')](handleEntityNotFound(_0x15cbfe,null))[_0xbaf7('0x18')](saveUpdates(_0x29704c[_0xbaf7('0x3c')],null))[_0xbaf7('0x18')](respondWithResult(_0x15cbfe,null))[_0xbaf7('0x37')](handleError(_0x15cbfe,null));};exports['destroy']=function(_0x984b7e,_0x3525e7){return db[_0xbaf7('0x32')]['find']({'where':{'id':_0x984b7e['params']['id']}})['then'](handleEntityNotFound(_0x3525e7,null))[_0xbaf7('0x18')](removeEntity(_0x3525e7,null))[_0xbaf7('0x37')](handleError(_0x3525e7,null));};exports[_0xbaf7('0x3f')]=function(_0x5abd9f,_0x31377f){return db[_0xbaf7('0x32')][_0xbaf7('0x3f')]()[_0xbaf7('0x18')](respondWithResult(_0x31377f,null))[_0xbaf7('0x37')](handleError(_0x31377f,null));};