40805c79dfd34e65686ee74caf45afc24411d85e
[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 _0x98f7=['query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','type','VIRTUAL','name','options','CmContactHasItem','findAll','catch','params','includeAll','include','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','destroy','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','crypto','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','sendStatus','status','end','json','count','offset','limit','apply','reject','save','update','then','get','CmContactHasItems','error','stack','send','index','rawAttributes','key','map'];(function(_0x10dfdf,_0x36b623){var _0x4d857d=function(_0x4683ee){while(--_0x4683ee){_0x10dfdf['push'](_0x10dfdf['shift']());}};_0x4d857d(++_0x36b623);}(_0x98f7,0x116));var _0x798f=function(_0x308c7e,_0x35875c){_0x308c7e=_0x308c7e-0x0;var _0xa75795=_0x98f7[_0x308c7e];return _0xa75795;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x798f('0x0'));var rimraf=require(_0x798f('0x1'));var zipdir=require(_0x798f('0x2'));var jsonpatch=require(_0x798f('0x3'));var rp=require(_0x798f('0x4'));var moment=require('moment');var BPromise=require(_0x798f('0x5'));var Mustache=require(_0x798f('0x6'));var util=require(_0x798f('0x7'));var path=require(_0x798f('0x8'));var sox=require(_0x798f('0x9'));var csv=require(_0x798f('0xa'));var ejs=require(_0x798f('0xb'));var fs=require('fs');var _=require(_0x798f('0xc'));var squel=require('squel');var crypto=require(_0x798f('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x798f('0xe'));var toCsv=require(_0x798f('0xa'));var querystring=require(_0x798f('0xf'));var Papa=require('papaparse');var Redis=require(_0x798f('0x10'));var authService=require(_0x798f('0x11'));var qs=require(_0x798f('0x12'));var as=require(_0x798f('0x13'));var hardwareService=require(_0x798f('0x14'));var logger=require(_0x798f('0x15'))(_0x798f('0x16'));var utils=require(_0x798f('0x17'));var config=require(_0x798f('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1e9987,_0x146ec6){_0x146ec6=_0x146ec6||0xcc;return function(_0x5ed923){if(_0x5ed923){return _0x1e9987[_0x798f('0x19')](_0x146ec6);}return _0x1e9987[_0x798f('0x1a')](_0x146ec6)[_0x798f('0x1b')]();};}function respondWithResult(_0x4d634f,_0x44bf83){_0x44bf83=_0x44bf83||0xc8;return function(_0x478941){if(_0x478941){return _0x4d634f[_0x798f('0x1a')](_0x44bf83)[_0x798f('0x1c')](_0x478941);}};}function respondWithFilteredResult(_0x21bbf8,_0x31f64b){return function(_0x3828ec){if(_0x3828ec){var _0xcc00fa=_0x3828ec[_0x798f('0x1d')],_0x3d7f80=_0x31f64b[_0x798f('0x1e')],_0x34bd56=_0x31f64b['offset']+_0x31f64b[_0x798f('0x1f')],_0x20e8ef;if(_0x34bd56>=_0xcc00fa){_0x34bd56=_0xcc00fa;_0x20e8ef=0xc8;}else{_0x20e8ef=0xce;}_0x21bbf8[_0x798f('0x1a')](_0x20e8ef);return _0x21bbf8['set']('Content-Range',_0x3d7f80+'-'+_0x34bd56+'/'+_0xcc00fa)[_0x798f('0x1c')](_0x3828ec);}return null;};}function patchUpdates(_0x3b89dc){return function(_0xe6820e){try{jsonpatch[_0x798f('0x20')](_0xe6820e,_0x3b89dc,!![]);}catch(_0x3b0160){return BPromise[_0x798f('0x21')](_0x3b0160);}return _0xe6820e[_0x798f('0x22')]();};}function saveUpdates(_0x22744d,_0x59856c){return function(_0x52fc72){if(_0x52fc72){return _0x52fc72[_0x798f('0x23')](_0x22744d)[_0x798f('0x24')](function(_0x48e8a5){return _0x48e8a5;});}return null;};}function removeEntity(_0x3af402,_0x19d9d7){return function(_0x4beffe){if(_0x4beffe){return _0x4beffe['destroy']()['then'](function(){var _0x3bcb0b=_0x4beffe[_0x798f('0x25')]({'plain':!![]});var _0x3db718=_0x798f('0x26');return db['UserProfileResource']['destroy']({'where':{'type':_0x3db718,'resourceId':_0x3bcb0b['id']}})[_0x798f('0x24')](function(){return _0x4beffe;});})[_0x798f('0x24')](function(){_0x3af402[_0x798f('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x52d138,_0x115aed){return function(_0x4abb70){if(!_0x4abb70){_0x52d138['sendStatus'](0x194);}return _0x4abb70;};}function handleError(_0xd1bef1,_0x2ae155){_0x2ae155=_0x2ae155||0x1f4;return function(_0x57412d){logger[_0x798f('0x27')](_0x57412d[_0x798f('0x28')]);if(_0x57412d['name']){delete _0x57412d['name'];}_0xd1bef1[_0x798f('0x1a')](_0x2ae155)[_0x798f('0x29')](_0x57412d);};}exports[_0x798f('0x2a')]=function(_0x3e6a70,_0x4254dd){var _0x591d77={},_0x3bc81c={},_0x2cead4={'count':0x0,'rows':[]};var _0x20f222=_['map'](db['CmContactHasItem'][_0x798f('0x2b')],function(_0x44598d){return{'name':_0x44598d['fieldName'],'type':_0x44598d['type'][_0x798f('0x2c')]};});_0x3bc81c['model']=_[_0x798f('0x2d')](_0x20f222,'name');_0x3bc81c[_0x798f('0x2e')]=_[_0x798f('0x2f')](_0x3e6a70['query']);_0x3bc81c[_0x798f('0x30')]=_[_0x798f('0x31')](_0x3bc81c[_0x798f('0x32')],_0x3bc81c['query']);_0x591d77[_0x798f('0x33')]=_[_0x798f('0x31')](_0x3bc81c['model'],qs[_0x798f('0x34')](_0x3e6a70[_0x798f('0x2e')][_0x798f('0x34')]));_0x591d77[_0x798f('0x33')]=_0x591d77['attributes'][_0x798f('0x35')]?_0x591d77['attributes']:_0x3bc81c['model'];if(!_0x3e6a70['query'][_0x798f('0x36')](_0x798f('0x37'))){_0x591d77[_0x798f('0x1f')]=qs[_0x798f('0x1f')](_0x3e6a70['query'][_0x798f('0x1f')]);_0x591d77['offset']=qs[_0x798f('0x1e')](_0x3e6a70[_0x798f('0x2e')][_0x798f('0x1e')]);}_0x591d77[_0x798f('0x38')]=qs['sort'](_0x3e6a70[_0x798f('0x2e')][_0x798f('0x39')]);_0x591d77[_0x798f('0x3a')]=qs['filters'](_['pick'](_0x3e6a70[_0x798f('0x2e')],_0x3bc81c[_0x798f('0x30')]),_0x20f222);if(_0x3e6a70[_0x798f('0x2e')][_0x798f('0x3b')]){_0x591d77[_0x798f('0x3a')]=_[_0x798f('0x3c')](_0x591d77['where'],{'$or':_[_0x798f('0x2d')](_0x20f222,function(_0x18d214){if(_0x18d214[_0x798f('0x3d')]!==_0x798f('0x3e')){var _0x4c58d5={};_0x4c58d5[_0x18d214[_0x798f('0x3f')]]={'$like':'%'+_0x3e6a70[_0x798f('0x2e')][_0x798f('0x3b')]+'%'};return _0x4c58d5;}})});}_0x591d77=_['merge']({},_0x591d77,_0x3e6a70[_0x798f('0x40')]);var _0x299a96={'where':_0x591d77[_0x798f('0x3a')]};return db[_0x798f('0x41')]['count'](_0x299a96)[_0x798f('0x24')](function(_0x268e9e){_0x2cead4['count']=_0x268e9e;if(_0x3e6a70['query']['includeAll']){_0x591d77['include']=[{'all':!![]}];}return db['CmContactHasItem'][_0x798f('0x42')](_0x591d77);})[_0x798f('0x24')](function(_0x1b75a8){_0x2cead4['rows']=_0x1b75a8;return _0x2cead4;})[_0x798f('0x24')](respondWithFilteredResult(_0x4254dd,_0x591d77))[_0x798f('0x43')](handleError(_0x4254dd,null));};exports['show']=function(_0x5584b5,_0x439e3d){var _0x52900d={'raw':!![],'where':{'id':_0x5584b5[_0x798f('0x44')]['id']}},_0x374436={};_0x374436[_0x798f('0x32')]=_[_0x798f('0x2f')](db['CmContactHasItem']['rawAttributes']);_0x374436[_0x798f('0x2e')]=_[_0x798f('0x2f')](_0x5584b5[_0x798f('0x2e')]);_0x374436['filters']=_[_0x798f('0x31')](_0x374436[_0x798f('0x32')],_0x374436['query']);_0x52900d[_0x798f('0x33')]=_['intersection'](_0x374436[_0x798f('0x32')],qs[_0x798f('0x34')](_0x5584b5[_0x798f('0x2e')]['fields']));_0x52900d['attributes']=_0x52900d['attributes']['length']?_0x52900d['attributes']:_0x374436['model'];if(_0x5584b5[_0x798f('0x2e')][_0x798f('0x45')]){_0x52900d[_0x798f('0x46')]=[{'all':!![]}];}_0x52900d=_[_0x798f('0x3c')]({},_0x52900d,_0x5584b5[_0x798f('0x40')]);return db[_0x798f('0x41')][_0x798f('0x47')](_0x52900d)[_0x798f('0x24')](handleEntityNotFound(_0x439e3d,null))['then'](respondWithResult(_0x439e3d,null))[_0x798f('0x43')](handleError(_0x439e3d,null));};exports[_0x798f('0x48')]=function(_0x547496,_0x57b709){return db[_0x798f('0x41')][_0x798f('0x48')](_0x547496['body'],{})[_0x798f('0x24')](function(_0x3bd1fe){var _0x1ca1ab=_0x547496[_0x798f('0x49')][_0x798f('0x25')]({'plain':!![]});if(!_0x1ca1ab)throw new Error(_0x798f('0x4a'));if(_0x1ca1ab[_0x798f('0x4b')]===_0x798f('0x49')){var _0x2b5c06=_0x3bd1fe['get']({'plain':!![]});var _0x388254=_0x798f('0x26');return db[_0x798f('0x4c')][_0x798f('0x47')]({'where':{'name':_0x388254,'userProfileId':_0x1ca1ab['userProfileId']},'raw':!![]})[_0x798f('0x24')](function(_0x260b13){if(_0x260b13&&_0x260b13[_0x798f('0x4d')]===0x0){return db['UserProfileResource'][_0x798f('0x48')]({'name':_0x2b5c06[_0x798f('0x3f')],'resourceId':_0x2b5c06['id'],'type':_0x260b13[_0x798f('0x3f')],'sectionId':_0x260b13['id']},{})['then'](function(){return _0x3bd1fe;});}else{return _0x3bd1fe;}})[_0x798f('0x43')](function(_0x4edf7e){logger[_0x798f('0x27')](_0x798f('0x4e'),_0x4edf7e);throw _0x4edf7e;});}return _0x3bd1fe;})[_0x798f('0x24')](respondWithResult(_0x57b709,0xc9))[_0x798f('0x43')](handleError(_0x57b709,null));};exports[_0x798f('0x23')]=function(_0x13894a,_0x3b7079){if(_0x13894a[_0x798f('0x4f')]['id']){delete _0x13894a[_0x798f('0x4f')]['id'];}return db[_0x798f('0x41')][_0x798f('0x47')]({'where':{'id':_0x13894a[_0x798f('0x44')]['id']}})['then'](handleEntityNotFound(_0x3b7079,null))[_0x798f('0x24')](saveUpdates(_0x13894a['body'],null))[_0x798f('0x24')](respondWithResult(_0x3b7079,null))['catch'](handleError(_0x3b7079,null));};exports[_0x798f('0x50')]=function(_0x933c1c,_0x58e0cd){return db['CmContactHasItem'][_0x798f('0x47')]({'where':{'id':_0x933c1c[_0x798f('0x44')]['id']}})[_0x798f('0x24')](handleEntityNotFound(_0x58e0cd,null))['then'](removeEntity(_0x58e0cd,null))[_0x798f('0x43')](handleError(_0x58e0cd,null));};