Built motion from commit 753c950e.|2.5.42
[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 _0xf817=['ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','json','undefined','limit','offset','count','Content-Range','apply','reject','save','update','then','destroy','end','stack','name','send','map','MailSubstatus','rawAttributes','fieldName','type','model','query','filters','intersection','fields','attributes','length','nolimit','order','sort','filter','VIRTUAL','merge','options','where','includeAll','include','rows','show','keys','catch','create','body','params','find','describe','eml-format','zip-dir','fast-json-patch','request-promise','moment','mustache','util','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse'];(function(_0x18a79d,_0x57bd2c){var _0x4f8848=function(_0x28af80){while(--_0x28af80){_0x18a79d['push'](_0x18a79d['shift']());}};_0x4f8848(++_0x57bd2c);}(_0xf817,0x161));var _0x7f81=function(_0x22bad0,_0x5c8d63){_0x22bad0=_0x22bad0-0x0;var _0x305748=_0xf817[_0x22bad0];return _0x305748;};'use strict';var emlformat=require(_0x7f81('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x7f81('0x1'));var jsonpatch=require(_0x7f81('0x2'));var rp=require(_0x7f81('0x3'));var moment=require(_0x7f81('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x7f81('0x5'));var util=require(_0x7f81('0x6'));var path=require('path');var sox=require(_0x7f81('0x7'));var csv=require('to-csv');var ejs=require(_0x7f81('0x8'));var fs=require('fs');var fs_extra=require(_0x7f81('0x9'));var _=require(_0x7f81('0xa'));var squel=require(_0x7f81('0xb'));var crypto=require(_0x7f81('0xc'));var jsforce=require(_0x7f81('0xd'));var deskjs=require(_0x7f81('0xe'));var toCsv=require('to-csv');var querystring=require(_0x7f81('0xf'));var Papa=require(_0x7f81('0x10'));var Redis=require(_0x7f81('0x11'));var authService=require(_0x7f81('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x7f81('0x13'));var hardwareService=require(_0x7f81('0x14'));var logger=require(_0x7f81('0x15'))('api');var utils=require(_0x7f81('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0x7f81('0x17'));var db=require(_0x7f81('0x18'))['db'];function respondWithStatusCode(_0x257839,_0x34abce){_0x34abce=_0x34abce||0xcc;return function(_0x3030c2){if(_0x3030c2){return _0x257839[_0x7f81('0x19')](_0x34abce);}return _0x257839[_0x7f81('0x1a')](_0x34abce)['end']();};}function respondWithResult(_0x228954,_0x414c50){_0x414c50=_0x414c50||0xc8;return function(_0x54391e){if(_0x54391e){return _0x228954[_0x7f81('0x1a')](_0x414c50)[_0x7f81('0x1b')](_0x54391e);}};}function respondWithFilteredResult(_0x370309,_0x599c2a){return function(_0x371c27){if(_0x371c27){var _0x1f6d42=typeof _0x599c2a['offset']===_0x7f81('0x1c')&&typeof _0x599c2a[_0x7f81('0x1d')]==='undefined';var _0x1f6886=_0x371c27['count'];var _0x5b3deb=_0x1f6d42?0x0:_0x599c2a[_0x7f81('0x1e')];var _0x70b6e0=_0x1f6d42?_0x371c27[_0x7f81('0x1f')]:_0x599c2a[_0x7f81('0x1e')]+_0x599c2a[_0x7f81('0x1d')];var _0x59de17;if(_0x70b6e0>=_0x1f6886){_0x70b6e0=_0x1f6886;_0x59de17=0xc8;}else{_0x59de17=0xce;}_0x370309[_0x7f81('0x1a')](_0x59de17);return _0x370309['set'](_0x7f81('0x20'),_0x5b3deb+'-'+_0x70b6e0+'/'+_0x1f6886)['json'](_0x371c27);}return null;};}function patchUpdates(_0x327374){return function(_0x2b0119){try{jsonpatch[_0x7f81('0x21')](_0x2b0119,_0x327374,!![]);}catch(_0x1b0fc0){return BPromise[_0x7f81('0x22')](_0x1b0fc0);}return _0x2b0119[_0x7f81('0x23')]();};}function saveUpdates(_0x5110d7,_0x47afb5){return function(_0x64880f){if(_0x64880f){return _0x64880f[_0x7f81('0x24')](_0x5110d7)[_0x7f81('0x25')](function(_0x3b0154){return _0x3b0154;});}return null;};}function removeEntity(_0x3790ad,_0x6cdaac){return function(_0x3f268f){if(_0x3f268f){return _0x3f268f[_0x7f81('0x26')]()[_0x7f81('0x25')](function(){_0x3790ad[_0x7f81('0x1a')](0xcc)[_0x7f81('0x27')]();});}};}function handleEntityNotFound(_0x24d1c7,_0x36d826){return function(_0x309b67){if(!_0x309b67){_0x24d1c7[_0x7f81('0x19')](0x194);}return _0x309b67;};}function handleError(_0x515c99,_0x5d95bd){_0x5d95bd=_0x5d95bd||0x1f4;return function(_0x1eb9f6){logger['error'](_0x1eb9f6[_0x7f81('0x28')]);if(_0x1eb9f6[_0x7f81('0x29')]){delete _0x1eb9f6[_0x7f81('0x29')];}_0x515c99['status'](_0x5d95bd)[_0x7f81('0x2a')](_0x1eb9f6);};}exports['index']=function(_0x31dda0,_0x25d2aa){var _0x22712a={},_0x6732a4={},_0x2f7266={'count':0x0,'rows':[]};var _0x4139c4=_[_0x7f81('0x2b')](db[_0x7f81('0x2c')][_0x7f81('0x2d')],function(_0x32d8ee){return{'name':_0x32d8ee[_0x7f81('0x2e')],'type':_0x32d8ee[_0x7f81('0x2f')]['key']};});_0x6732a4[_0x7f81('0x30')]=_[_0x7f81('0x2b')](_0x4139c4,_0x7f81('0x29'));_0x6732a4[_0x7f81('0x31')]=_['keys'](_0x31dda0['query']);_0x6732a4[_0x7f81('0x32')]=_[_0x7f81('0x33')](_0x6732a4['model'],_0x6732a4[_0x7f81('0x31')]);_0x22712a['attributes']=_[_0x7f81('0x33')](_0x6732a4[_0x7f81('0x30')],qs[_0x7f81('0x34')](_0x31dda0[_0x7f81('0x31')][_0x7f81('0x34')]));_0x22712a[_0x7f81('0x35')]=_0x22712a['attributes'][_0x7f81('0x36')]?_0x22712a[_0x7f81('0x35')]:_0x6732a4['model'];if(!_0x31dda0[_0x7f81('0x31')]['hasOwnProperty'](_0x7f81('0x37'))){_0x22712a['limit']=qs['limit'](_0x31dda0[_0x7f81('0x31')][_0x7f81('0x1d')]);_0x22712a[_0x7f81('0x1e')]=qs[_0x7f81('0x1e')](_0x31dda0[_0x7f81('0x31')][_0x7f81('0x1e')]);}_0x22712a[_0x7f81('0x38')]=qs[_0x7f81('0x39')](_0x31dda0[_0x7f81('0x31')][_0x7f81('0x39')]);_0x22712a['where']=qs['filters'](_['pick'](_0x31dda0[_0x7f81('0x31')],_0x6732a4['filters']),_0x4139c4);if(_0x31dda0[_0x7f81('0x31')][_0x7f81('0x3a')]){_0x22712a['where']=_['merge'](_0x22712a['where'],{'$or':_[_0x7f81('0x2b')](_0x4139c4,function(_0x4ea8de){if(_0x4ea8de['type']!==_0x7f81('0x3b')){var _0x9e9ab9={};_0x9e9ab9[_0x4ea8de['name']]={'$like':'%'+_0x31dda0['query'][_0x7f81('0x3a')]+'%'};return _0x9e9ab9;}})});}_0x22712a=_[_0x7f81('0x3c')]({},_0x22712a,_0x31dda0[_0x7f81('0x3d')]);var _0x3922be={'where':_0x22712a[_0x7f81('0x3e')]};return db[_0x7f81('0x2c')][_0x7f81('0x1f')](_0x3922be)[_0x7f81('0x25')](function(_0x2c1708){_0x2f7266[_0x7f81('0x1f')]=_0x2c1708;if(_0x31dda0[_0x7f81('0x31')][_0x7f81('0x3f')]){_0x22712a[_0x7f81('0x40')]=[{'all':!![]}];}return db['MailSubstatus']['findAll'](_0x22712a);})[_0x7f81('0x25')](function(_0x374211){_0x2f7266[_0x7f81('0x41')]=_0x374211;return _0x2f7266;})[_0x7f81('0x25')](respondWithFilteredResult(_0x25d2aa,_0x22712a))['catch'](handleError(_0x25d2aa,null));};exports[_0x7f81('0x42')]=function(_0x244156,_0x321640){var _0x5b4de1={'raw':!![],'where':{'id':_0x244156['params']['id']}},_0x979737={};_0x979737[_0x7f81('0x30')]=_['keys'](db['MailSubstatus'][_0x7f81('0x2d')]);_0x979737['query']=_[_0x7f81('0x43')](_0x244156[_0x7f81('0x31')]);_0x979737['filters']=_[_0x7f81('0x33')](_0x979737['model'],_0x979737[_0x7f81('0x31')]);_0x5b4de1[_0x7f81('0x35')]=_[_0x7f81('0x33')](_0x979737[_0x7f81('0x30')],qs[_0x7f81('0x34')](_0x244156[_0x7f81('0x31')][_0x7f81('0x34')]));_0x5b4de1[_0x7f81('0x35')]=_0x5b4de1[_0x7f81('0x35')][_0x7f81('0x36')]?_0x5b4de1['attributes']:_0x979737[_0x7f81('0x30')];if(_0x244156[_0x7f81('0x31')][_0x7f81('0x3f')]){_0x5b4de1['include']=[{'all':!![]}];}_0x5b4de1=_[_0x7f81('0x3c')]({},_0x5b4de1,_0x244156['options']);return db[_0x7f81('0x2c')]['find'](_0x5b4de1)[_0x7f81('0x25')](handleEntityNotFound(_0x321640,null))[_0x7f81('0x25')](respondWithResult(_0x321640,null))[_0x7f81('0x44')](handleError(_0x321640,null));};exports[_0x7f81('0x45')]=function(_0xf4236,_0x501fcd){return db[_0x7f81('0x2c')][_0x7f81('0x45')](_0xf4236[_0x7f81('0x46')],{})[_0x7f81('0x25')](respondWithResult(_0x501fcd,0xc9))[_0x7f81('0x44')](handleError(_0x501fcd,null));};exports[_0x7f81('0x24')]=function(_0x3a0b4c,_0x5a6a48){if(_0x3a0b4c[_0x7f81('0x46')]['id']){delete _0x3a0b4c['body']['id'];}return db[_0x7f81('0x2c')]['find']({'where':{'id':_0x3a0b4c[_0x7f81('0x47')]['id']}})['then'](handleEntityNotFound(_0x5a6a48,null))[_0x7f81('0x25')](saveUpdates(_0x3a0b4c[_0x7f81('0x46')],null))['then'](respondWithResult(_0x5a6a48,null))[_0x7f81('0x44')](handleError(_0x5a6a48,null));};exports['destroy']=function(_0xd74bb2,_0x33a8ec){return db[_0x7f81('0x2c')][_0x7f81('0x48')]({'where':{'id':_0xd74bb2[_0x7f81('0x47')]['id']}})['then'](handleEntityNotFound(_0x33a8ec,null))[_0x7f81('0x25')](removeEntity(_0x33a8ec,null))[_0x7f81('0x44')](handleError(_0x33a8ec,null));};exports[_0x7f81('0x49')]=function(_0x4b4e59,_0x1cb2e3){return db['MailSubstatus'][_0x7f81('0x49')]()['then'](respondWithResult(_0x1cb2e3,null))[_0x7f81('0x44')](handleError(_0x1cb2e3,null));};