Built motion from commit (unavailable).|2.5.4
[motion2.git] / server / api / cmContactHasItem / cmContactHasItem.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 _0xc4bf=['intersection','model','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','includeAll','include','rows','catch','fields','options','find','create','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','autoAssociation','body','params','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','sox','to-csv','ejs','lodash','crypto','jsforce','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','destroy','then','get','UserProfileResource','error','name','map','CmContactHasItem','rawAttributes','fieldName','type','key','keys','query','filters'];(function(_0x345f45,_0x4c7a5a){var _0x278bab=function(_0x53a96c){while(--_0x53a96c){_0x345f45['push'](_0x345f45['shift']());}};_0x278bab(++_0x4c7a5a);}(_0xc4bf,0x65));var _0xfc4b=function(_0x5d81a9,_0x5aaedd){_0x5d81a9=_0x5d81a9-0x0;var _0x1ceac5=_0xc4bf[_0x5d81a9];return _0x1ceac5;};'use strict';var pdf=require(_0xfc4b('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xfc4b('0x1'));var zipdir=require(_0xfc4b('0x2'));var jsonpatch=require(_0xfc4b('0x3'));var rp=require(_0xfc4b('0x4'));var moment=require('moment');var BPromise=require(_0xfc4b('0x5'));var Mustache=require(_0xfc4b('0x6'));var util=require('util');var path=require(_0xfc4b('0x7'));var sox=require(_0xfc4b('0x8'));var csv=require(_0xfc4b('0x9'));var ejs=require(_0xfc4b('0xa'));var fs=require('fs');var _=require(_0xfc4b('0xb'));var squel=require('squel');var crypto=require(_0xfc4b('0xc'));var jsforce=require(_0xfc4b('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xfc4b('0xe'));var Papa=require(_0xfc4b('0xf'));var Redis=require(_0xfc4b('0x10'));var authService=require('../../components/auth/service');var qs=require(_0xfc4b('0x11'));var as=require(_0xfc4b('0x12'));var hardwareService=require(_0xfc4b('0x13'));var logger=require('../../config/logger')('api');var utils=require(_0xfc4b('0x14'));var config=require(_0xfc4b('0x15'));var db=require(_0xfc4b('0x16'))['db'];function respondWithStatusCode(_0x1cacbd,_0x2e5ab6){_0x2e5ab6=_0x2e5ab6||0xcc;return function(_0x4f6266){if(_0x4f6266){return _0x1cacbd[_0xfc4b('0x17')](_0x2e5ab6);}return _0x1cacbd[_0xfc4b('0x18')](_0x2e5ab6)[_0xfc4b('0x19')]();};}function respondWithResult(_0x231744,_0x2835d3){_0x2835d3=_0x2835d3||0xc8;return function(_0x13ab2a){if(_0x13ab2a){return _0x231744[_0xfc4b('0x18')](_0x2835d3)[_0xfc4b('0x1a')](_0x13ab2a);}};}function respondWithFilteredResult(_0x5c361d,_0x5b7ae9){return function(_0x225043){if(_0x225043){var _0x47b946=_0x225043[_0xfc4b('0x1b')],_0x34ca80=_0x5b7ae9['offset'],_0x1e28d6=_0x5b7ae9[_0xfc4b('0x1c')]+_0x5b7ae9[_0xfc4b('0x1d')],_0x5ea51f;if(_0x1e28d6>=_0x47b946){_0x1e28d6=_0x47b946;_0x5ea51f=0xc8;}else{_0x5ea51f=0xce;}_0x5c361d['status'](_0x5ea51f);return _0x5c361d[_0xfc4b('0x1e')](_0xfc4b('0x1f'),_0x34ca80+'-'+_0x1e28d6+'/'+_0x47b946)['json'](_0x225043);}return null;};}function patchUpdates(_0x259404){return function(_0x4de0e3){try{jsonpatch[_0xfc4b('0x20')](_0x4de0e3,_0x259404,!![]);}catch(_0xdfb5a8){return BPromise[_0xfc4b('0x21')](_0xdfb5a8);}return _0x4de0e3[_0xfc4b('0x22')]();};}function saveUpdates(_0x30d7db,_0x58967e){return function(_0x1f5ef9){if(_0x1f5ef9){return _0x1f5ef9[_0xfc4b('0x23')](_0x30d7db)['then'](function(_0x304c58){return _0x304c58;});}return null;};}function removeEntity(_0x504176,_0x8ba450){return function(_0xa1edfb){if(_0xa1edfb){return _0xa1edfb[_0xfc4b('0x24')]()[_0xfc4b('0x25')](function(){var _0xa2c6d0=_0xa1edfb[_0xfc4b('0x26')]({'plain':!![]});var _0x166061='CmContactHasItems';return db[_0xfc4b('0x27')][_0xfc4b('0x24')]({'where':{'type':_0x166061,'resourceId':_0xa2c6d0['id']}})[_0xfc4b('0x25')](function(){return _0xa1edfb;});})[_0xfc4b('0x25')](function(){_0x504176[_0xfc4b('0x18')](0xcc)[_0xfc4b('0x19')]();});}};}function handleEntityNotFound(_0x55f5af,_0x27648b){return function(_0x9482c){if(!_0x9482c){_0x55f5af['sendStatus'](0x194);}return _0x9482c;};}function handleError(_0x10a203,_0x19005a){_0x19005a=_0x19005a||0x1f4;return function(_0x4a5aab){logger[_0xfc4b('0x28')](_0x4a5aab['stack']);if(_0x4a5aab[_0xfc4b('0x29')]){delete _0x4a5aab['name'];}_0x10a203['status'](_0x19005a)['send'](_0x4a5aab);};}exports['index']=function(_0x40a643,_0x38bc77){var _0x91dbe={},_0x46e0de={},_0x5e3b4a={'count':0x0,'rows':[]};var _0x37fb78=_[_0xfc4b('0x2a')](db[_0xfc4b('0x2b')][_0xfc4b('0x2c')],function(_0x2a92f0){return{'name':_0x2a92f0[_0xfc4b('0x2d')],'type':_0x2a92f0[_0xfc4b('0x2e')][_0xfc4b('0x2f')]};});_0x46e0de['model']=_['map'](_0x37fb78,_0xfc4b('0x29'));_0x46e0de['query']=_[_0xfc4b('0x30')](_0x40a643[_0xfc4b('0x31')]);_0x46e0de[_0xfc4b('0x32')]=_[_0xfc4b('0x33')](_0x46e0de[_0xfc4b('0x34')],_0x46e0de['query']);_0x91dbe[_0xfc4b('0x35')]=_[_0xfc4b('0x33')](_0x46e0de[_0xfc4b('0x34')],qs['fields'](_0x40a643[_0xfc4b('0x31')]['fields']));_0x91dbe[_0xfc4b('0x35')]=_0x91dbe[_0xfc4b('0x35')][_0xfc4b('0x36')]?_0x91dbe[_0xfc4b('0x35')]:_0x46e0de[_0xfc4b('0x34')];if(!_0x40a643['query'][_0xfc4b('0x37')](_0xfc4b('0x38'))){_0x91dbe[_0xfc4b('0x1d')]=qs['limit'](_0x40a643[_0xfc4b('0x31')][_0xfc4b('0x1d')]);_0x91dbe[_0xfc4b('0x1c')]=qs[_0xfc4b('0x1c')](_0x40a643[_0xfc4b('0x31')][_0xfc4b('0x1c')]);}_0x91dbe[_0xfc4b('0x39')]=qs[_0xfc4b('0x3a')](_0x40a643[_0xfc4b('0x31')]['sort']);_0x91dbe[_0xfc4b('0x3b')]=qs[_0xfc4b('0x32')](_[_0xfc4b('0x3c')](_0x40a643[_0xfc4b('0x31')],_0x46e0de['filters']),_0x37fb78);if(_0x40a643[_0xfc4b('0x31')][_0xfc4b('0x3d')]){_0x91dbe[_0xfc4b('0x3b')]=_[_0xfc4b('0x3e')](_0x91dbe['where'],{'$or':_[_0xfc4b('0x2a')](_0x37fb78,function(_0x5b7e08){if(_0x5b7e08['type']!=='VIRTUAL'){var _0x4b2952={};_0x4b2952[_0x5b7e08[_0xfc4b('0x29')]]={'$like':'%'+_0x40a643[_0xfc4b('0x31')][_0xfc4b('0x3d')]+'%'};return _0x4b2952;}})});}_0x91dbe=_[_0xfc4b('0x3e')]({},_0x91dbe,_0x40a643['options']);var _0x1ffb0e={'where':_0x91dbe[_0xfc4b('0x3b')]};return db[_0xfc4b('0x2b')]['count'](_0x1ffb0e)[_0xfc4b('0x25')](function(_0x340c1f){_0x5e3b4a['count']=_0x340c1f;if(_0x40a643['query'][_0xfc4b('0x3f')]){_0x91dbe[_0xfc4b('0x40')]=[{'all':!![]}];}return db[_0xfc4b('0x2b')]['findAll'](_0x91dbe);})[_0xfc4b('0x25')](function(_0x4d200a){_0x5e3b4a[_0xfc4b('0x41')]=_0x4d200a;return _0x5e3b4a;})['then'](respondWithFilteredResult(_0x38bc77,_0x91dbe))[_0xfc4b('0x42')](handleError(_0x38bc77,null));};exports['show']=function(_0x559fa2,_0x59258c){var _0x357f4c={'raw':!![],'where':{'id':_0x559fa2['params']['id']}},_0x409937={};_0x409937[_0xfc4b('0x34')]=_[_0xfc4b('0x30')](db[_0xfc4b('0x2b')]['rawAttributes']);_0x409937[_0xfc4b('0x31')]=_['keys'](_0x559fa2[_0xfc4b('0x31')]);_0x409937[_0xfc4b('0x32')]=_[_0xfc4b('0x33')](_0x409937['model'],_0x409937[_0xfc4b('0x31')]);_0x357f4c[_0xfc4b('0x35')]=_[_0xfc4b('0x33')](_0x409937[_0xfc4b('0x34')],qs[_0xfc4b('0x43')](_0x559fa2[_0xfc4b('0x31')][_0xfc4b('0x43')]));_0x357f4c[_0xfc4b('0x35')]=_0x357f4c[_0xfc4b('0x35')][_0xfc4b('0x36')]?_0x357f4c[_0xfc4b('0x35')]:_0x409937[_0xfc4b('0x34')];if(_0x559fa2['query'][_0xfc4b('0x3f')]){_0x357f4c['include']=[{'all':!![]}];}_0x357f4c=_[_0xfc4b('0x3e')]({},_0x357f4c,_0x559fa2[_0xfc4b('0x44')]);return db[_0xfc4b('0x2b')][_0xfc4b('0x45')](_0x357f4c)[_0xfc4b('0x25')](handleEntityNotFound(_0x59258c,null))[_0xfc4b('0x25')](respondWithResult(_0x59258c,null))[_0xfc4b('0x42')](handleError(_0x59258c,null));};exports[_0xfc4b('0x46')]=function(_0x1465cd,_0x155df7){return db['CmContactHasItem'][_0xfc4b('0x46')](_0x1465cd['body'],{})[_0xfc4b('0x25')](function(_0x51e9f9){var _0x51da12=_0x1465cd['user']['get']({'plain':!![]});if(!_0x51da12)throw new Error(_0xfc4b('0x47'));if(_0x51da12[_0xfc4b('0x48')]==='user'){var _0x212183=_0x51e9f9[_0xfc4b('0x26')]({'plain':!![]});var _0x21dfb1='CmContactHasItems';return db['UserProfileSection'][_0xfc4b('0x45')]({'where':{'name':_0x21dfb1,'userProfileId':_0x51da12['userProfileId']},'raw':!![]})[_0xfc4b('0x25')](function(_0x829056){if(_0x829056&&_0x829056[_0xfc4b('0x49')]===0x0){return db[_0xfc4b('0x27')][_0xfc4b('0x46')]({'name':_0x212183[_0xfc4b('0x29')],'resourceId':_0x212183['id'],'type':_0x829056['name'],'sectionId':_0x829056['id']},{})[_0xfc4b('0x25')](function(){return _0x51e9f9;});}else{return _0x51e9f9;}})[_0xfc4b('0x42')](function(_0x115bc7){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x115bc7);throw _0x115bc7;});}return _0x51e9f9;})['then'](respondWithResult(_0x155df7,0xc9))[_0xfc4b('0x42')](handleError(_0x155df7,null));};exports[_0xfc4b('0x23')]=function(_0x3dfa12,_0x1611cb){if(_0x3dfa12[_0xfc4b('0x4a')]['id']){delete _0x3dfa12[_0xfc4b('0x4a')]['id'];}return db[_0xfc4b('0x2b')][_0xfc4b('0x45')]({'where':{'id':_0x3dfa12[_0xfc4b('0x4b')]['id']}})[_0xfc4b('0x25')](handleEntityNotFound(_0x1611cb,null))[_0xfc4b('0x25')](saveUpdates(_0x3dfa12['body'],null))['then'](respondWithResult(_0x1611cb,null))[_0xfc4b('0x42')](handleError(_0x1611cb,null));};exports[_0xfc4b('0x24')]=function(_0x1b27d3,_0x4dd943){return db[_0xfc4b('0x2b')][_0xfc4b('0x45')]({'where':{'id':_0x1b27d3[_0xfc4b('0x4b')]['id']}})[_0xfc4b('0x25')](handleEntityNotFound(_0x4dd943,null))[_0xfc4b('0x25')](removeEntity(_0x4dd943,null))[_0xfc4b('0x42')](handleError(_0x4dd943,null));};