365d1c7f647dc92d010a58183c11a28bc5531e7d
[motion2.git] / server / api / cmContactHasPhone / cmContactHasPhone.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 _0xc4cb=['where','pick','filter','merge','VIRTUAL','options','count','includeAll','findAll','rows','catch','show','params','keys','fields','include','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','CmContactHasPhones','UserProfileSection','userProfileId','autoAssociation','update','html-pdf','eml-format','rimraf','zip-dir','request-promise','moment','mustache','util','sox','to-csv','ejs','squel','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','json','offset','limit','set','reject','save','then','destroy','get','UserProfileResource','error','name','index','map','CmContactHasPhone','rawAttributes','fieldName','type','key','query','filters','intersection','model','attributes','length','hasOwnProperty','sort'];(function(_0x101f13,_0x506bf0){var _0xf4a101=function(_0x25fe45){while(--_0x25fe45){_0x101f13['push'](_0x101f13['shift']());}};_0xf4a101(++_0x506bf0);}(_0xc4cb,0x10b));var _0xbc4c=function(_0x52bdfe,_0x5282ec){_0x52bdfe=_0x52bdfe-0x0;var _0x5c6df7=_0xc4cb[_0x52bdfe];return _0x5c6df7;};'use strict';var pdf=require(_0xbc4c('0x0'));var emlformat=require(_0xbc4c('0x1'));var rimraf=require(_0xbc4c('0x2'));var zipdir=require(_0xbc4c('0x3'));var jsonpatch=require('fast-json-patch');var rp=require(_0xbc4c('0x4'));var moment=require(_0xbc4c('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xbc4c('0x6'));var util=require(_0xbc4c('0x7'));var path=require('path');var sox=require(_0xbc4c('0x8'));var csv=require(_0xbc4c('0x9'));var ejs=require(_0xbc4c('0xa'));var fs=require('fs');var _=require('lodash');var squel=require(_0xbc4c('0xb'));var crypto=require(_0xbc4c('0xc'));var jsforce=require(_0xbc4c('0xd'));var deskjs=require('desk.js');var toCsv=require(_0xbc4c('0x9'));var querystring=require(_0xbc4c('0xe'));var Papa=require('papaparse');var Redis=require(_0xbc4c('0xf'));var authService=require(_0xbc4c('0x10'));var qs=require(_0xbc4c('0x11'));var as=require(_0xbc4c('0x12'));var hardwareService=require(_0xbc4c('0x13'));var logger=require('../../config/logger')(_0xbc4c('0x14'));var utils=require(_0xbc4c('0x15'));var config=require(_0xbc4c('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0xbc4c('0x17'))['db'];function respondWithStatusCode(_0xd4c86f,_0x12ad1c){_0x12ad1c=_0x12ad1c||0xcc;return function(_0x219dc0){if(_0x219dc0){return _0xd4c86f[_0xbc4c('0x18')](_0x12ad1c);}return _0xd4c86f[_0xbc4c('0x19')](_0x12ad1c)['end']();};}function respondWithResult(_0x4bcb65,_0x2f185c){_0x2f185c=_0x2f185c||0xc8;return function(_0x4eb142){if(_0x4eb142){return _0x4bcb65[_0xbc4c('0x19')](_0x2f185c)[_0xbc4c('0x1a')](_0x4eb142);}};}function respondWithFilteredResult(_0x3a25b0,_0x2c204b){return function(_0x50333d){if(_0x50333d){var _0x49e112=_0x50333d['count'],_0xd92c11=_0x2c204b[_0xbc4c('0x1b')],_0x3a339b=_0x2c204b['offset']+_0x2c204b[_0xbc4c('0x1c')],_0xfaf41d;if(_0x3a339b>=_0x49e112){_0x3a339b=_0x49e112;_0xfaf41d=0xc8;}else{_0xfaf41d=0xce;}_0x3a25b0[_0xbc4c('0x19')](_0xfaf41d);return _0x3a25b0[_0xbc4c('0x1d')]('Content-Range',_0xd92c11+'-'+_0x3a339b+'/'+_0x49e112)[_0xbc4c('0x1a')](_0x50333d);}return null;};}function patchUpdates(_0x1a6fd7){return function(_0xa505c7){try{jsonpatch['apply'](_0xa505c7,_0x1a6fd7,!![]);}catch(_0x4d2455){return BPromise[_0xbc4c('0x1e')](_0x4d2455);}return _0xa505c7[_0xbc4c('0x1f')]();};}function saveUpdates(_0x110192,_0x165903){return function(_0x2a52b3){if(_0x2a52b3){return _0x2a52b3['update'](_0x110192)[_0xbc4c('0x20')](function(_0x2f7c87){return _0x2f7c87;});}return null;};}function removeEntity(_0x3db678,_0x2c9419){return function(_0x52c4a7){if(_0x52c4a7){return _0x52c4a7[_0xbc4c('0x21')]()[_0xbc4c('0x20')](function(){var _0x309dd9=_0x52c4a7[_0xbc4c('0x22')]({'plain':!![]});var _0x1641d3='CmContactHasPhones';return db[_0xbc4c('0x23')][_0xbc4c('0x21')]({'where':{'type':_0x1641d3,'resourceId':_0x309dd9['id']}})[_0xbc4c('0x20')](function(){return _0x52c4a7;});})[_0xbc4c('0x20')](function(){_0x3db678[_0xbc4c('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x591ebf,_0x3ae2ec){return function(_0x4312fd){if(!_0x4312fd){_0x591ebf[_0xbc4c('0x18')](0x194);}return _0x4312fd;};}function handleError(_0x7b087b,_0x4745b9){_0x4745b9=_0x4745b9||0x1f4;return function(_0x32ecd6){logger[_0xbc4c('0x24')](_0x32ecd6['stack']);if(_0x32ecd6['name']){delete _0x32ecd6[_0xbc4c('0x25')];}_0x7b087b[_0xbc4c('0x19')](_0x4745b9)['send'](_0x32ecd6);};}exports[_0xbc4c('0x26')]=function(_0x1a86c1,_0x385056){var _0x243510={},_0x4e1234={},_0x2b3941={'count':0x0,'rows':[]};var _0x322093=_[_0xbc4c('0x27')](db[_0xbc4c('0x28')][_0xbc4c('0x29')],function(_0x49de64){return{'name':_0x49de64[_0xbc4c('0x2a')],'type':_0x49de64[_0xbc4c('0x2b')][_0xbc4c('0x2c')]};});_0x4e1234['model']=_[_0xbc4c('0x27')](_0x322093,_0xbc4c('0x25'));_0x4e1234[_0xbc4c('0x2d')]=_['keys'](_0x1a86c1[_0xbc4c('0x2d')]);_0x4e1234[_0xbc4c('0x2e')]=_[_0xbc4c('0x2f')](_0x4e1234[_0xbc4c('0x30')],_0x4e1234[_0xbc4c('0x2d')]);_0x243510[_0xbc4c('0x31')]=_[_0xbc4c('0x2f')](_0x4e1234[_0xbc4c('0x30')],qs['fields'](_0x1a86c1['query']['fields']));_0x243510[_0xbc4c('0x31')]=_0x243510[_0xbc4c('0x31')][_0xbc4c('0x32')]?_0x243510[_0xbc4c('0x31')]:_0x4e1234[_0xbc4c('0x30')];if(!_0x1a86c1[_0xbc4c('0x2d')][_0xbc4c('0x33')]('nolimit')){_0x243510['limit']=qs[_0xbc4c('0x1c')](_0x1a86c1[_0xbc4c('0x2d')][_0xbc4c('0x1c')]);_0x243510[_0xbc4c('0x1b')]=qs[_0xbc4c('0x1b')](_0x1a86c1[_0xbc4c('0x2d')][_0xbc4c('0x1b')]);}_0x243510['order']=qs[_0xbc4c('0x34')](_0x1a86c1[_0xbc4c('0x2d')][_0xbc4c('0x34')]);_0x243510[_0xbc4c('0x35')]=qs[_0xbc4c('0x2e')](_[_0xbc4c('0x36')](_0x1a86c1[_0xbc4c('0x2d')],_0x4e1234[_0xbc4c('0x2e')]),_0x322093);if(_0x1a86c1[_0xbc4c('0x2d')][_0xbc4c('0x37')]){_0x243510[_0xbc4c('0x35')]=_[_0xbc4c('0x38')](_0x243510[_0xbc4c('0x35')],{'$or':_['map'](_0x322093,function(_0x359aef){if(_0x359aef['type']!==_0xbc4c('0x39')){var _0x3365ea={};_0x3365ea[_0x359aef[_0xbc4c('0x25')]]={'$like':'%'+_0x1a86c1['query'][_0xbc4c('0x37')]+'%'};return _0x3365ea;}})});}_0x243510=_[_0xbc4c('0x38')]({},_0x243510,_0x1a86c1[_0xbc4c('0x3a')]);var _0x15b788={'where':_0x243510[_0xbc4c('0x35')]};return db[_0xbc4c('0x28')]['count'](_0x15b788)[_0xbc4c('0x20')](function(_0x378987){_0x2b3941[_0xbc4c('0x3b')]=_0x378987;if(_0x1a86c1['query'][_0xbc4c('0x3c')]){_0x243510['include']=[{'all':!![]}];}return db['CmContactHasPhone'][_0xbc4c('0x3d')](_0x243510);})['then'](function(_0x5eabc8){_0x2b3941[_0xbc4c('0x3e')]=_0x5eabc8;return _0x2b3941;})[_0xbc4c('0x20')](respondWithFilteredResult(_0x385056,_0x243510))[_0xbc4c('0x3f')](handleError(_0x385056,null));};exports[_0xbc4c('0x40')]=function(_0x3f5534,_0xdde14b){var _0x20d26e={'raw':!![],'where':{'id':_0x3f5534[_0xbc4c('0x41')]['id']}},_0x230cfa={};_0x230cfa[_0xbc4c('0x30')]=_[_0xbc4c('0x42')](db[_0xbc4c('0x28')][_0xbc4c('0x29')]);_0x230cfa[_0xbc4c('0x2d')]=_['keys'](_0x3f5534[_0xbc4c('0x2d')]);_0x230cfa['filters']=_[_0xbc4c('0x2f')](_0x230cfa['model'],_0x230cfa[_0xbc4c('0x2d')]);_0x20d26e['attributes']=_['intersection'](_0x230cfa[_0xbc4c('0x30')],qs[_0xbc4c('0x43')](_0x3f5534[_0xbc4c('0x2d')]['fields']));_0x20d26e[_0xbc4c('0x31')]=_0x20d26e[_0xbc4c('0x31')][_0xbc4c('0x32')]?_0x20d26e[_0xbc4c('0x31')]:_0x230cfa[_0xbc4c('0x30')];if(_0x3f5534[_0xbc4c('0x2d')]['includeAll']){_0x20d26e[_0xbc4c('0x44')]=[{'all':!![]}];}_0x20d26e=_['merge']({},_0x20d26e,_0x3f5534[_0xbc4c('0x3a')]);return db['CmContactHasPhone'][_0xbc4c('0x45')](_0x20d26e)[_0xbc4c('0x20')](handleEntityNotFound(_0xdde14b,null))[_0xbc4c('0x20')](respondWithResult(_0xdde14b,null))[_0xbc4c('0x3f')](handleError(_0xdde14b,null));};exports[_0xbc4c('0x46')]=function(_0x4ecbbc,_0x2d449c){return db['CmContactHasPhone'][_0xbc4c('0x46')](_0x4ecbbc[_0xbc4c('0x47')],{})[_0xbc4c('0x20')](function(_0x534ac9){var _0x10d33a=_0x4ecbbc[_0xbc4c('0x48')][_0xbc4c('0x22')]({'plain':!![]});if(!_0x10d33a)throw new Error(_0xbc4c('0x49'));if(_0x10d33a[_0xbc4c('0x4a')]===_0xbc4c('0x48')){var _0x153d90=_0x534ac9[_0xbc4c('0x22')]({'plain':!![]});var _0x682aa9=_0xbc4c('0x4b');return db[_0xbc4c('0x4c')][_0xbc4c('0x45')]({'where':{'name':_0x682aa9,'userProfileId':_0x10d33a[_0xbc4c('0x4d')]},'raw':!![]})[_0xbc4c('0x20')](function(_0x99a83e){if(_0x99a83e&&_0x99a83e[_0xbc4c('0x4e')]===0x0){return db['UserProfileResource'][_0xbc4c('0x46')]({'name':_0x153d90[_0xbc4c('0x25')],'resourceId':_0x153d90['id'],'type':_0x99a83e[_0xbc4c('0x25')],'sectionId':_0x99a83e['id']},{})[_0xbc4c('0x20')](function(){return _0x534ac9;});}else{return _0x534ac9;}})[_0xbc4c('0x3f')](function(_0xe0da1a){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0xe0da1a);throw _0xe0da1a;});}return _0x534ac9;})['then'](respondWithResult(_0x2d449c,0xc9))[_0xbc4c('0x3f')](handleError(_0x2d449c,null));};exports[_0xbc4c('0x4f')]=function(_0x1afee8,_0x4e14a7){if(_0x1afee8[_0xbc4c('0x47')]['id']){delete _0x1afee8['body']['id'];}return db['CmContactHasPhone'][_0xbc4c('0x45')]({'where':{'id':_0x1afee8[_0xbc4c('0x41')]['id']}})[_0xbc4c('0x20')](handleEntityNotFound(_0x4e14a7,null))[_0xbc4c('0x20')](saveUpdates(_0x1afee8[_0xbc4c('0x47')],null))[_0xbc4c('0x20')](respondWithResult(_0x4e14a7,null))[_0xbc4c('0x3f')](handleError(_0x4e14a7,null));};exports[_0xbc4c('0x21')]=function(_0x4d9c03,_0x5935c5){return db['CmContactHasPhone']['find']({'where':{'id':_0x4d9c03[_0xbc4c('0x41')]['id']}})[_0xbc4c('0x20')](handleEntityNotFound(_0x5935c5,null))[_0xbc4c('0x20')](removeEntity(_0x5935c5,null))[_0xbc4c('0x3f')](handleError(_0x5935c5,null));};