f71d016066411d216e22bf9b38a7c3e93366c882
[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 _0x04f8=['end','offset','limit','undefined','count','set','Content-Range','json','apply','save','update','destroy','then','get','CmContactHasItems','UserProfileResource','sendStatus','error','stack','name','send','index','map','CmContactHasItem','rawAttributes','fieldName','type','key','model','keys','filters','intersection','query','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','options','rows','show','params','includeAll','include','catch','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','util','path','sox','to-csv','ejs','lodash','squel','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../config/license/util','status'];(function(_0x5b55bc,_0x18f5c6){var _0x2599c5=function(_0x56798b){while(--_0x56798b){_0x5b55bc['push'](_0x5b55bc['shift']());}};_0x2599c5(++_0x18f5c6);}(_0x04f8,0xe4));var _0x804f=function(_0x26641e,_0x40bbf3){_0x26641e=_0x26641e-0x0;var _0x1d2e42=_0x04f8[_0x26641e];return _0x1d2e42;};'use strict';var emlformat=require(_0x804f('0x0'));var rimraf=require(_0x804f('0x1'));var zipdir=require(_0x804f('0x2'));var jsonpatch=require(_0x804f('0x3'));var rp=require(_0x804f('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x804f('0x5'));var path=require(_0x804f('0x6'));var sox=require(_0x804f('0x7'));var csv=require(_0x804f('0x8'));var ejs=require(_0x804f('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x804f('0xa'));var squel=require(_0x804f('0xb'));var crypto=require('crypto');var jsforce=require(_0x804f('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x804f('0x8'));var querystring=require(_0x804f('0xd'));var Papa=require(_0x804f('0xe'));var Redis=require(_0x804f('0xf'));var authService=require(_0x804f('0x10'));var qs=require(_0x804f('0x11'));var as=require(_0x804f('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x804f('0x13'))(_0x804f('0x14'));var utils=require('../../config/utils');var config=require(_0x804f('0x15'));var licenseUtil=require(_0x804f('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x16dfbb,_0x31a149){_0x31a149=_0x31a149||0xcc;return function(_0x342328){if(_0x342328){return _0x16dfbb['sendStatus'](_0x31a149);}return _0x16dfbb[_0x804f('0x17')](_0x31a149)[_0x804f('0x18')]();};}function respondWithResult(_0x93d6d8,_0x24eb7c){_0x24eb7c=_0x24eb7c||0xc8;return function(_0x45db92){if(_0x45db92){return _0x93d6d8[_0x804f('0x17')](_0x24eb7c)['json'](_0x45db92);}};}function respondWithFilteredResult(_0x5b430a,_0xa57742){return function(_0x48f227){if(_0x48f227){var _0xb02e61=typeof _0xa57742[_0x804f('0x19')]==='undefined'&&typeof _0xa57742[_0x804f('0x1a')]===_0x804f('0x1b');var _0x112827=_0x48f227[_0x804f('0x1c')];var _0x5c38ab=_0xb02e61?0x0:_0xa57742[_0x804f('0x19')];var _0x469167=_0xb02e61?_0x48f227['count']:_0xa57742[_0x804f('0x19')]+_0xa57742[_0x804f('0x1a')];var _0x5f562b;if(_0x469167>=_0x112827){_0x469167=_0x112827;_0x5f562b=0xc8;}else{_0x5f562b=0xce;}_0x5b430a[_0x804f('0x17')](_0x5f562b);return _0x5b430a[_0x804f('0x1d')](_0x804f('0x1e'),_0x5c38ab+'-'+_0x469167+'/'+_0x112827)[_0x804f('0x1f')](_0x48f227);}return null;};}function patchUpdates(_0x9a6577){return function(_0x1ab9c1){try{jsonpatch[_0x804f('0x20')](_0x1ab9c1,_0x9a6577,!![]);}catch(_0x2abf88){return BPromise['reject'](_0x2abf88);}return _0x1ab9c1[_0x804f('0x21')]();};}function saveUpdates(_0x557d8a,_0x158885){return function(_0x34217d){if(_0x34217d){return _0x34217d[_0x804f('0x22')](_0x557d8a)['then'](function(_0x10d1f6){return _0x10d1f6;});}return null;};}function removeEntity(_0x4a8dd2,_0x54c30e){return function(_0x1b71ee){if(_0x1b71ee){return _0x1b71ee[_0x804f('0x23')]()[_0x804f('0x24')](function(){var _0x9038fe=_0x1b71ee[_0x804f('0x25')]({'plain':!![]});var _0x5cac13=_0x804f('0x26');return db[_0x804f('0x27')][_0x804f('0x23')]({'where':{'type':_0x5cac13,'resourceId':_0x9038fe['id']}})[_0x804f('0x24')](function(){return _0x1b71ee;});})[_0x804f('0x24')](function(){_0x4a8dd2['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x3bd7bc,_0x5eca25){return function(_0x1bb512){if(!_0x1bb512){_0x3bd7bc[_0x804f('0x28')](0x194);}return _0x1bb512;};}function handleError(_0x49c894,_0x16bb61){_0x16bb61=_0x16bb61||0x1f4;return function(_0x2101d4){logger[_0x804f('0x29')](_0x2101d4[_0x804f('0x2a')]);if(_0x2101d4[_0x804f('0x2b')]){delete _0x2101d4[_0x804f('0x2b')];}_0x49c894[_0x804f('0x17')](_0x16bb61)[_0x804f('0x2c')](_0x2101d4);};}exports[_0x804f('0x2d')]=function(_0x4339f1,_0x587a40){var _0x435678={},_0x4865c5={},_0x4f4b5f={'count':0x0,'rows':[]};var _0x14ffd7=_[_0x804f('0x2e')](db[_0x804f('0x2f')][_0x804f('0x30')],function(_0x19ba36){return{'name':_0x19ba36[_0x804f('0x31')],'type':_0x19ba36[_0x804f('0x32')][_0x804f('0x33')]};});_0x4865c5[_0x804f('0x34')]=_[_0x804f('0x2e')](_0x14ffd7,_0x804f('0x2b'));_0x4865c5['query']=_[_0x804f('0x35')](_0x4339f1['query']);_0x4865c5[_0x804f('0x36')]=_[_0x804f('0x37')](_0x4865c5[_0x804f('0x34')],_0x4865c5[_0x804f('0x38')]);_0x435678[_0x804f('0x39')]=_[_0x804f('0x37')](_0x4865c5[_0x804f('0x34')],qs[_0x804f('0x3a')](_0x4339f1[_0x804f('0x38')]['fields']));_0x435678['attributes']=_0x435678[_0x804f('0x39')][_0x804f('0x3b')]?_0x435678[_0x804f('0x39')]:_0x4865c5[_0x804f('0x34')];if(!_0x4339f1[_0x804f('0x38')][_0x804f('0x3c')](_0x804f('0x3d'))){_0x435678[_0x804f('0x1a')]=qs['limit'](_0x4339f1[_0x804f('0x38')][_0x804f('0x1a')]);_0x435678[_0x804f('0x19')]=qs[_0x804f('0x19')](_0x4339f1[_0x804f('0x38')][_0x804f('0x19')]);}_0x435678[_0x804f('0x3e')]=qs[_0x804f('0x3f')](_0x4339f1[_0x804f('0x38')][_0x804f('0x3f')]);_0x435678[_0x804f('0x40')]=qs[_0x804f('0x36')](_[_0x804f('0x41')](_0x4339f1[_0x804f('0x38')],_0x4865c5['filters']),_0x14ffd7);if(_0x4339f1['query'][_0x804f('0x42')]){_0x435678[_0x804f('0x40')]=_[_0x804f('0x43')](_0x435678[_0x804f('0x40')],{'$or':_[_0x804f('0x2e')](_0x14ffd7,function(_0x292541){if(_0x292541[_0x804f('0x32')]!=='VIRTUAL'){var _0x40aad8={};_0x40aad8[_0x292541['name']]={'$like':'%'+_0x4339f1[_0x804f('0x38')][_0x804f('0x42')]+'%'};return _0x40aad8;}})});}_0x435678=_['merge']({},_0x435678,_0x4339f1[_0x804f('0x44')]);var _0x1b09e3={'where':_0x435678[_0x804f('0x40')]};return db[_0x804f('0x2f')]['count'](_0x1b09e3)[_0x804f('0x24')](function(_0x1fbd32){_0x4f4b5f[_0x804f('0x1c')]=_0x1fbd32;if(_0x4339f1[_0x804f('0x38')]['includeAll']){_0x435678['include']=[{'all':!![]}];}return db[_0x804f('0x2f')]['findAll'](_0x435678);})[_0x804f('0x24')](function(_0x256469){_0x4f4b5f[_0x804f('0x45')]=_0x256469;return _0x4f4b5f;})[_0x804f('0x24')](respondWithFilteredResult(_0x587a40,_0x435678))['catch'](handleError(_0x587a40,null));};exports[_0x804f('0x46')]=function(_0x1a8d75,_0x207744){var _0x2f6da2={'raw':!![],'where':{'id':_0x1a8d75[_0x804f('0x47')]['id']}},_0x19f6a6={};_0x19f6a6['model']=_[_0x804f('0x35')](db['CmContactHasItem']['rawAttributes']);_0x19f6a6[_0x804f('0x38')]=_[_0x804f('0x35')](_0x1a8d75[_0x804f('0x38')]);_0x19f6a6['filters']=_[_0x804f('0x37')](_0x19f6a6[_0x804f('0x34')],_0x19f6a6[_0x804f('0x38')]);_0x2f6da2[_0x804f('0x39')]=_[_0x804f('0x37')](_0x19f6a6['model'],qs[_0x804f('0x3a')](_0x1a8d75[_0x804f('0x38')][_0x804f('0x3a')]));_0x2f6da2[_0x804f('0x39')]=_0x2f6da2[_0x804f('0x39')][_0x804f('0x3b')]?_0x2f6da2['attributes']:_0x19f6a6[_0x804f('0x34')];if(_0x1a8d75['query'][_0x804f('0x48')]){_0x2f6da2[_0x804f('0x49')]=[{'all':!![]}];}_0x2f6da2=_['merge']({},_0x2f6da2,_0x1a8d75[_0x804f('0x44')]);return db[_0x804f('0x2f')]['find'](_0x2f6da2)[_0x804f('0x24')](handleEntityNotFound(_0x207744,null))[_0x804f('0x24')](respondWithResult(_0x207744,null))[_0x804f('0x4a')](handleError(_0x207744,null));};exports['create']=function(_0x478c09,_0x45cc5e){return db['CmContactHasItem'][_0x804f('0x4b')](_0x478c09[_0x804f('0x4c')],{})[_0x804f('0x24')](function(_0x44f01f){var _0x2764e6=_0x478c09[_0x804f('0x4d')][_0x804f('0x25')]({'plain':!![]});if(!_0x2764e6)throw new Error(_0x804f('0x4e'));if(_0x2764e6[_0x804f('0x4f')]===_0x804f('0x4d')){var _0x145522=_0x44f01f[_0x804f('0x25')]({'plain':!![]});var _0x2c6233=_0x804f('0x26');return db[_0x804f('0x50')][_0x804f('0x51')]({'where':{'name':_0x2c6233,'userProfileId':_0x2764e6['userProfileId']},'raw':!![]})[_0x804f('0x24')](function(_0x287819){if(_0x287819&&_0x287819[_0x804f('0x52')]===0x0){return db[_0x804f('0x27')][_0x804f('0x4b')]({'name':_0x145522['name'],'resourceId':_0x145522['id'],'type':_0x287819[_0x804f('0x2b')],'sectionId':_0x287819['id']},{})[_0x804f('0x24')](function(){return _0x44f01f;});}else{return _0x44f01f;}})['catch'](function(_0x262ce4){logger[_0x804f('0x29')](_0x804f('0x53'),_0x262ce4);throw _0x262ce4;});}return _0x44f01f;})[_0x804f('0x24')](respondWithResult(_0x45cc5e,0xc9))['catch'](handleError(_0x45cc5e,null));};exports[_0x804f('0x22')]=function(_0x433d99,_0x27f67e){if(_0x433d99['body']['id']){delete _0x433d99[_0x804f('0x4c')]['id'];}return db[_0x804f('0x2f')]['find']({'where':{'id':_0x433d99[_0x804f('0x47')]['id']}})[_0x804f('0x24')](handleEntityNotFound(_0x27f67e,null))[_0x804f('0x24')](saveUpdates(_0x433d99[_0x804f('0x4c')],null))[_0x804f('0x24')](respondWithResult(_0x27f67e,null))['catch'](handleError(_0x27f67e,null));};exports[_0x804f('0x23')]=function(_0x22584e,_0x34b944){return db[_0x804f('0x2f')][_0x804f('0x51')]({'where':{'id':_0x22584e[_0x804f('0x47')]['id']}})['then'](handleEntityNotFound(_0x34b944,null))['then'](removeEntity(_0x34b944,null))[_0x804f('0x4a')](handleError(_0x34b944,null));};