dbf87fb067cc01ed635f522706500dc297d4993f
[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 _0x9fc1=['UserProfileResource','end','error','name','send','index','CmContactHasItem','fieldName','key','model','map','query','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','where','pick','merge','VIRTUAL','includeAll','include','rows','catch','params','keys','rawAttributes','filters','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','destroy','eml-format','rimraf','zip-dir','request-promise','moment','mustache','util','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','limit','count','apply','then','get','CmContactHasItems'];(function(_0x51d165,_0x32ec7e){var _0x4a8f42=function(_0x191f93){while(--_0x191f93){_0x51d165['push'](_0x51d165['shift']());}};_0x4a8f42(++_0x32ec7e);}(_0x9fc1,0xd2));var _0x19fc=function(_0x45f0db,_0x5bbb3c){_0x45f0db=_0x45f0db-0x0;var _0x1f820a=_0x9fc1[_0x45f0db];return _0x1f820a;};'use strict';var emlformat=require(_0x19fc('0x0'));var rimraf=require(_0x19fc('0x1'));var zipdir=require(_0x19fc('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x19fc('0x3'));var moment=require(_0x19fc('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x19fc('0x5'));var util=require(_0x19fc('0x6'));var path=require(_0x19fc('0x7'));var sox=require(_0x19fc('0x8'));var csv=require('to-csv');var ejs=require(_0x19fc('0x9'));var fs=require('fs');var fs_extra=require(_0x19fc('0xa'));var _=require(_0x19fc('0xb'));var squel=require(_0x19fc('0xc'));var crypto=require(_0x19fc('0xd'));var jsforce=require(_0x19fc('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x19fc('0xf'));var querystring=require(_0x19fc('0x10'));var Papa=require(_0x19fc('0x11'));var Redis=require(_0x19fc('0x12'));var authService=require(_0x19fc('0x13'));var qs=require(_0x19fc('0x14'));var as=require(_0x19fc('0x15'));var hardwareService=require(_0x19fc('0x16'));var logger=require(_0x19fc('0x17'))(_0x19fc('0x18'));var utils=require(_0x19fc('0x19'));var config=require(_0x19fc('0x1a'));var licenseUtil=require(_0x19fc('0x1b'));var db=require(_0x19fc('0x1c'))['db'];function respondWithStatusCode(_0x36e431,_0xa9ad87){_0xa9ad87=_0xa9ad87||0xcc;return function(_0x5c6989){if(_0x5c6989){return _0x36e431[_0x19fc('0x1d')](_0xa9ad87);}return _0x36e431['status'](_0xa9ad87)['end']();};}function respondWithResult(_0x11f635,_0x136c9c){_0x136c9c=_0x136c9c||0xc8;return function(_0x24c8f2){if(_0x24c8f2){return _0x11f635[_0x19fc('0x1e')](_0x136c9c)[_0x19fc('0x1f')](_0x24c8f2);}};}function respondWithFilteredResult(_0x144572,_0x4f91aa){return function(_0x5b7344){if(_0x5b7344){var _0x22be5a=typeof _0x4f91aa[_0x19fc('0x20')]==='undefined'&&typeof _0x4f91aa[_0x19fc('0x21')]==='undefined';var _0x4ab80d=_0x5b7344[_0x19fc('0x22')];var _0x2d9cee=_0x22be5a?0x0:_0x4f91aa[_0x19fc('0x20')];var _0x3ec1ed=_0x22be5a?_0x5b7344[_0x19fc('0x22')]:_0x4f91aa[_0x19fc('0x20')]+_0x4f91aa[_0x19fc('0x21')];var _0x4c29ba;if(_0x3ec1ed>=_0x4ab80d){_0x3ec1ed=_0x4ab80d;_0x4c29ba=0xc8;}else{_0x4c29ba=0xce;}_0x144572[_0x19fc('0x1e')](_0x4c29ba);return _0x144572['set']('Content-Range',_0x2d9cee+'-'+_0x3ec1ed+'/'+_0x4ab80d)[_0x19fc('0x1f')](_0x5b7344);}return null;};}function patchUpdates(_0x3288fc){return function(_0x26cadf){try{jsonpatch[_0x19fc('0x23')](_0x26cadf,_0x3288fc,!![]);}catch(_0x101e1c){return BPromise['reject'](_0x101e1c);}return _0x26cadf['save']();};}function saveUpdates(_0x489286,_0x12b946){return function(_0x2f0a01){if(_0x2f0a01){return _0x2f0a01['update'](_0x489286)[_0x19fc('0x24')](function(_0xfffa70){return _0xfffa70;});}return null;};}function removeEntity(_0x258e65,_0x5c4509){return function(_0x1fa1c7){if(_0x1fa1c7){return _0x1fa1c7['destroy']()[_0x19fc('0x24')](function(){var _0x5b4448=_0x1fa1c7[_0x19fc('0x25')]({'plain':!![]});var _0x223003=_0x19fc('0x26');return db[_0x19fc('0x27')]['destroy']({'where':{'type':_0x223003,'resourceId':_0x5b4448['id']}})[_0x19fc('0x24')](function(){return _0x1fa1c7;});})[_0x19fc('0x24')](function(){_0x258e65[_0x19fc('0x1e')](0xcc)[_0x19fc('0x28')]();});}};}function handleEntityNotFound(_0x18fdec,_0x33ddda){return function(_0x773f05){if(!_0x773f05){_0x18fdec['sendStatus'](0x194);}return _0x773f05;};}function handleError(_0x5bf802,_0x559ac4){_0x559ac4=_0x559ac4||0x1f4;return function(_0x3b9089){logger[_0x19fc('0x29')](_0x3b9089['stack']);if(_0x3b9089[_0x19fc('0x2a')]){delete _0x3b9089[_0x19fc('0x2a')];}_0x5bf802[_0x19fc('0x1e')](_0x559ac4)[_0x19fc('0x2b')](_0x3b9089);};}exports[_0x19fc('0x2c')]=function(_0x177254,_0xb0e629){var _0x589c5e={},_0x34ebe0={},_0xea4a22={'count':0x0,'rows':[]};var _0x2eeb76=_['map'](db[_0x19fc('0x2d')]['rawAttributes'],function(_0x330231){return{'name':_0x330231[_0x19fc('0x2e')],'type':_0x330231['type'][_0x19fc('0x2f')]};});_0x34ebe0[_0x19fc('0x30')]=_[_0x19fc('0x31')](_0x2eeb76,_0x19fc('0x2a'));_0x34ebe0['query']=_['keys'](_0x177254[_0x19fc('0x32')]);_0x34ebe0['filters']=_[_0x19fc('0x33')](_0x34ebe0[_0x19fc('0x30')],_0x34ebe0['query']);_0x589c5e['attributes']=_[_0x19fc('0x33')](_0x34ebe0[_0x19fc('0x30')],qs[_0x19fc('0x34')](_0x177254[_0x19fc('0x32')][_0x19fc('0x34')]));_0x589c5e[_0x19fc('0x35')]=_0x589c5e[_0x19fc('0x35')]['length']?_0x589c5e['attributes']:_0x34ebe0[_0x19fc('0x30')];if(!_0x177254['query'][_0x19fc('0x36')](_0x19fc('0x37'))){_0x589c5e[_0x19fc('0x21')]=qs[_0x19fc('0x21')](_0x177254[_0x19fc('0x32')]['limit']);_0x589c5e[_0x19fc('0x20')]=qs[_0x19fc('0x20')](_0x177254[_0x19fc('0x32')][_0x19fc('0x20')]);}_0x589c5e[_0x19fc('0x38')]=qs[_0x19fc('0x39')](_0x177254[_0x19fc('0x32')]['sort']);_0x589c5e[_0x19fc('0x3a')]=qs['filters'](_[_0x19fc('0x3b')](_0x177254[_0x19fc('0x32')],_0x34ebe0['filters']),_0x2eeb76);if(_0x177254[_0x19fc('0x32')]['filter']){_0x589c5e[_0x19fc('0x3a')]=_[_0x19fc('0x3c')](_0x589c5e['where'],{'$or':_['map'](_0x2eeb76,function(_0x5635af){if(_0x5635af['type']!==_0x19fc('0x3d')){var _0x5b416c={};_0x5b416c[_0x5635af['name']]={'$like':'%'+_0x177254[_0x19fc('0x32')]['filter']+'%'};return _0x5b416c;}})});}_0x589c5e=_[_0x19fc('0x3c')]({},_0x589c5e,_0x177254['options']);var _0x43c5a5={'where':_0x589c5e[_0x19fc('0x3a')]};return db[_0x19fc('0x2d')][_0x19fc('0x22')](_0x43c5a5)[_0x19fc('0x24')](function(_0x402cf1){_0xea4a22[_0x19fc('0x22')]=_0x402cf1;if(_0x177254[_0x19fc('0x32')][_0x19fc('0x3e')]){_0x589c5e[_0x19fc('0x3f')]=[{'all':!![]}];}return db[_0x19fc('0x2d')]['findAll'](_0x589c5e);})[_0x19fc('0x24')](function(_0x5dfbc7){_0xea4a22[_0x19fc('0x40')]=_0x5dfbc7;return _0xea4a22;})[_0x19fc('0x24')](respondWithFilteredResult(_0xb0e629,_0x589c5e))[_0x19fc('0x41')](handleError(_0xb0e629,null));};exports['show']=function(_0xa266f,_0x3b8f81){var _0x11b51d={'raw':!![],'where':{'id':_0xa266f[_0x19fc('0x42')]['id']}},_0x46b654={};_0x46b654['model']=_[_0x19fc('0x43')](db[_0x19fc('0x2d')][_0x19fc('0x44')]);_0x46b654[_0x19fc('0x32')]=_['keys'](_0xa266f[_0x19fc('0x32')]);_0x46b654[_0x19fc('0x45')]=_[_0x19fc('0x33')](_0x46b654['model'],_0x46b654['query']);_0x11b51d['attributes']=_[_0x19fc('0x33')](_0x46b654[_0x19fc('0x30')],qs[_0x19fc('0x34')](_0xa266f[_0x19fc('0x32')][_0x19fc('0x34')]));_0x11b51d[_0x19fc('0x35')]=_0x11b51d[_0x19fc('0x35')]['length']?_0x11b51d[_0x19fc('0x35')]:_0x46b654[_0x19fc('0x30')];if(_0xa266f['query'][_0x19fc('0x3e')]){_0x11b51d[_0x19fc('0x3f')]=[{'all':!![]}];}_0x11b51d=_[_0x19fc('0x3c')]({},_0x11b51d,_0xa266f[_0x19fc('0x46')]);return db[_0x19fc('0x2d')][_0x19fc('0x47')](_0x11b51d)[_0x19fc('0x24')](handleEntityNotFound(_0x3b8f81,null))[_0x19fc('0x24')](respondWithResult(_0x3b8f81,null))[_0x19fc('0x41')](handleError(_0x3b8f81,null));};exports[_0x19fc('0x48')]=function(_0x5a74ce,_0x5b64c9){return db[_0x19fc('0x2d')][_0x19fc('0x48')](_0x5a74ce[_0x19fc('0x49')],{})['then'](function(_0x1f41f0){var _0x581a9f=_0x5a74ce[_0x19fc('0x4a')][_0x19fc('0x25')]({'plain':!![]});if(!_0x581a9f)throw new Error(_0x19fc('0x4b'));if(_0x581a9f[_0x19fc('0x4c')]===_0x19fc('0x4a')){var _0x4423ef=_0x1f41f0['get']({'plain':!![]});var _0x2b9f13=_0x19fc('0x26');return db[_0x19fc('0x4d')][_0x19fc('0x47')]({'where':{'name':_0x2b9f13,'userProfileId':_0x581a9f[_0x19fc('0x4e')]},'raw':!![]})[_0x19fc('0x24')](function(_0x547304){if(_0x547304&&_0x547304[_0x19fc('0x4f')]===0x0){return db[_0x19fc('0x27')][_0x19fc('0x48')]({'name':_0x4423ef[_0x19fc('0x2a')],'resourceId':_0x4423ef['id'],'type':_0x547304['name'],'sectionId':_0x547304['id']},{})[_0x19fc('0x24')](function(){return _0x1f41f0;});}else{return _0x1f41f0;}})['catch'](function(_0xce328d){logger[_0x19fc('0x29')](_0x19fc('0x50'),_0xce328d);throw _0xce328d;});}return _0x1f41f0;})[_0x19fc('0x24')](respondWithResult(_0x5b64c9,0xc9))[_0x19fc('0x41')](handleError(_0x5b64c9,null));};exports[_0x19fc('0x51')]=function(_0x5defb3,_0x42a67f){if(_0x5defb3[_0x19fc('0x49')]['id']){delete _0x5defb3['body']['id'];}return db[_0x19fc('0x2d')][_0x19fc('0x47')]({'where':{'id':_0x5defb3[_0x19fc('0x42')]['id']}})[_0x19fc('0x24')](handleEntityNotFound(_0x42a67f,null))[_0x19fc('0x24')](saveUpdates(_0x5defb3[_0x19fc('0x49')],null))[_0x19fc('0x24')](respondWithResult(_0x42a67f,null))[_0x19fc('0x41')](handleError(_0x42a67f,null));};exports[_0x19fc('0x52')]=function(_0x55b924,_0x2ad749){return db[_0x19fc('0x2d')][_0x19fc('0x47')]({'where':{'id':_0x55b924[_0x19fc('0x42')]['id']}})[_0x19fc('0x24')](handleEntityNotFound(_0x2ad749,null))['then'](removeEntity(_0x2ad749,null))[_0x19fc('0x41')](handleError(_0x2ad749,null));};