Built motion from commit (unavailable).|2.5.4
[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 _0x321f=['UserProfileResource','error','name','send','index','rawAttributes','key','model','map','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','pick','filter','merge','type','options','includeAll','include','findAll','rows','show','params','CmContactHasPhone','catch','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','to-csv','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','sendStatus','end','status','json','count','offset','limit','set','apply','reject','save','update','then','destroy','get','CmContactHasPhones'];(function(_0x39e869,_0x2d7972){var _0x508ddd=function(_0x117815){while(--_0x117815){_0x39e869['push'](_0x39e869['shift']());}};_0x508ddd(++_0x2d7972);}(_0x321f,0x78));var _0xf321=function(_0x3f57db,_0x10e075){_0x3f57db=_0x3f57db-0x0;var _0x8cc430=_0x321f[_0x3f57db];return _0x8cc430;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xf321('0x0'));var rimraf=require(_0xf321('0x1'));var zipdir=require(_0xf321('0x2'));var jsonpatch=require(_0xf321('0x3'));var rp=require(_0xf321('0x4'));var moment=require(_0xf321('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xf321('0x6'));var util=require('util');var path=require(_0xf321('0x7'));var sox=require('sox');var csv=require(_0xf321('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0xf321('0x9'));var crypto=require(_0xf321('0xa'));var jsforce=require(_0xf321('0xb'));var deskjs=require(_0xf321('0xc'));var toCsv=require(_0xf321('0x8'));var querystring=require(_0xf321('0xd'));var Papa=require(_0xf321('0xe'));var Redis=require(_0xf321('0xf'));var authService=require(_0xf321('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0xf321('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf321('0x12'))(_0xf321('0x13'));var utils=require(_0xf321('0x14'));var config=require(_0xf321('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x46b899,_0x4b1b5d){_0x4b1b5d=_0x4b1b5d||0xcc;return function(_0x5f4df2){if(_0x5f4df2){return _0x46b899[_0xf321('0x16')](_0x4b1b5d);}return _0x46b899['status'](_0x4b1b5d)[_0xf321('0x17')]();};}function respondWithResult(_0x4228c1,_0x1b0d99){_0x1b0d99=_0x1b0d99||0xc8;return function(_0x33e33b){if(_0x33e33b){return _0x4228c1[_0xf321('0x18')](_0x1b0d99)[_0xf321('0x19')](_0x33e33b);}};}function respondWithFilteredResult(_0x4c645c,_0x20f7d0){return function(_0x10509c){if(_0x10509c){var _0x1c6d5e=_0x10509c[_0xf321('0x1a')],_0x49fbb6=_0x20f7d0[_0xf321('0x1b')],_0x5032df=_0x20f7d0[_0xf321('0x1b')]+_0x20f7d0[_0xf321('0x1c')],_0x5ce4e9;if(_0x5032df>=_0x1c6d5e){_0x5032df=_0x1c6d5e;_0x5ce4e9=0xc8;}else{_0x5ce4e9=0xce;}_0x4c645c['status'](_0x5ce4e9);return _0x4c645c[_0xf321('0x1d')]('Content-Range',_0x49fbb6+'-'+_0x5032df+'/'+_0x1c6d5e)[_0xf321('0x19')](_0x10509c);}return null;};}function patchUpdates(_0x39126c){return function(_0xa8be93){try{jsonpatch[_0xf321('0x1e')](_0xa8be93,_0x39126c,!![]);}catch(_0x1f2b64){return BPromise[_0xf321('0x1f')](_0x1f2b64);}return _0xa8be93[_0xf321('0x20')]();};}function saveUpdates(_0x4cfda3,_0x344af3){return function(_0x4ca000){if(_0x4ca000){return _0x4ca000[_0xf321('0x21')](_0x4cfda3)[_0xf321('0x22')](function(_0x4d376f){return _0x4d376f;});}return null;};}function removeEntity(_0x1653e2,_0x14b33d){return function(_0x5d56e0){if(_0x5d56e0){return _0x5d56e0[_0xf321('0x23')]()[_0xf321('0x22')](function(){var _0x52248b=_0x5d56e0[_0xf321('0x24')]({'plain':!![]});var _0x420873=_0xf321('0x25');return db[_0xf321('0x26')][_0xf321('0x23')]({'where':{'type':_0x420873,'resourceId':_0x52248b['id']}})[_0xf321('0x22')](function(){return _0x5d56e0;});})[_0xf321('0x22')](function(){_0x1653e2[_0xf321('0x18')](0xcc)[_0xf321('0x17')]();});}};}function handleEntityNotFound(_0x487b0b,_0x145417){return function(_0x3335ca){if(!_0x3335ca){_0x487b0b[_0xf321('0x16')](0x194);}return _0x3335ca;};}function handleError(_0x218ae1,_0x4834c6){_0x4834c6=_0x4834c6||0x1f4;return function(_0x155efd){logger[_0xf321('0x27')](_0x155efd['stack']);if(_0x155efd[_0xf321('0x28')]){delete _0x155efd[_0xf321('0x28')];}_0x218ae1[_0xf321('0x18')](_0x4834c6)[_0xf321('0x29')](_0x155efd);};}exports[_0xf321('0x2a')]=function(_0x571561,_0x31a1f0){var _0x81380d={},_0x156fc9={},_0xfa54ec={'count':0x0,'rows':[]};var _0x354001=_['map'](db['CmContactHasPhone'][_0xf321('0x2b')],function(_0x5d8cf6){return{'name':_0x5d8cf6['fieldName'],'type':_0x5d8cf6['type'][_0xf321('0x2c')]};});_0x156fc9[_0xf321('0x2d')]=_[_0xf321('0x2e')](_0x354001,_0xf321('0x28'));_0x156fc9['query']=_[_0xf321('0x2f')](_0x571561[_0xf321('0x30')]);_0x156fc9[_0xf321('0x31')]=_[_0xf321('0x32')](_0x156fc9[_0xf321('0x2d')],_0x156fc9[_0xf321('0x30')]);_0x81380d[_0xf321('0x33')]=_[_0xf321('0x32')](_0x156fc9[_0xf321('0x2d')],qs[_0xf321('0x34')](_0x571561['query'][_0xf321('0x34')]));_0x81380d[_0xf321('0x33')]=_0x81380d['attributes'][_0xf321('0x35')]?_0x81380d[_0xf321('0x33')]:_0x156fc9['model'];if(!_0x571561[_0xf321('0x30')][_0xf321('0x36')]('nolimit')){_0x81380d[_0xf321('0x1c')]=qs[_0xf321('0x1c')](_0x571561[_0xf321('0x30')][_0xf321('0x1c')]);_0x81380d[_0xf321('0x1b')]=qs['offset'](_0x571561[_0xf321('0x30')][_0xf321('0x1b')]);}_0x81380d[_0xf321('0x37')]=qs['sort'](_0x571561[_0xf321('0x30')][_0xf321('0x38')]);_0x81380d[_0xf321('0x39')]=qs[_0xf321('0x31')](_[_0xf321('0x3a')](_0x571561[_0xf321('0x30')],_0x156fc9[_0xf321('0x31')]),_0x354001);if(_0x571561[_0xf321('0x30')][_0xf321('0x3b')]){_0x81380d[_0xf321('0x39')]=_[_0xf321('0x3c')](_0x81380d[_0xf321('0x39')],{'$or':_[_0xf321('0x2e')](_0x354001,function(_0x29f953){if(_0x29f953[_0xf321('0x3d')]!=='VIRTUAL'){var _0x3c969e={};_0x3c969e[_0x29f953[_0xf321('0x28')]]={'$like':'%'+_0x571561[_0xf321('0x30')]['filter']+'%'};return _0x3c969e;}})});}_0x81380d=_[_0xf321('0x3c')]({},_0x81380d,_0x571561[_0xf321('0x3e')]);var _0x1efc56={'where':_0x81380d[_0xf321('0x39')]};return db['CmContactHasPhone'][_0xf321('0x1a')](_0x1efc56)[_0xf321('0x22')](function(_0x33761a){_0xfa54ec['count']=_0x33761a;if(_0x571561['query'][_0xf321('0x3f')]){_0x81380d[_0xf321('0x40')]=[{'all':!![]}];}return db['CmContactHasPhone'][_0xf321('0x41')](_0x81380d);})['then'](function(_0x20beaa){_0xfa54ec[_0xf321('0x42')]=_0x20beaa;return _0xfa54ec;})[_0xf321('0x22')](respondWithFilteredResult(_0x31a1f0,_0x81380d))['catch'](handleError(_0x31a1f0,null));};exports[_0xf321('0x43')]=function(_0x54b048,_0x185b30){var _0x1b2a77={'raw':!![],'where':{'id':_0x54b048[_0xf321('0x44')]['id']}},_0x51c848={};_0x51c848[_0xf321('0x2d')]=_[_0xf321('0x2f')](db[_0xf321('0x45')][_0xf321('0x2b')]);_0x51c848[_0xf321('0x30')]=_[_0xf321('0x2f')](_0x54b048['query']);_0x51c848['filters']=_[_0xf321('0x32')](_0x51c848[_0xf321('0x2d')],_0x51c848['query']);_0x1b2a77[_0xf321('0x33')]=_[_0xf321('0x32')](_0x51c848[_0xf321('0x2d')],qs[_0xf321('0x34')](_0x54b048['query'][_0xf321('0x34')]));_0x1b2a77['attributes']=_0x1b2a77[_0xf321('0x33')][_0xf321('0x35')]?_0x1b2a77['attributes']:_0x51c848[_0xf321('0x2d')];if(_0x54b048[_0xf321('0x30')][_0xf321('0x3f')]){_0x1b2a77['include']=[{'all':!![]}];}_0x1b2a77=_[_0xf321('0x3c')]({},_0x1b2a77,_0x54b048[_0xf321('0x3e')]);return db[_0xf321('0x45')]['find'](_0x1b2a77)[_0xf321('0x22')](handleEntityNotFound(_0x185b30,null))['then'](respondWithResult(_0x185b30,null))[_0xf321('0x46')](handleError(_0x185b30,null));};exports[_0xf321('0x47')]=function(_0x4939a6,_0x4e3795){return db[_0xf321('0x45')][_0xf321('0x47')](_0x4939a6[_0xf321('0x48')],{})['then'](function(_0x1e5138){var _0x5b0415=_0x4939a6[_0xf321('0x49')]['get']({'plain':!![]});if(!_0x5b0415)throw new Error(_0xf321('0x4a'));if(_0x5b0415['role']===_0xf321('0x49')){var _0x2fbb93=_0x1e5138[_0xf321('0x24')]({'plain':!![]});var _0x34e18b='CmContactHasPhones';return db['UserProfileSection'][_0xf321('0x4b')]({'where':{'name':_0x34e18b,'userProfileId':_0x5b0415[_0xf321('0x4c')]},'raw':!![]})['then'](function(_0x5f41b1){if(_0x5f41b1&&_0x5f41b1[_0xf321('0x4d')]===0x0){return db['UserProfileResource'][_0xf321('0x47')]({'name':_0x2fbb93[_0xf321('0x28')],'resourceId':_0x2fbb93['id'],'type':_0x5f41b1[_0xf321('0x28')],'sectionId':_0x5f41b1['id']},{})[_0xf321('0x22')](function(){return _0x1e5138;});}else{return _0x1e5138;}})['catch'](function(_0x113dfe){logger[_0xf321('0x27')](_0xf321('0x4e'),_0x113dfe);throw _0x113dfe;});}return _0x1e5138;})['then'](respondWithResult(_0x4e3795,0xc9))[_0xf321('0x46')](handleError(_0x4e3795,null));};exports[_0xf321('0x21')]=function(_0x3affff,_0x5771f0){if(_0x3affff[_0xf321('0x48')]['id']){delete _0x3affff[_0xf321('0x48')]['id'];}return db[_0xf321('0x45')][_0xf321('0x4b')]({'where':{'id':_0x3affff[_0xf321('0x44')]['id']}})['then'](handleEntityNotFound(_0x5771f0,null))[_0xf321('0x22')](saveUpdates(_0x3affff[_0xf321('0x48')],null))[_0xf321('0x22')](respondWithResult(_0x5771f0,null))[_0xf321('0x46')](handleError(_0x5771f0,null));};exports[_0xf321('0x23')]=function(_0x350bbe,_0x3ac524){return db['CmContactHasPhone'][_0xf321('0x4b')]({'where':{'id':_0x350bbe['params']['id']}})[_0xf321('0x22')](handleEntityNotFound(_0x3ac524,null))[_0xf321('0x22')](removeEntity(_0x3ac524,null))['catch'](handleError(_0x3ac524,null));};