Built motion from commit (unavailable).|2.5.4
[motion2.git] / server / api / cmCompany / cmCompany.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 _0x3fc0=['limit','set','Content-Range','apply','reject','save','update','then','destroy','get','UserProfileResource','error','name','send','CmCompany','describe','model','keys','query','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','filters','filter','merge','options','includeAll','include','findAll','rows','catch','show','rawAttributes','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','Companies','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','CmContact','addContacts','ids','omit','getContacts','findOne','pick','map','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','ejs','squel','crypto','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','../../config/environment','sendStatus','status','end','json','count','offset'];(function(_0x18a79d,_0x57bd2c){var _0x4f8848=function(_0x28af80){while(--_0x28af80){_0x18a79d['push'](_0x18a79d['shift']());}};_0x4f8848(++_0x57bd2c);}(_0x3fc0,0x13c));var _0x03fc=function(_0x36dfbd,_0x5bfe2d){_0x36dfbd=_0x36dfbd-0x0;var _0x4ecad9=_0x3fc0[_0x36dfbd];return _0x4ecad9;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x03fc('0x0'));var zipdir=require(_0x03fc('0x1'));var jsonpatch=require(_0x03fc('0x2'));var rp=require(_0x03fc('0x3'));var moment=require(_0x03fc('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x03fc('0x5'));var util=require(_0x03fc('0x6'));var path=require(_0x03fc('0x7'));var sox=require(_0x03fc('0x8'));var csv=require('to-csv');var ejs=require(_0x03fc('0x9'));var fs=require('fs');var _=require('lodash');var squel=require(_0x03fc('0xa'));var crypto=require(_0x03fc('0xb'));var jsforce=require(_0x03fc('0xc'));var deskjs=require(_0x03fc('0xd'));var toCsv=require(_0x03fc('0xe'));var querystring=require(_0x03fc('0xf'));var Papa=require(_0x03fc('0x10'));var Redis=require(_0x03fc('0x11'));var authService=require(_0x03fc('0x12'));var qs=require(_0x03fc('0x13'));var as=require(_0x03fc('0x14'));var hardwareService=require(_0x03fc('0x15'));var logger=require(_0x03fc('0x16'))(_0x03fc('0x17'));var utils=require(_0x03fc('0x18'));var config=require(_0x03fc('0x19'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3c1d9f,_0xadb1f3){_0xadb1f3=_0xadb1f3||0xcc;return function(_0x3c2430){if(_0x3c2430){return _0x3c1d9f[_0x03fc('0x1a')](_0xadb1f3);}return _0x3c1d9f[_0x03fc('0x1b')](_0xadb1f3)[_0x03fc('0x1c')]();};}function respondWithResult(_0x4d1381,_0x11e45c){_0x11e45c=_0x11e45c||0xc8;return function(_0x4c8171){if(_0x4c8171){return _0x4d1381[_0x03fc('0x1b')](_0x11e45c)[_0x03fc('0x1d')](_0x4c8171);}};}function respondWithFilteredResult(_0x28c9fa,_0xfb4ee8){return function(_0x3e6902){if(_0x3e6902){var _0x529343=_0x3e6902[_0x03fc('0x1e')],_0x5acb46=_0xfb4ee8[_0x03fc('0x1f')],_0x4d5511=_0xfb4ee8['offset']+_0xfb4ee8[_0x03fc('0x20')],_0x34593d;if(_0x4d5511>=_0x529343){_0x4d5511=_0x529343;_0x34593d=0xc8;}else{_0x34593d=0xce;}_0x28c9fa[_0x03fc('0x1b')](_0x34593d);return _0x28c9fa[_0x03fc('0x21')](_0x03fc('0x22'),_0x5acb46+'-'+_0x4d5511+'/'+_0x529343)[_0x03fc('0x1d')](_0x3e6902);}return null;};}function patchUpdates(_0x26abbe){return function(_0x3a0a19){try{jsonpatch[_0x03fc('0x23')](_0x3a0a19,_0x26abbe,!![]);}catch(_0x16241e){return BPromise[_0x03fc('0x24')](_0x16241e);}return _0x3a0a19[_0x03fc('0x25')]();};}function saveUpdates(_0x400042,_0x4af1e7){return function(_0x40c17a){if(_0x40c17a){return _0x40c17a[_0x03fc('0x26')](_0x400042)[_0x03fc('0x27')](function(_0x1e178d){return _0x1e178d;});}return null;};}function removeEntity(_0x378493,_0xe20747){return function(_0x2e8392){if(_0x2e8392){return _0x2e8392[_0x03fc('0x28')]()[_0x03fc('0x27')](function(){var _0xa188a4=_0x2e8392[_0x03fc('0x29')]({'plain':!![]});var _0x4f0cd6='Companies';return db[_0x03fc('0x2a')][_0x03fc('0x28')]({'where':{'type':_0x4f0cd6,'resourceId':_0xa188a4['id']}})[_0x03fc('0x27')](function(){return _0x2e8392;});})[_0x03fc('0x27')](function(){_0x378493[_0x03fc('0x1b')](0xcc)[_0x03fc('0x1c')]();});}};}function handleEntityNotFound(_0x3f39ea,_0x138bac){return function(_0x2760f9){if(!_0x2760f9){_0x3f39ea['sendStatus'](0x194);}return _0x2760f9;};}function handleError(_0x32015d,_0x3b4059){_0x3b4059=_0x3b4059||0x1f4;return function(_0x422c94){logger[_0x03fc('0x2b')](_0x422c94['stack']);if(_0x422c94[_0x03fc('0x2c')]){delete _0x422c94[_0x03fc('0x2c')];}_0x32015d[_0x03fc('0x1b')](_0x3b4059)[_0x03fc('0x2d')](_0x422c94);};}exports['index']=function(_0x10b2e7,_0x30c96a){var _0x54c16d={},_0x48d1ef={},_0x58e602={'count':0x0,'rows':[]};return db[_0x03fc('0x2e')][_0x03fc('0x2f')]()[_0x03fc('0x27')](function(_0x4b91ce){_0x48d1ef[_0x03fc('0x30')]=_[_0x03fc('0x31')](_0x4b91ce);_0x48d1ef[_0x03fc('0x32')]=_['keys'](_0x10b2e7[_0x03fc('0x32')]);_0x48d1ef['filters']=_[_0x03fc('0x33')](_0x48d1ef[_0x03fc('0x30')],_0x48d1ef[_0x03fc('0x32')]);_0x54c16d[_0x03fc('0x34')]=_['intersection'](_0x48d1ef[_0x03fc('0x30')],qs[_0x03fc('0x35')](_0x10b2e7['query'][_0x03fc('0x35')]));_0x54c16d[_0x03fc('0x34')]=_0x54c16d['attributes'][_0x03fc('0x36')]?_0x54c16d['attributes']:_0x48d1ef[_0x03fc('0x30')];if(!_0x10b2e7['query'][_0x03fc('0x37')]('nolimit')){_0x54c16d[_0x03fc('0x20')]=qs[_0x03fc('0x20')](_0x10b2e7[_0x03fc('0x32')][_0x03fc('0x20')]);_0x54c16d[_0x03fc('0x1f')]=qs[_0x03fc('0x1f')](_0x10b2e7[_0x03fc('0x32')]['offset']);}_0x54c16d[_0x03fc('0x38')]=qs[_0x03fc('0x39')](_0x10b2e7[_0x03fc('0x32')][_0x03fc('0x39')]);_0x54c16d[_0x03fc('0x3a')]=qs[_0x03fc('0x3b')](_['pick'](_0x10b2e7['query'],_0x48d1ef[_0x03fc('0x3b')]),_0x4b91ce);if(_0x10b2e7[_0x03fc('0x32')][_0x03fc('0x3c')]){_0x54c16d[_0x03fc('0x3a')]=_[_0x03fc('0x3d')](_0x54c16d[_0x03fc('0x3a')],{'$or':_['map'](_0x54c16d[_0x03fc('0x34')],function(_0x1484cf){var _0x5401a1={};_0x5401a1[_0x1484cf]={'$like':'%'+_0x10b2e7['query'][_0x03fc('0x3c')]+'%'};return _0x5401a1;})});}_0x54c16d=_[_0x03fc('0x3d')]({},_0x54c16d,_0x10b2e7[_0x03fc('0x3e')]);var _0x17c62c={'where':_0x54c16d[_0x03fc('0x3a')]};return db[_0x03fc('0x2e')][_0x03fc('0x1e')](_0x17c62c)[_0x03fc('0x27')](function(_0x143f17){_0x58e602[_0x03fc('0x1e')]=_0x143f17;if(_0x10b2e7[_0x03fc('0x32')][_0x03fc('0x3f')]){_0x54c16d[_0x03fc('0x40')]=[{'all':!![]}];}return db[_0x03fc('0x2e')][_0x03fc('0x41')](_0x54c16d);})[_0x03fc('0x27')](function(_0x462632){_0x58e602[_0x03fc('0x42')]=_0x462632;return _0x58e602;})['then'](respondWithFilteredResult(_0x30c96a,_0x54c16d))['catch'](handleError(_0x30c96a,null));})[_0x03fc('0x43')](handleError(_0x30c96a,null));};exports[_0x03fc('0x44')]=function(_0x2e3245,_0x54f5a4){var _0x2958d5={'raw':![],'where':{'id':_0x2e3245['params']['id']}},_0xe6c2c0={};_0xe6c2c0[_0x03fc('0x30')]=_['keys'](db['CmCompany'][_0x03fc('0x45')]);_0xe6c2c0[_0x03fc('0x32')]=_[_0x03fc('0x31')](_0x2e3245[_0x03fc('0x32')]);_0xe6c2c0[_0x03fc('0x3b')]=_[_0x03fc('0x33')](_0xe6c2c0['model'],_0xe6c2c0[_0x03fc('0x32')]);_0x2958d5[_0x03fc('0x34')]=_['intersection'](_0xe6c2c0[_0x03fc('0x30')],qs[_0x03fc('0x35')](_0x2e3245[_0x03fc('0x32')]['fields']));_0x2958d5[_0x03fc('0x34')]=_0x2958d5[_0x03fc('0x34')][_0x03fc('0x36')]?_0x2958d5['attributes']:_0xe6c2c0['model'];if(_0x2e3245[_0x03fc('0x32')][_0x03fc('0x3f')]){_0x2958d5[_0x03fc('0x40')]=[{'all':!![]}];}_0x2958d5=_[_0x03fc('0x3d')]({},_0x2958d5,_0x2e3245[_0x03fc('0x3e')]);return db['CmCompany'][_0x03fc('0x46')](_0x2958d5)[_0x03fc('0x27')](handleEntityNotFound(_0x54f5a4,null))[_0x03fc('0x27')](respondWithResult(_0x54f5a4,null))[_0x03fc('0x43')](handleError(_0x54f5a4,null));};exports['create']=function(_0x4fdc10,_0xb31356){return db[_0x03fc('0x2e')][_0x03fc('0x47')](_0x4fdc10[_0x03fc('0x48')],{})[_0x03fc('0x27')](function(_0xd086b){var _0x126330=_0x4fdc10['user'][_0x03fc('0x29')]({'plain':!![]});if(!_0x126330)throw new Error(_0x03fc('0x49'));if(_0x126330[_0x03fc('0x4a')]===_0x03fc('0x4b')){var _0xbc3ab7=_0xd086b['get']({'plain':!![]});var _0x204feb=_0x03fc('0x4c');return db['UserProfileSection']['find']({'where':{'name':_0x204feb,'userProfileId':_0x126330['userProfileId']},'raw':!![]})[_0x03fc('0x27')](function(_0x4d5bfb){if(_0x4d5bfb&&_0x4d5bfb['autoAssociation']===0x0){return db[_0x03fc('0x2a')][_0x03fc('0x47')]({'name':_0xbc3ab7[_0x03fc('0x2c')],'resourceId':_0xbc3ab7['id'],'type':_0x4d5bfb[_0x03fc('0x2c')],'sectionId':_0x4d5bfb['id']},{})[_0x03fc('0x27')](function(){return _0xd086b;});}else{return _0xd086b;}})[_0x03fc('0x43')](function(_0x2bf7d){logger[_0x03fc('0x2b')](_0x03fc('0x4d'),_0x2bf7d);throw _0x2bf7d;});}return _0xd086b;})[_0x03fc('0x27')](respondWithResult(_0xb31356,0xc9))['catch'](handleError(_0xb31356,null));};exports[_0x03fc('0x26')]=function(_0x2b7477,_0x43fcfc){if(_0x2b7477[_0x03fc('0x48')]['id']){delete _0x2b7477[_0x03fc('0x48')]['id'];}return db[_0x03fc('0x2e')][_0x03fc('0x46')]({'where':{'id':_0x2b7477['params']['id']}})[_0x03fc('0x27')](handleEntityNotFound(_0x43fcfc,null))[_0x03fc('0x27')](saveUpdates(_0x2b7477['body'],null))[_0x03fc('0x27')](respondWithResult(_0x43fcfc,null))[_0x03fc('0x43')](handleError(_0x43fcfc,null));};exports[_0x03fc('0x28')]=function(_0xb1bba2,_0x209ccc){return db[_0x03fc('0x2e')][_0x03fc('0x46')]({'where':{'id':_0xb1bba2[_0x03fc('0x4e')]['id']}})[_0x03fc('0x27')](handleEntityNotFound(_0x209ccc,null))['then'](removeEntity(_0x209ccc,null))['catch'](handleError(_0x209ccc,null));};exports[_0x03fc('0x2f')]=function(_0x377e43,_0x327f0a){return db[_0x03fc('0x2e')][_0x03fc('0x2f')]()[_0x03fc('0x27')](respondWithResult(_0x327f0a,null))['catch'](handleError(_0x327f0a,null));};exports['addContacts']=function(_0x3bf80d,_0x105d11,_0x406c7d){return db[_0x03fc('0x4f')]['find']({'where':{'id':_0x3bf80d[_0x03fc('0x4e')]['id']}})[_0x03fc('0x27')](handleEntityNotFound(_0x105d11,null))[_0x03fc('0x27')](function(_0x352de1){if(_0x352de1){return _0x352de1[_0x03fc('0x50')](_0x3bf80d[_0x03fc('0x48')][_0x03fc('0x51')],_[_0x03fc('0x52')](_0x3bf80d[_0x03fc('0x48')],[_0x03fc('0x51'),'id'])||{});}})[_0x03fc('0x27')](respondWithResult(_0x105d11,null))['catch'](handleError(_0x105d11,null));};exports[_0x03fc('0x53')]=function(_0x595de5,_0x18b2c8,_0x4b75bc){var _0x17626b={};var _0x945498={};var _0x31e665;var _0x108f81;return db[_0x03fc('0x2e')][_0x03fc('0x54')]({'where':{'id':_0x595de5[_0x03fc('0x4e')]['id']}})['then'](handleEntityNotFound(_0x18b2c8,null))[_0x03fc('0x27')](function(_0x1ebef4){if(_0x1ebef4){_0x31e665=_0x1ebef4;_0x945498['model']=_[_0x03fc('0x31')](db[_0x03fc('0x4f')][_0x03fc('0x45')]);_0x945498[_0x03fc('0x32')]=_['keys'](_0x595de5[_0x03fc('0x32')]);_0x945498['filters']=_[_0x03fc('0x33')](_0x945498[_0x03fc('0x30')],_0x945498[_0x03fc('0x32')]);_0x17626b[_0x03fc('0x34')]=_[_0x03fc('0x33')](_0x945498[_0x03fc('0x30')],qs[_0x03fc('0x35')](_0x595de5[_0x03fc('0x32')][_0x03fc('0x35')]));_0x17626b[_0x03fc('0x34')]=_0x17626b[_0x03fc('0x34')][_0x03fc('0x36')]?_0x17626b[_0x03fc('0x34')]:_0x945498[_0x03fc('0x30')];_0x17626b[_0x03fc('0x38')]=qs[_0x03fc('0x39')](_0x595de5[_0x03fc('0x32')]['sort']);_0x17626b[_0x03fc('0x3a')]=qs[_0x03fc('0x3b')](_[_0x03fc('0x55')](_0x595de5['query'],_0x945498[_0x03fc('0x3b')]));if(_0x595de5[_0x03fc('0x32')][_0x03fc('0x3c')]){_0x17626b['where']=_[_0x03fc('0x3d')](_0x17626b[_0x03fc('0x3a')],{'$or':_[_0x03fc('0x56')](_0x17626b[_0x03fc('0x34')],function(_0x5980ec){var _0x15c8b6={};_0x15c8b6[_0x5980ec]={'$like':'%'+_0x595de5['query'][_0x03fc('0x3c')]+'%'};return _0x15c8b6;})});}_0x17626b=_['merge']({},_0x17626b,_0x595de5[_0x03fc('0x3e')]);return _0x31e665[_0x03fc('0x53')](_0x17626b);}})[_0x03fc('0x27')](function(_0x3204da){if(_0x3204da){_0x108f81=_0x3204da[_0x03fc('0x36')];if(!_0x595de5[_0x03fc('0x32')][_0x03fc('0x37')]('nolimit')){_0x17626b[_0x03fc('0x20')]=qs[_0x03fc('0x20')](_0x595de5[_0x03fc('0x32')]['limit']);_0x17626b['offset']=qs[_0x03fc('0x1f')](_0x595de5[_0x03fc('0x32')]['offset']);}return _0x31e665[_0x03fc('0x53')](_0x17626b);}})[_0x03fc('0x27')](function(_0x38fae2){if(_0x38fae2){return _0x38fae2?{'count':_0x108f81,'rows':_0x38fae2}:null;}})['then'](respondWithResult(_0x18b2c8,null))[_0x03fc('0x43')](handleError(_0x18b2c8,null));};