e6fd9401e33295b6057370fb070e22c4a7684a85
[motion2.git] / server / api / openchannelApplication / openchannelApplication.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 _0x3fff=['zip-dir','fast-json-patch','bluebird','mustache','path','sox','to-csv','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','limit','count','offset','set','Content-Range','apply','reject','save','then','error','stack','name','OpenchannelApplication','fieldName','type','key','map','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','include','findAll','rows','catch','params','find','create','update','destroy','eml-format','rimraf'];(function(_0x1e47c8,_0x161337){var _0xe1a2f3=function(_0x319fa3){while(--_0x319fa3){_0x1e47c8['push'](_0x1e47c8['shift']());}};_0xe1a2f3(++_0x161337);}(_0x3fff,0x12e));var _0xf3ff=function(_0x2758f8,_0x49a1ee){_0x2758f8=_0x2758f8-0x0;var _0x1ef670=_0x3fff[_0x2758f8];return _0x1ef670;};'use strict';var emlformat=require(_0xf3ff('0x0'));var rimraf=require(_0xf3ff('0x1'));var zipdir=require(_0xf3ff('0x2'));var jsonpatch=require(_0xf3ff('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xf3ff('0x4'));var Mustache=require(_0xf3ff('0x5'));var util=require('util');var path=require(_0xf3ff('0x6'));var sox=require(_0xf3ff('0x7'));var csv=require(_0xf3ff('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf3ff('0x9'));var _=require(_0xf3ff('0xa'));var squel=require(_0xf3ff('0xb'));var crypto=require(_0xf3ff('0xc'));var jsforce=require('jsforce');var deskjs=require(_0xf3ff('0xd'));var toCsv=require(_0xf3ff('0x8'));var querystring=require(_0xf3ff('0xe'));var Papa=require(_0xf3ff('0xf'));var Redis=require(_0xf3ff('0x10'));var authService=require(_0xf3ff('0x11'));var qs=require(_0xf3ff('0x12'));var as=require(_0xf3ff('0x13'));var hardwareService=require(_0xf3ff('0x14'));var logger=require(_0xf3ff('0x15'))(_0xf3ff('0x16'));var utils=require(_0xf3ff('0x17'));var config=require(_0xf3ff('0x18'));var licenseUtil=require(_0xf3ff('0x19'));var db=require(_0xf3ff('0x1a'))['db'];function respondWithStatusCode(_0x1ccbbb,_0x5e7ab3){_0x5e7ab3=_0x5e7ab3||0xcc;return function(_0x20fabc){if(_0x20fabc){return _0x1ccbbb[_0xf3ff('0x1b')](_0x5e7ab3);}return _0x1ccbbb[_0xf3ff('0x1c')](_0x5e7ab3)[_0xf3ff('0x1d')]();};}function respondWithResult(_0x4c4014,_0x1120b6){_0x1120b6=_0x1120b6||0xc8;return function(_0x508733){if(_0x508733){return _0x4c4014[_0xf3ff('0x1c')](_0x1120b6)[_0xf3ff('0x1e')](_0x508733);}};}function respondWithFilteredResult(_0x1e6a30,_0x45fa05){return function(_0x233312){if(_0x233312){var _0x226612=typeof _0x45fa05['offset']===_0xf3ff('0x1f')&&typeof _0x45fa05[_0xf3ff('0x20')]==='undefined';var _0x2b99c3=_0x233312[_0xf3ff('0x21')];var _0x56f4a6=_0x226612?0x0:_0x45fa05[_0xf3ff('0x22')];var _0x974fa6=_0x226612?_0x233312[_0xf3ff('0x21')]:_0x45fa05[_0xf3ff('0x22')]+_0x45fa05[_0xf3ff('0x20')];var _0x58b99b;if(_0x974fa6>=_0x2b99c3){_0x974fa6=_0x2b99c3;_0x58b99b=0xc8;}else{_0x58b99b=0xce;}_0x1e6a30['status'](_0x58b99b);return _0x1e6a30[_0xf3ff('0x23')](_0xf3ff('0x24'),_0x56f4a6+'-'+_0x974fa6+'/'+_0x2b99c3)[_0xf3ff('0x1e')](_0x233312);}return null;};}function patchUpdates(_0x2ad2cf){return function(_0x1fdf07){try{jsonpatch[_0xf3ff('0x25')](_0x1fdf07,_0x2ad2cf,!![]);}catch(_0x2efa0f){return BPromise[_0xf3ff('0x26')](_0x2efa0f);}return _0x1fdf07[_0xf3ff('0x27')]();};}function saveUpdates(_0x751a95,_0x127a7a){return function(_0x55ea0d){if(_0x55ea0d){return _0x55ea0d['update'](_0x751a95)[_0xf3ff('0x28')](function(_0x497a7c){return _0x497a7c;});}return null;};}function removeEntity(_0x4550f7,_0x105187){return function(_0x502aa3){if(_0x502aa3){return _0x502aa3['destroy']()[_0xf3ff('0x28')](function(){_0x4550f7[_0xf3ff('0x1c')](0xcc)[_0xf3ff('0x1d')]();});}};}function handleEntityNotFound(_0x2ffdcd,_0x302c0e){return function(_0xd2fc04){if(!_0xd2fc04){_0x2ffdcd[_0xf3ff('0x1b')](0x194);}return _0xd2fc04;};}function handleError(_0x22a103,_0x5626e5){_0x5626e5=_0x5626e5||0x1f4;return function(_0x4d2d55){logger[_0xf3ff('0x29')](_0x4d2d55[_0xf3ff('0x2a')]);if(_0x4d2d55[_0xf3ff('0x2b')]){delete _0x4d2d55[_0xf3ff('0x2b')];}_0x22a103[_0xf3ff('0x1c')](_0x5626e5)['send'](_0x4d2d55);};}exports['index']=function(_0x2bf763,_0x38c1a4){var _0x2059e0={},_0x1a7c62={},_0x2c60cc={'count':0x0,'rows':[]};var _0x2ea63e=_['map'](db[_0xf3ff('0x2c')]['rawAttributes'],function(_0x289e28){return{'name':_0x289e28[_0xf3ff('0x2d')],'type':_0x289e28[_0xf3ff('0x2e')][_0xf3ff('0x2f')]};});_0x1a7c62['model']=_[_0xf3ff('0x30')](_0x2ea63e,_0xf3ff('0x2b'));_0x1a7c62[_0xf3ff('0x31')]=_[_0xf3ff('0x32')](_0x2bf763[_0xf3ff('0x31')]);_0x1a7c62[_0xf3ff('0x33')]=_[_0xf3ff('0x34')](_0x1a7c62[_0xf3ff('0x35')],_0x1a7c62[_0xf3ff('0x31')]);_0x2059e0[_0xf3ff('0x36')]=_[_0xf3ff('0x34')](_0x1a7c62[_0xf3ff('0x35')],qs[_0xf3ff('0x37')](_0x2bf763['query'][_0xf3ff('0x37')]));_0x2059e0[_0xf3ff('0x36')]=_0x2059e0[_0xf3ff('0x36')][_0xf3ff('0x38')]?_0x2059e0[_0xf3ff('0x36')]:_0x1a7c62[_0xf3ff('0x35')];if(!_0x2bf763['query'][_0xf3ff('0x39')](_0xf3ff('0x3a'))){_0x2059e0[_0xf3ff('0x20')]=qs['limit'](_0x2bf763[_0xf3ff('0x31')]['limit']);_0x2059e0[_0xf3ff('0x22')]=qs['offset'](_0x2bf763['query'][_0xf3ff('0x22')]);}_0x2059e0[_0xf3ff('0x3b')]=qs[_0xf3ff('0x3c')](_0x2bf763[_0xf3ff('0x31')][_0xf3ff('0x3c')]);_0x2059e0[_0xf3ff('0x3d')]=qs['filters'](_[_0xf3ff('0x3e')](_0x2bf763[_0xf3ff('0x31')],_0x1a7c62[_0xf3ff('0x33')]),_0x2ea63e);if(_0x2bf763[_0xf3ff('0x31')][_0xf3ff('0x3f')]){_0x2059e0[_0xf3ff('0x3d')]=_[_0xf3ff('0x40')](_0x2059e0[_0xf3ff('0x3d')],{'$or':_['map'](_0x2ea63e,function(_0x10da24){if(_0x10da24[_0xf3ff('0x2e')]!==_0xf3ff('0x41')){var _0x2582f2={};_0x2582f2[_0x10da24[_0xf3ff('0x2b')]]={'$like':'%'+_0x2bf763['query'][_0xf3ff('0x3f')]+'%'};return _0x2582f2;}})});}_0x2059e0=_[_0xf3ff('0x40')]({},_0x2059e0,_0x2bf763[_0xf3ff('0x42')]);var _0x52134f={'where':_0x2059e0[_0xf3ff('0x3d')]};return db['OpenchannelApplication']['count'](_0x52134f)[_0xf3ff('0x28')](function(_0x1f7c5c){_0x2c60cc['count']=_0x1f7c5c;if(_0x2bf763[_0xf3ff('0x31')]['includeAll']){_0x2059e0[_0xf3ff('0x43')]=[{'all':!![]}];}return db[_0xf3ff('0x2c')][_0xf3ff('0x44')](_0x2059e0);})['then'](function(_0x346312){_0x2c60cc[_0xf3ff('0x45')]=_0x346312;return _0x2c60cc;})['then'](respondWithFilteredResult(_0x38c1a4,_0x2059e0))[_0xf3ff('0x46')](handleError(_0x38c1a4,null));};exports['show']=function(_0x597ffb,_0x49bc56){var _0x4876da={'raw':!![],'where':{'id':_0x597ffb[_0xf3ff('0x47')]['id']}},_0x19e055={};_0x19e055[_0xf3ff('0x35')]=_[_0xf3ff('0x32')](db[_0xf3ff('0x2c')]['rawAttributes']);_0x19e055[_0xf3ff('0x31')]=_[_0xf3ff('0x32')](_0x597ffb['query']);_0x19e055[_0xf3ff('0x33')]=_['intersection'](_0x19e055['model'],_0x19e055[_0xf3ff('0x31')]);_0x4876da[_0xf3ff('0x36')]=_['intersection'](_0x19e055[_0xf3ff('0x35')],qs['fields'](_0x597ffb[_0xf3ff('0x31')][_0xf3ff('0x37')]));_0x4876da[_0xf3ff('0x36')]=_0x4876da['attributes']['length']?_0x4876da[_0xf3ff('0x36')]:_0x19e055[_0xf3ff('0x35')];if(_0x597ffb[_0xf3ff('0x31')]['includeAll']){_0x4876da[_0xf3ff('0x43')]=[{'all':!![]}];}_0x4876da=_['merge']({},_0x4876da,_0x597ffb['options']);return db[_0xf3ff('0x2c')][_0xf3ff('0x48')](_0x4876da)['then'](handleEntityNotFound(_0x49bc56,null))[_0xf3ff('0x28')](respondWithResult(_0x49bc56,null))['catch'](handleError(_0x49bc56,null));};exports[_0xf3ff('0x49')]=function(_0x3a25f5,_0x29e9d0){return db[_0xf3ff('0x2c')][_0xf3ff('0x49')](_0x3a25f5['body'],{})[_0xf3ff('0x28')](respondWithResult(_0x29e9d0,0xc9))[_0xf3ff('0x46')](handleError(_0x29e9d0,null));};exports[_0xf3ff('0x4a')]=function(_0x49a265,_0x2b3c85){if(_0x49a265['body']['id']){delete _0x49a265['body']['id'];}return db[_0xf3ff('0x2c')]['find']({'where':{'id':_0x49a265[_0xf3ff('0x47')]['id']}})[_0xf3ff('0x28')](handleEntityNotFound(_0x2b3c85,null))[_0xf3ff('0x28')](saveUpdates(_0x49a265['body'],null))['then'](respondWithResult(_0x2b3c85,null))[_0xf3ff('0x46')](handleError(_0x2b3c85,null));};exports[_0xf3ff('0x4b')]=function(_0x3f745b,_0x4a2a3e){return db[_0xf3ff('0x2c')][_0xf3ff('0x48')]({'where':{'id':_0x3f745b[_0xf3ff('0x47')]['id']}})[_0xf3ff('0x28')](handleEntityNotFound(_0x4a2a3e,null))[_0xf3ff('0x28')](removeEntity(_0x4a2a3e,null))[_0xf3ff('0x46')](handleError(_0x4a2a3e,null));};