Built motion from commit f74363e9.|2.6.34
[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 _0x6afd=['merge','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','error','eml-format','rimraf','moment','bluebird','util','sox','to-csv','fs-extra','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','get','CmContactHasItems','UserProfileResource','stack','name','send','index','map','CmContactHasItem','rawAttributes','fieldName','model','keys','filters','intersection','query','fields','attributes','length','hasOwnProperty','nolimit','order','sort','filter','where','type','VIRTUAL','options','includeAll','include','findAll','rows','catch','params'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x6afd,0x101));var _0xd6af=function(_0x433a86,_0x175b5c){_0x433a86=_0x433a86-0x0;var _0x23000c=_0x6afd[_0x433a86];return _0x23000c;};'use strict';var emlformat=require(_0xd6af('0x0'));var rimraf=require(_0xd6af('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xd6af('0x2'));var BPromise=require(_0xd6af('0x3'));var Mustache=require('mustache');var util=require(_0xd6af('0x4'));var path=require('path');var sox=require(_0xd6af('0x5'));var csv=require(_0xd6af('0x6'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xd6af('0x7'));var _=require(_0xd6af('0x8'));var squel=require(_0xd6af('0x9'));var crypto=require('crypto');var jsforce=require(_0xd6af('0xa'));var deskjs=require(_0xd6af('0xb'));var toCsv=require(_0xd6af('0x6'));var querystring=require(_0xd6af('0xc'));var Papa=require(_0xd6af('0xd'));var Redis=require(_0xd6af('0xe'));var authService=require('../../components/auth/service');var qs=require(_0xd6af('0xf'));var as=require(_0xd6af('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xd6af('0x11'));var utils=require(_0xd6af('0x12'));var config=require(_0xd6af('0x13'));var licenseUtil=require(_0xd6af('0x14'));var db=require(_0xd6af('0x15'))['db'];function respondWithStatusCode(_0x5221f6,_0x347cdb){_0x347cdb=_0x347cdb||0xcc;return function(_0x26a20b){if(_0x26a20b){return _0x5221f6[_0xd6af('0x16')](_0x347cdb);}return _0x5221f6[_0xd6af('0x17')](_0x347cdb)[_0xd6af('0x18')]();};}function respondWithResult(_0x993eac,_0x4a91f1){_0x4a91f1=_0x4a91f1||0xc8;return function(_0x5ad958){if(_0x5ad958){return _0x993eac[_0xd6af('0x17')](_0x4a91f1)[_0xd6af('0x19')](_0x5ad958);}};}function respondWithFilteredResult(_0x4d839c,_0x2c1bad){return function(_0x3f9590){if(_0x3f9590){var _0x3ef1e4=typeof _0x2c1bad['offset']==='undefined'&&typeof _0x2c1bad['limit']==='undefined';var _0x326d45=_0x3f9590[_0xd6af('0x1a')];var _0x367dd3=_0x3ef1e4?0x0:_0x2c1bad[_0xd6af('0x1b')];var _0x31c557=_0x3ef1e4?_0x3f9590[_0xd6af('0x1a')]:_0x2c1bad[_0xd6af('0x1b')]+_0x2c1bad[_0xd6af('0x1c')];var _0x1e4d74;if(_0x31c557>=_0x326d45){_0x31c557=_0x326d45;_0x1e4d74=0xc8;}else{_0x1e4d74=0xce;}_0x4d839c[_0xd6af('0x17')](_0x1e4d74);return _0x4d839c[_0xd6af('0x1d')](_0xd6af('0x1e'),_0x367dd3+'-'+_0x31c557+'/'+_0x326d45)[_0xd6af('0x19')](_0x3f9590);}return null;};}function patchUpdates(_0x520bf2){return function(_0x4c0a16){try{jsonpatch[_0xd6af('0x1f')](_0x4c0a16,_0x520bf2,!![]);}catch(_0x1e327d){return BPromise[_0xd6af('0x20')](_0x1e327d);}return _0x4c0a16[_0xd6af('0x21')]();};}function saveUpdates(_0x24cd4f,_0x3cf5e1){return function(_0x104afc){if(_0x104afc){return _0x104afc[_0xd6af('0x22')](_0x24cd4f)[_0xd6af('0x23')](function(_0xa6bdfb){return _0xa6bdfb;});}return null;};}function removeEntity(_0x4acc5d,_0x22deb5){return function(_0x21dbd4){if(_0x21dbd4){return _0x21dbd4[_0xd6af('0x24')]()[_0xd6af('0x23')](function(){var _0x14c1d5=_0x21dbd4[_0xd6af('0x25')]({'plain':!![]});var _0x301526=_0xd6af('0x26');return db[_0xd6af('0x27')][_0xd6af('0x24')]({'where':{'type':_0x301526,'resourceId':_0x14c1d5['id']}})['then'](function(){return _0x21dbd4;});})[_0xd6af('0x23')](function(){_0x4acc5d[_0xd6af('0x17')](0xcc)['end']();});}};}function handleEntityNotFound(_0x223f67,_0x25a323){return function(_0x593d99){if(!_0x593d99){_0x223f67['sendStatus'](0x194);}return _0x593d99;};}function handleError(_0x5ad58b,_0x51ac67){_0x51ac67=_0x51ac67||0x1f4;return function(_0x45d0c3){logger['error'](_0x45d0c3[_0xd6af('0x28')]);if(_0x45d0c3['name']){delete _0x45d0c3[_0xd6af('0x29')];}_0x5ad58b[_0xd6af('0x17')](_0x51ac67)[_0xd6af('0x2a')](_0x45d0c3);};}exports[_0xd6af('0x2b')]=function(_0x46e181,_0x2ef5c9){var _0x4984ea={},_0x4396ff={},_0x30bf83={'count':0x0,'rows':[]};var _0x12d4b7=_[_0xd6af('0x2c')](db[_0xd6af('0x2d')][_0xd6af('0x2e')],function(_0x2f1a79){return{'name':_0x2f1a79[_0xd6af('0x2f')],'type':_0x2f1a79['type']['key']};});_0x4396ff[_0xd6af('0x30')]=_['map'](_0x12d4b7,_0xd6af('0x29'));_0x4396ff['query']=_[_0xd6af('0x31')](_0x46e181['query']);_0x4396ff[_0xd6af('0x32')]=_[_0xd6af('0x33')](_0x4396ff[_0xd6af('0x30')],_0x4396ff[_0xd6af('0x34')]);_0x4984ea['attributes']=_[_0xd6af('0x33')](_0x4396ff[_0xd6af('0x30')],qs[_0xd6af('0x35')](_0x46e181['query'][_0xd6af('0x35')]));_0x4984ea[_0xd6af('0x36')]=_0x4984ea[_0xd6af('0x36')][_0xd6af('0x37')]?_0x4984ea['attributes']:_0x4396ff['model'];if(!_0x46e181[_0xd6af('0x34')][_0xd6af('0x38')](_0xd6af('0x39'))){_0x4984ea['limit']=qs[_0xd6af('0x1c')](_0x46e181[_0xd6af('0x34')]['limit']);_0x4984ea['offset']=qs[_0xd6af('0x1b')](_0x46e181[_0xd6af('0x34')]['offset']);}_0x4984ea[_0xd6af('0x3a')]=qs['sort'](_0x46e181['query'][_0xd6af('0x3b')]);_0x4984ea['where']=qs[_0xd6af('0x32')](_['pick'](_0x46e181[_0xd6af('0x34')],_0x4396ff[_0xd6af('0x32')]),_0x12d4b7);if(_0x46e181[_0xd6af('0x34')][_0xd6af('0x3c')]){_0x4984ea['where']=_['merge'](_0x4984ea[_0xd6af('0x3d')],{'$or':_[_0xd6af('0x2c')](_0x12d4b7,function(_0x98d7c){if(_0x98d7c[_0xd6af('0x3e')]!==_0xd6af('0x3f')){var _0x5990b5={};_0x5990b5[_0x98d7c[_0xd6af('0x29')]]={'$like':'%'+_0x46e181[_0xd6af('0x34')][_0xd6af('0x3c')]+'%'};return _0x5990b5;}})});}_0x4984ea=_['merge']({},_0x4984ea,_0x46e181[_0xd6af('0x40')]);var _0x1729d2={'where':_0x4984ea[_0xd6af('0x3d')]};return db[_0xd6af('0x2d')][_0xd6af('0x1a')](_0x1729d2)[_0xd6af('0x23')](function(_0x27dece){_0x30bf83[_0xd6af('0x1a')]=_0x27dece;if(_0x46e181[_0xd6af('0x34')][_0xd6af('0x41')]){_0x4984ea[_0xd6af('0x42')]=[{'all':!![]}];}return db[_0xd6af('0x2d')][_0xd6af('0x43')](_0x4984ea);})[_0xd6af('0x23')](function(_0x30c81a){_0x30bf83[_0xd6af('0x44')]=_0x30c81a;return _0x30bf83;})['then'](respondWithFilteredResult(_0x2ef5c9,_0x4984ea))[_0xd6af('0x45')](handleError(_0x2ef5c9,null));};exports['show']=function(_0x429f8d,_0x3c98c4){var _0x1e967a={'raw':!![],'where':{'id':_0x429f8d[_0xd6af('0x46')]['id']}},_0x567b38={};_0x567b38[_0xd6af('0x30')]=_[_0xd6af('0x31')](db[_0xd6af('0x2d')][_0xd6af('0x2e')]);_0x567b38['query']=_['keys'](_0x429f8d['query']);_0x567b38['filters']=_[_0xd6af('0x33')](_0x567b38[_0xd6af('0x30')],_0x567b38['query']);_0x1e967a['attributes']=_[_0xd6af('0x33')](_0x567b38[_0xd6af('0x30')],qs[_0xd6af('0x35')](_0x429f8d[_0xd6af('0x34')][_0xd6af('0x35')]));_0x1e967a[_0xd6af('0x36')]=_0x1e967a[_0xd6af('0x36')][_0xd6af('0x37')]?_0x1e967a[_0xd6af('0x36')]:_0x567b38['model'];if(_0x429f8d[_0xd6af('0x34')]['includeAll']){_0x1e967a[_0xd6af('0x42')]=[{'all':!![]}];}_0x1e967a=_[_0xd6af('0x47')]({},_0x1e967a,_0x429f8d[_0xd6af('0x40')]);return db['CmContactHasItem'][_0xd6af('0x48')](_0x1e967a)[_0xd6af('0x23')](handleEntityNotFound(_0x3c98c4,null))[_0xd6af('0x23')](respondWithResult(_0x3c98c4,null))[_0xd6af('0x45')](handleError(_0x3c98c4,null));};exports['create']=function(_0x64db24,_0x1b4e42){return db[_0xd6af('0x2d')][_0xd6af('0x49')](_0x64db24[_0xd6af('0x4a')],{})[_0xd6af('0x23')](function(_0x449c6b){var _0x54781d=_0x64db24[_0xd6af('0x4b')]['get']({'plain':!![]});if(!_0x54781d)throw new Error(_0xd6af('0x4c'));if(_0x54781d[_0xd6af('0x4d')]===_0xd6af('0x4b')){var _0xef2132=_0x449c6b['get']({'plain':!![]});var _0x39fe38=_0xd6af('0x26');return db[_0xd6af('0x4e')][_0xd6af('0x48')]({'where':{'name':_0x39fe38,'userProfileId':_0x54781d[_0xd6af('0x4f')]},'raw':!![]})['then'](function(_0x592e7b){if(_0x592e7b&&_0x592e7b[_0xd6af('0x50')]===0x0){return db['UserProfileResource'][_0xd6af('0x49')]({'name':_0xef2132[_0xd6af('0x29')],'resourceId':_0xef2132['id'],'type':_0x592e7b[_0xd6af('0x29')],'sectionId':_0x592e7b['id']},{})[_0xd6af('0x23')](function(){return _0x449c6b;});}else{return _0x449c6b;}})[_0xd6af('0x45')](function(_0x14adb4){logger[_0xd6af('0x51')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x14adb4);throw _0x14adb4;});}return _0x449c6b;})[_0xd6af('0x23')](respondWithResult(_0x1b4e42,0xc9))['catch'](handleError(_0x1b4e42,null));};exports[_0xd6af('0x22')]=function(_0x1b1f07,_0x3c0049){if(_0x1b1f07[_0xd6af('0x4a')]['id']){delete _0x1b1f07[_0xd6af('0x4a')]['id'];}return db[_0xd6af('0x2d')][_0xd6af('0x48')]({'where':{'id':_0x1b1f07['params']['id']}})['then'](handleEntityNotFound(_0x3c0049,null))[_0xd6af('0x23')](saveUpdates(_0x1b1f07['body'],null))['then'](respondWithResult(_0x3c0049,null))[_0xd6af('0x45')](handleError(_0x3c0049,null));};exports['destroy']=function(_0x3068d3,_0xe655e4){return db[_0xd6af('0x2d')][_0xd6af('0x48')]({'where':{'id':_0x3068d3['params']['id']}})[_0xd6af('0x23')](handleEntityNotFound(_0xe655e4,null))[_0xd6af('0x23')](removeEntity(_0xe655e4,null))['catch'](handleError(_0xe655e4,null));};