55dba39493377b04c71dd7386988a73318eb01e8
[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 _0x49b1=['ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','get','CmContactHasPhones','UserProfileResource','stack','name','send','render','merge','body','contact','agent','interaction','index','map','CmContactHasPhone','rawAttributes','fieldName','type','model','keys','filters','query','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','VIRTUAL','options','includeAll','include','findAll','rows','catch','params','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','lodash','squel','crypto','desk.js','to-csv'];(function(_0xe8fa1f,_0x12bba1){var _0x4b3a65=function(_0x3f5161){while(--_0x3f5161){_0xe8fa1f['push'](_0xe8fa1f['shift']());}};_0x4b3a65(++_0x12bba1);}(_0x49b1,0x101));var _0x149b=function(_0x1facfa,_0x1acf7d){_0x1facfa=_0x1facfa-0x0;var _0x9ec701=_0x49b1[_0x1facfa];return _0x9ec701;};'use strict';var emlformat=require(_0x149b('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x149b('0x1'));var jsonpatch=require(_0x149b('0x2'));var rp=require(_0x149b('0x3'));var moment=require(_0x149b('0x4'));var BPromise=require(_0x149b('0x5'));var Mustache=require(_0x149b('0x6'));var util=require(_0x149b('0x7'));var path=require(_0x149b('0x8'));var sox=require(_0x149b('0x9'));var csv=require('to-csv');var ejs=require(_0x149b('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x149b('0xb'));var squel=require(_0x149b('0xc'));var crypto=require(_0x149b('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x149b('0xe'));var toCsv=require(_0x149b('0xf'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x149b('0x10'));var authService=require(_0x149b('0x11'));var qs=require(_0x149b('0x12'));var as=require(_0x149b('0x13'));var hardwareService=require(_0x149b('0x14'));var logger=require(_0x149b('0x15'))('api');var utils=require(_0x149b('0x16'));var config=require(_0x149b('0x17'));var licenseUtil=require(_0x149b('0x18'));var db=require(_0x149b('0x19'))['db'];function respondWithStatusCode(_0x224ba3,_0x54bce4){_0x54bce4=_0x54bce4||0xcc;return function(_0x413de2){if(_0x413de2){return _0x224ba3[_0x149b('0x1a')](_0x54bce4);}return _0x224ba3[_0x149b('0x1b')](_0x54bce4)[_0x149b('0x1c')]();};}function respondWithResult(_0x4e3894,_0x3c784e){_0x3c784e=_0x3c784e||0xc8;return function(_0x5074ef){if(_0x5074ef){return _0x4e3894[_0x149b('0x1b')](_0x3c784e)[_0x149b('0x1d')](_0x5074ef);}};}function respondWithFilteredResult(_0x332e12,_0x3f59d1){return function(_0x367dea){if(_0x367dea){var _0x2ba27a=typeof _0x3f59d1[_0x149b('0x1e')]===_0x149b('0x1f')&&typeof _0x3f59d1[_0x149b('0x20')]===_0x149b('0x1f');var _0x49304d=_0x367dea[_0x149b('0x21')];var _0x34c987=_0x2ba27a?0x0:_0x3f59d1[_0x149b('0x1e')];var _0x491b9f=_0x2ba27a?_0x367dea[_0x149b('0x21')]:_0x3f59d1[_0x149b('0x1e')]+_0x3f59d1[_0x149b('0x20')];var _0x51af35;if(_0x491b9f>=_0x49304d){_0x491b9f=_0x49304d;_0x51af35=0xc8;}else{_0x51af35=0xce;}_0x332e12[_0x149b('0x1b')](_0x51af35);return _0x332e12[_0x149b('0x22')](_0x149b('0x23'),_0x34c987+'-'+_0x491b9f+'/'+_0x49304d)['json'](_0x367dea);}return null;};}function patchUpdates(_0x1f7ca6){return function(_0x5c04c6){try{jsonpatch[_0x149b('0x24')](_0x5c04c6,_0x1f7ca6,!![]);}catch(_0x2420a0){return BPromise[_0x149b('0x25')](_0x2420a0);}return _0x5c04c6[_0x149b('0x26')]();};}function saveUpdates(_0x3c5b2b,_0x5c7a10){return function(_0x585415){if(_0x585415){return _0x585415[_0x149b('0x27')](_0x3c5b2b)[_0x149b('0x28')](function(_0x20346f){return _0x20346f;});}return null;};}function removeEntity(_0x27e8dd,_0x27c245){return function(_0x31865d){if(_0x31865d){return _0x31865d[_0x149b('0x29')]()[_0x149b('0x28')](function(){var _0x340bdc=_0x31865d[_0x149b('0x2a')]({'plain':!![]});var _0x51785c=_0x149b('0x2b');return db[_0x149b('0x2c')][_0x149b('0x29')]({'where':{'type':_0x51785c,'resourceId':_0x340bdc['id']}})[_0x149b('0x28')](function(){return _0x31865d;});})[_0x149b('0x28')](function(){_0x27e8dd[_0x149b('0x1b')](0xcc)[_0x149b('0x1c')]();});}};}function handleEntityNotFound(_0x173c1d,_0x119ae0){return function(_0x5b3bbb){if(!_0x5b3bbb){_0x173c1d[_0x149b('0x1a')](0x194);}return _0x5b3bbb;};}function handleError(_0x46ebb9,_0x9d16a9){_0x9d16a9=_0x9d16a9||0x1f4;return function(_0x37ad0d){logger['error'](_0x37ad0d[_0x149b('0x2d')]);if(_0x37ad0d[_0x149b('0x2e')]){delete _0x37ad0d[_0x149b('0x2e')];}_0x46ebb9[_0x149b('0x1b')](_0x9d16a9)[_0x149b('0x2f')](_0x37ad0d);};}function getMustacheRender(_0x11f6c9,_0x1c3727){return Mustache[_0x149b('0x30')](_0x11f6c9,_[_0x149b('0x31')](_0x1c3727[_0x149b('0x32')],{'contact':_0x1c3727[_0x149b('0x33')],'message':_0x1c3727['message'],'agent':_0x1c3727[_0x149b('0x34')],'interaction':_0x1c3727[_0x149b('0x35')],'account':_0x1c3727['account']}))||'';}exports[_0x149b('0x36')]=function(_0x1b5986,_0x370eea){var _0x4bf600={},_0x2a075a={},_0x2c4e3a={'count':0x0,'rows':[]};var _0x109916=_[_0x149b('0x37')](db[_0x149b('0x38')][_0x149b('0x39')],function(_0x2f0a40){return{'name':_0x2f0a40[_0x149b('0x3a')],'type':_0x2f0a40[_0x149b('0x3b')]['key']};});_0x2a075a[_0x149b('0x3c')]=_[_0x149b('0x37')](_0x109916,'name');_0x2a075a['query']=_[_0x149b('0x3d')](_0x1b5986['query']);_0x2a075a[_0x149b('0x3e')]=_['intersection'](_0x2a075a['model'],_0x2a075a[_0x149b('0x3f')]);_0x4bf600[_0x149b('0x40')]=_[_0x149b('0x41')](_0x2a075a[_0x149b('0x3c')],qs['fields'](_0x1b5986[_0x149b('0x3f')][_0x149b('0x42')]));_0x4bf600[_0x149b('0x40')]=_0x4bf600[_0x149b('0x40')][_0x149b('0x43')]?_0x4bf600[_0x149b('0x40')]:_0x2a075a['model'];if(!_0x1b5986['query'][_0x149b('0x44')](_0x149b('0x45'))){_0x4bf600['limit']=qs[_0x149b('0x20')](_0x1b5986[_0x149b('0x3f')][_0x149b('0x20')]);_0x4bf600[_0x149b('0x1e')]=qs[_0x149b('0x1e')](_0x1b5986[_0x149b('0x3f')][_0x149b('0x1e')]);}_0x4bf600[_0x149b('0x46')]=qs[_0x149b('0x47')](_0x1b5986['query'][_0x149b('0x47')]);_0x4bf600['where']=qs[_0x149b('0x3e')](_[_0x149b('0x48')](_0x1b5986['query'],_0x2a075a[_0x149b('0x3e')]),_0x109916);if(_0x1b5986[_0x149b('0x3f')][_0x149b('0x49')]){_0x4bf600[_0x149b('0x4a')]=_['merge'](_0x4bf600[_0x149b('0x4a')],{'$or':_[_0x149b('0x37')](_0x109916,function(_0x8f1cc8){if(_0x8f1cc8[_0x149b('0x3b')]!==_0x149b('0x4b')){var _0x5647c7={};_0x5647c7[_0x8f1cc8[_0x149b('0x2e')]]={'$like':'%'+_0x1b5986[_0x149b('0x3f')][_0x149b('0x49')]+'%'};return _0x5647c7;}})});}_0x4bf600=_['merge']({},_0x4bf600,_0x1b5986[_0x149b('0x4c')]);var _0x95f9f6={'where':_0x4bf600['where']};return db['CmContactHasPhone']['count'](_0x95f9f6)['then'](function(_0x5f47fe){_0x2c4e3a[_0x149b('0x21')]=_0x5f47fe;if(_0x1b5986[_0x149b('0x3f')][_0x149b('0x4d')]){_0x4bf600[_0x149b('0x4e')]=[{'all':!![]}];}return db[_0x149b('0x38')][_0x149b('0x4f')](_0x4bf600);})[_0x149b('0x28')](function(_0x118d12){_0x2c4e3a[_0x149b('0x50')]=_0x118d12;return _0x2c4e3a;})['then'](respondWithFilteredResult(_0x370eea,_0x4bf600))[_0x149b('0x51')](handleError(_0x370eea,null));};exports['show']=function(_0x6e4f2e,_0x87c99f){var _0x4f5a3a={'raw':!![],'where':{'id':_0x6e4f2e[_0x149b('0x52')]['id']}},_0x2833f6={};_0x2833f6[_0x149b('0x3c')]=_[_0x149b('0x3d')](db['CmContactHasPhone']['rawAttributes']);_0x2833f6[_0x149b('0x3f')]=_[_0x149b('0x3d')](_0x6e4f2e[_0x149b('0x3f')]);_0x2833f6[_0x149b('0x3e')]=_[_0x149b('0x41')](_0x2833f6[_0x149b('0x3c')],_0x2833f6['query']);_0x4f5a3a[_0x149b('0x40')]=_['intersection'](_0x2833f6[_0x149b('0x3c')],qs[_0x149b('0x42')](_0x6e4f2e[_0x149b('0x3f')]['fields']));_0x4f5a3a[_0x149b('0x40')]=_0x4f5a3a[_0x149b('0x40')][_0x149b('0x43')]?_0x4f5a3a[_0x149b('0x40')]:_0x2833f6[_0x149b('0x3c')];if(_0x6e4f2e['query'][_0x149b('0x4d')]){_0x4f5a3a[_0x149b('0x4e')]=[{'all':!![]}];}_0x4f5a3a=_[_0x149b('0x31')]({},_0x4f5a3a,_0x6e4f2e[_0x149b('0x4c')]);return db[_0x149b('0x38')][_0x149b('0x53')](_0x4f5a3a)['then'](handleEntityNotFound(_0x87c99f,null))[_0x149b('0x28')](respondWithResult(_0x87c99f,null))[_0x149b('0x51')](handleError(_0x87c99f,null));};exports[_0x149b('0x54')]=function(_0x5713bc,_0x44d950){return db[_0x149b('0x38')][_0x149b('0x54')](_0x5713bc[_0x149b('0x32')],{})['then'](function(_0x3a58c8){var _0x5645a2=_0x5713bc[_0x149b('0x55')][_0x149b('0x2a')]({'plain':!![]});if(!_0x5645a2)throw new Error(_0x149b('0x56'));if(_0x5645a2['role']==='user'){var _0x4e0bf2=_0x3a58c8['get']({'plain':!![]});var _0x4305f7=_0x149b('0x2b');return db[_0x149b('0x57')][_0x149b('0x53')]({'where':{'name':_0x4305f7,'userProfileId':_0x5645a2[_0x149b('0x58')]},'raw':!![]})['then'](function(_0x26eb30){if(_0x26eb30&&_0x26eb30[_0x149b('0x59')]===0x0){return db['UserProfileResource'][_0x149b('0x54')]({'name':_0x4e0bf2[_0x149b('0x2e')],'resourceId':_0x4e0bf2['id'],'type':_0x26eb30[_0x149b('0x2e')],'sectionId':_0x26eb30['id']},{})[_0x149b('0x28')](function(){return _0x3a58c8;});}else{return _0x3a58c8;}})['catch'](function(_0x401942){logger['error'](_0x149b('0x5a'),_0x401942);throw _0x401942;});}return _0x3a58c8;})[_0x149b('0x28')](respondWithResult(_0x44d950,0xc9))[_0x149b('0x51')](handleError(_0x44d950,null));};exports[_0x149b('0x27')]=function(_0xb94a73,_0x485d04){if(_0xb94a73[_0x149b('0x32')]['id']){delete _0xb94a73[_0x149b('0x32')]['id'];}return db['CmContactHasPhone'][_0x149b('0x53')]({'where':{'id':_0xb94a73[_0x149b('0x52')]['id']}})[_0x149b('0x28')](handleEntityNotFound(_0x485d04,null))[_0x149b('0x28')](saveUpdates(_0xb94a73[_0x149b('0x32')],null))['then'](respondWithResult(_0x485d04,null))[_0x149b('0x51')](handleError(_0x485d04,null));};exports['destroy']=function(_0x1145eb,_0x3aab84){return db[_0x149b('0x38')][_0x149b('0x53')]({'where':{'id':_0x1145eb[_0x149b('0x52')]['id']}})['then'](handleEntityNotFound(_0x3aab84,null))[_0x149b('0x28')](removeEntity(_0x3aab84,null))['catch'](handleError(_0x3aab84,null));};