Built motion from commit dbf3a7e2.|2.6.30
[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 _0x1eb2=['intersection','fields','model','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','catch','show','params','length','find','create','body','eml-format','zip-dir','request-promise','bluebird','util','path','sox','to-csv','fs-extra','lodash','squel','crypto','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','limit','set','apply','reject','save','update','then','destroy','error','stack','name','map','OpenchannelApplication','rawAttributes','fieldName','type','key','query','keys','filters','attributes'];(function(_0x54e335,_0x6b782d){var _0x5be44a=function(_0x599a0e){while(--_0x599a0e){_0x54e335['push'](_0x54e335['shift']());}};_0x5be44a(++_0x6b782d);}(_0x1eb2,0x17e));var _0x21eb=function(_0x176c66,_0x221b98){_0x176c66=_0x176c66-0x0;var _0x9c5aaf=_0x1eb2[_0x176c66];return _0x9c5aaf;};'use strict';var emlformat=require(_0x21eb('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x21eb('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x21eb('0x2'));var moment=require('moment');var BPromise=require(_0x21eb('0x3'));var Mustache=require('mustache');var util=require(_0x21eb('0x4'));var path=require(_0x21eb('0x5'));var sox=require(_0x21eb('0x6'));var csv=require(_0x21eb('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x21eb('0x8'));var _=require(_0x21eb('0x9'));var squel=require(_0x21eb('0xa'));var crypto=require(_0x21eb('0xb'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x21eb('0xc'));var Redis=require(_0x21eb('0xd'));var authService=require(_0x21eb('0xe'));var qs=require(_0x21eb('0xf'));var as=require(_0x21eb('0x10'));var hardwareService=require(_0x21eb('0x11'));var logger=require('../../config/logger')(_0x21eb('0x12'));var utils=require(_0x21eb('0x13'));var config=require(_0x21eb('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0x21eb('0x15'))['db'];function respondWithStatusCode(_0x2e5d4e,_0xad7ec8){_0xad7ec8=_0xad7ec8||0xcc;return function(_0x155030){if(_0x155030){return _0x2e5d4e[_0x21eb('0x16')](_0xad7ec8);}return _0x2e5d4e[_0x21eb('0x17')](_0xad7ec8)[_0x21eb('0x18')]();};}function respondWithResult(_0x4c3d7b,_0x2550f2){_0x2550f2=_0x2550f2||0xc8;return function(_0x56ccc3){if(_0x56ccc3){return _0x4c3d7b['status'](_0x2550f2)[_0x21eb('0x19')](_0x56ccc3);}};}function respondWithFilteredResult(_0x1782a3,_0xed7276){return function(_0x32337b){if(_0x32337b){var _0x1a847f=typeof _0xed7276[_0x21eb('0x1a')]===_0x21eb('0x1b')&&typeof _0xed7276['limit']===_0x21eb('0x1b');var _0x183c13=_0x32337b[_0x21eb('0x1c')];var _0x2d6609=_0x1a847f?0x0:_0xed7276[_0x21eb('0x1a')];var _0x49ade9=_0x1a847f?_0x32337b[_0x21eb('0x1c')]:_0xed7276[_0x21eb('0x1a')]+_0xed7276[_0x21eb('0x1d')];var _0x1d27a9;if(_0x49ade9>=_0x183c13){_0x49ade9=_0x183c13;_0x1d27a9=0xc8;}else{_0x1d27a9=0xce;}_0x1782a3['status'](_0x1d27a9);return _0x1782a3[_0x21eb('0x1e')]('Content-Range',_0x2d6609+'-'+_0x49ade9+'/'+_0x183c13)[_0x21eb('0x19')](_0x32337b);}return null;};}function patchUpdates(_0x515791){return function(_0x48ebc2){try{jsonpatch[_0x21eb('0x1f')](_0x48ebc2,_0x515791,!![]);}catch(_0x3cb2af){return BPromise[_0x21eb('0x20')](_0x3cb2af);}return _0x48ebc2[_0x21eb('0x21')]();};}function saveUpdates(_0x42a67d,_0x3eeac4){return function(_0x2a300e){if(_0x2a300e){return _0x2a300e[_0x21eb('0x22')](_0x42a67d)[_0x21eb('0x23')](function(_0x2e9f85){return _0x2e9f85;});}return null;};}function removeEntity(_0x1eb144,_0x57fb4b){return function(_0x1fcd87){if(_0x1fcd87){return _0x1fcd87[_0x21eb('0x24')]()[_0x21eb('0x23')](function(){_0x1eb144[_0x21eb('0x17')](0xcc)[_0x21eb('0x18')]();});}};}function handleEntityNotFound(_0x197557,_0x30191c){return function(_0x360081){if(!_0x360081){_0x197557['sendStatus'](0x194);}return _0x360081;};}function handleError(_0x1c1de4,_0x212f79){_0x212f79=_0x212f79||0x1f4;return function(_0x2e5b16){logger[_0x21eb('0x25')](_0x2e5b16[_0x21eb('0x26')]);if(_0x2e5b16[_0x21eb('0x27')]){delete _0x2e5b16[_0x21eb('0x27')];}_0x1c1de4['status'](_0x212f79)['send'](_0x2e5b16);};}exports['index']=function(_0x4dbcbe,_0x1db684){var _0x250d3c={},_0x30e68e={},_0x40313d={'count':0x0,'rows':[]};var _0x401070=_[_0x21eb('0x28')](db[_0x21eb('0x29')][_0x21eb('0x2a')],function(_0x157373){return{'name':_0x157373[_0x21eb('0x2b')],'type':_0x157373[_0x21eb('0x2c')][_0x21eb('0x2d')]};});_0x30e68e['model']=_[_0x21eb('0x28')](_0x401070,_0x21eb('0x27'));_0x30e68e[_0x21eb('0x2e')]=_[_0x21eb('0x2f')](_0x4dbcbe[_0x21eb('0x2e')]);_0x30e68e[_0x21eb('0x30')]=_['intersection'](_0x30e68e['model'],_0x30e68e[_0x21eb('0x2e')]);_0x250d3c[_0x21eb('0x31')]=_[_0x21eb('0x32')](_0x30e68e['model'],qs['fields'](_0x4dbcbe[_0x21eb('0x2e')][_0x21eb('0x33')]));_0x250d3c[_0x21eb('0x31')]=_0x250d3c[_0x21eb('0x31')]['length']?_0x250d3c[_0x21eb('0x31')]:_0x30e68e[_0x21eb('0x34')];if(!_0x4dbcbe[_0x21eb('0x2e')]['hasOwnProperty'](_0x21eb('0x35'))){_0x250d3c['limit']=qs[_0x21eb('0x1d')](_0x4dbcbe[_0x21eb('0x2e')][_0x21eb('0x1d')]);_0x250d3c[_0x21eb('0x1a')]=qs[_0x21eb('0x1a')](_0x4dbcbe[_0x21eb('0x2e')][_0x21eb('0x1a')]);}_0x250d3c[_0x21eb('0x36')]=qs['sort'](_0x4dbcbe['query'][_0x21eb('0x37')]);_0x250d3c[_0x21eb('0x38')]=qs[_0x21eb('0x30')](_[_0x21eb('0x39')](_0x4dbcbe[_0x21eb('0x2e')],_0x30e68e[_0x21eb('0x30')]),_0x401070);if(_0x4dbcbe['query'][_0x21eb('0x3a')]){_0x250d3c[_0x21eb('0x38')]=_[_0x21eb('0x3b')](_0x250d3c['where'],{'$or':_[_0x21eb('0x28')](_0x401070,function(_0x278104){if(_0x278104[_0x21eb('0x2c')]!==_0x21eb('0x3c')){var _0x48704e={};_0x48704e[_0x278104['name']]={'$like':'%'+_0x4dbcbe[_0x21eb('0x2e')][_0x21eb('0x3a')]+'%'};return _0x48704e;}})});}_0x250d3c=_[_0x21eb('0x3b')]({},_0x250d3c,_0x4dbcbe[_0x21eb('0x3d')]);var _0x5d4583={'where':_0x250d3c[_0x21eb('0x38')]};return db['OpenchannelApplication'][_0x21eb('0x1c')](_0x5d4583)[_0x21eb('0x23')](function(_0x1691cf){_0x40313d[_0x21eb('0x1c')]=_0x1691cf;if(_0x4dbcbe[_0x21eb('0x2e')][_0x21eb('0x3e')]){_0x250d3c[_0x21eb('0x3f')]=[{'all':!![]}];}return db['OpenchannelApplication'][_0x21eb('0x40')](_0x250d3c);})[_0x21eb('0x23')](function(_0x19cbb5){_0x40313d['rows']=_0x19cbb5;return _0x40313d;})[_0x21eb('0x23')](respondWithFilteredResult(_0x1db684,_0x250d3c))[_0x21eb('0x41')](handleError(_0x1db684,null));};exports[_0x21eb('0x42')]=function(_0x536ccd,_0x517544){var _0x54bc67={'raw':!![],'where':{'id':_0x536ccd[_0x21eb('0x43')]['id']}},_0x2826eb={};_0x2826eb[_0x21eb('0x34')]=_[_0x21eb('0x2f')](db[_0x21eb('0x29')]['rawAttributes']);_0x2826eb[_0x21eb('0x2e')]=_[_0x21eb('0x2f')](_0x536ccd[_0x21eb('0x2e')]);_0x2826eb[_0x21eb('0x30')]=_[_0x21eb('0x32')](_0x2826eb[_0x21eb('0x34')],_0x2826eb[_0x21eb('0x2e')]);_0x54bc67[_0x21eb('0x31')]=_[_0x21eb('0x32')](_0x2826eb[_0x21eb('0x34')],qs['fields'](_0x536ccd[_0x21eb('0x2e')]['fields']));_0x54bc67[_0x21eb('0x31')]=_0x54bc67['attributes'][_0x21eb('0x44')]?_0x54bc67[_0x21eb('0x31')]:_0x2826eb['model'];if(_0x536ccd[_0x21eb('0x2e')][_0x21eb('0x3e')]){_0x54bc67[_0x21eb('0x3f')]=[{'all':!![]}];}_0x54bc67=_['merge']({},_0x54bc67,_0x536ccd[_0x21eb('0x3d')]);return db[_0x21eb('0x29')][_0x21eb('0x45')](_0x54bc67)[_0x21eb('0x23')](handleEntityNotFound(_0x517544,null))[_0x21eb('0x23')](respondWithResult(_0x517544,null))['catch'](handleError(_0x517544,null));};exports[_0x21eb('0x46')]=function(_0x5701e1,_0x1ac3e2){return db[_0x21eb('0x29')]['create'](_0x5701e1[_0x21eb('0x47')],{})[_0x21eb('0x23')](respondWithResult(_0x1ac3e2,0xc9))[_0x21eb('0x41')](handleError(_0x1ac3e2,null));};exports[_0x21eb('0x22')]=function(_0x470768,_0x5f15a7){if(_0x470768[_0x21eb('0x47')]['id']){delete _0x470768[_0x21eb('0x47')]['id'];}return db['OpenchannelApplication'][_0x21eb('0x45')]({'where':{'id':_0x470768[_0x21eb('0x43')]['id']}})['then'](handleEntityNotFound(_0x5f15a7,null))[_0x21eb('0x23')](saveUpdates(_0x470768['body'],null))['then'](respondWithResult(_0x5f15a7,null))[_0x21eb('0x41')](handleError(_0x5f15a7,null));};exports[_0x21eb('0x24')]=function(_0x3b2e76,_0x43abe5){return db[_0x21eb('0x29')][_0x21eb('0x45')]({'where':{'id':_0x3b2e76['params']['id']}})[_0x21eb('0x23')](handleEntityNotFound(_0x43abe5,null))[_0x21eb('0x23')](removeEntity(_0x43abe5,null))['catch'](handleError(_0x43abe5,null));};