5f244e762f445c7bc5621c4e8d3f20bedbc9e560
[motion2.git] / server / api / contactItemType / contactItemType.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 _0x4b84=['fast-json-patch','bluebird','mustache','util','ejs','squel','jsforce','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','sendStatus','end','count','offset','limit','set','Content-Range','reject','save','update','then','get','ContactItemTypes','destroy','status','stack','name','send','index','ContactItemType','rawAttributes','fieldName','type','key','model','map','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','options','includeAll','include','findAll','rows','catch','params','find','create','body','user','role','UserProfileSection','userProfileId','UserProfileResource','error','html-pdf','eml-format'];(function(_0x378d80,_0x30c95a){var _0x52b0ba=function(_0x3864a2){while(--_0x3864a2){_0x378d80['push'](_0x378d80['shift']());}};_0x52b0ba(++_0x30c95a);}(_0x4b84,0x1cc));var _0x44b8=function(_0x52b24f,_0xca062d){_0x52b24f=_0x52b24f-0x0;var _0x46ea6b=_0x4b84[_0x52b24f];return _0x46ea6b;};'use strict';var pdf=require(_0x44b8('0x0'));var emlformat=require(_0x44b8('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x44b8('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x44b8('0x3'));var Mustache=require(_0x44b8('0x4'));var util=require(_0x44b8('0x5'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x44b8('0x6'));var fs=require('fs');var _=require('lodash');var squel=require(_0x44b8('0x7'));var crypto=require('crypto');var jsforce=require(_0x44b8('0x8'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x44b8('0x9'));var Papa=require(_0x44b8('0xa'));var Redis=require(_0x44b8('0xb'));var authService=require('../../components/auth/service');var qs=require(_0x44b8('0xc'));var as=require(_0x44b8('0xd'));var hardwareService=require(_0x44b8('0xe'));var logger=require(_0x44b8('0xf'))(_0x44b8('0x10'));var utils=require(_0x44b8('0x11'));var config=require(_0x44b8('0x12'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x147529,_0x4301a6){_0x4301a6=_0x4301a6||0xcc;return function(_0x4bcc43){if(_0x4bcc43){return _0x147529[_0x44b8('0x13')](_0x4301a6);}return _0x147529['status'](_0x4301a6)[_0x44b8('0x14')]();};}function respondWithResult(_0x18d642,_0x4df670){_0x4df670=_0x4df670||0xc8;return function(_0x63e8f6){if(_0x63e8f6){return _0x18d642['status'](_0x4df670)['json'](_0x63e8f6);}};}function respondWithFilteredResult(_0x2a3e4c,_0x2af0ad){return function(_0x1722da){if(_0x1722da){var _0x41ab46=_0x1722da[_0x44b8('0x15')],_0x5e52f2=_0x2af0ad['offset'],_0x495c74=_0x2af0ad[_0x44b8('0x16')]+_0x2af0ad[_0x44b8('0x17')],_0x5d6349;if(_0x495c74>=_0x41ab46){_0x495c74=_0x41ab46;_0x5d6349=0xc8;}else{_0x5d6349=0xce;}_0x2a3e4c['status'](_0x5d6349);return _0x2a3e4c[_0x44b8('0x18')](_0x44b8('0x19'),_0x5e52f2+'-'+_0x495c74+'/'+_0x41ab46)['json'](_0x1722da);}return null;};}function patchUpdates(_0x89bc30){return function(_0x3f4688){try{jsonpatch['apply'](_0x3f4688,_0x89bc30,!![]);}catch(_0xcce202){return BPromise[_0x44b8('0x1a')](_0xcce202);}return _0x3f4688[_0x44b8('0x1b')]();};}function saveUpdates(_0x235bdc,_0x102ef9){return function(_0x369c09){if(_0x369c09){return _0x369c09[_0x44b8('0x1c')](_0x235bdc)[_0x44b8('0x1d')](function(_0x429461){return _0x429461;});}return null;};}function removeEntity(_0x1e0f2d,_0x1d642b){return function(_0x14996c){if(_0x14996c){return _0x14996c['destroy']()[_0x44b8('0x1d')](function(){var _0x3a8aa4=_0x14996c[_0x44b8('0x1e')]({'plain':!![]});var _0x1418db=_0x44b8('0x1f');return db['UserProfileResource'][_0x44b8('0x20')]({'where':{'type':_0x1418db,'resourceId':_0x3a8aa4['id']}})['then'](function(){return _0x14996c;});})[_0x44b8('0x1d')](function(){_0x1e0f2d[_0x44b8('0x21')](0xcc)[_0x44b8('0x14')]();});}};}function handleEntityNotFound(_0x47689e,_0x230a3d){return function(_0x59acbc){if(!_0x59acbc){_0x47689e[_0x44b8('0x13')](0x194);}return _0x59acbc;};}function handleError(_0x502acf,_0x41d673){_0x41d673=_0x41d673||0x1f4;return function(_0x350482){logger['error'](_0x350482[_0x44b8('0x22')]);if(_0x350482[_0x44b8('0x23')]){delete _0x350482[_0x44b8('0x23')];}_0x502acf['status'](_0x41d673)[_0x44b8('0x24')](_0x350482);};}exports[_0x44b8('0x25')]=function(_0x53d9c7,_0x2e0174){var _0x4a182d={},_0xfb0028={},_0x5a544c={'count':0x0,'rows':[]};var _0x559f0b=_['map'](db[_0x44b8('0x26')][_0x44b8('0x27')],function(_0x44ce5a){return{'name':_0x44ce5a[_0x44b8('0x28')],'type':_0x44ce5a[_0x44b8('0x29')][_0x44b8('0x2a')]};});_0xfb0028[_0x44b8('0x2b')]=_[_0x44b8('0x2c')](_0x559f0b,_0x44b8('0x23'));_0xfb0028[_0x44b8('0x2d')]=_[_0x44b8('0x2e')](_0x53d9c7[_0x44b8('0x2d')]);_0xfb0028[_0x44b8('0x2f')]=_['intersection'](_0xfb0028[_0x44b8('0x2b')],_0xfb0028['query']);_0x4a182d[_0x44b8('0x30')]=_[_0x44b8('0x31')](_0xfb0028[_0x44b8('0x2b')],qs[_0x44b8('0x32')](_0x53d9c7[_0x44b8('0x2d')]['fields']));_0x4a182d[_0x44b8('0x30')]=_0x4a182d[_0x44b8('0x30')][_0x44b8('0x33')]?_0x4a182d[_0x44b8('0x30')]:_0xfb0028[_0x44b8('0x2b')];if(!_0x53d9c7['query'][_0x44b8('0x34')](_0x44b8('0x35'))){_0x4a182d[_0x44b8('0x17')]=qs[_0x44b8('0x17')](_0x53d9c7[_0x44b8('0x2d')][_0x44b8('0x17')]);_0x4a182d[_0x44b8('0x16')]=qs[_0x44b8('0x16')](_0x53d9c7[_0x44b8('0x2d')][_0x44b8('0x16')]);}_0x4a182d[_0x44b8('0x36')]=qs[_0x44b8('0x37')](_0x53d9c7[_0x44b8('0x2d')][_0x44b8('0x37')]);_0x4a182d[_0x44b8('0x38')]=qs[_0x44b8('0x2f')](_[_0x44b8('0x39')](_0x53d9c7[_0x44b8('0x2d')],_0xfb0028[_0x44b8('0x2f')]),_0x559f0b);if(_0x53d9c7[_0x44b8('0x2d')][_0x44b8('0x3a')]){_0x4a182d[_0x44b8('0x38')]=_['merge'](_0x4a182d[_0x44b8('0x38')],{'$or':_[_0x44b8('0x2c')](_0x559f0b,function(_0x4fcfa0){if(_0x4fcfa0[_0x44b8('0x29')]!==_0x44b8('0x3b')){var _0x6658be={};_0x6658be[_0x4fcfa0[_0x44b8('0x23')]]={'$like':'%'+_0x53d9c7['query'][_0x44b8('0x3a')]+'%'};return _0x6658be;}})});}_0x4a182d=_[_0x44b8('0x3c')]({},_0x4a182d,_0x53d9c7[_0x44b8('0x3d')]);var _0x1ee3cc={'where':_0x4a182d[_0x44b8('0x38')]};return db[_0x44b8('0x26')][_0x44b8('0x15')](_0x1ee3cc)[_0x44b8('0x1d')](function(_0x209039){_0x5a544c[_0x44b8('0x15')]=_0x209039;if(_0x53d9c7[_0x44b8('0x2d')][_0x44b8('0x3e')]){_0x4a182d[_0x44b8('0x3f')]=[{'all':!![]}];}return db[_0x44b8('0x26')][_0x44b8('0x40')](_0x4a182d);})[_0x44b8('0x1d')](function(_0x57d8c4){_0x5a544c[_0x44b8('0x41')]=_0x57d8c4;return _0x5a544c;})[_0x44b8('0x1d')](respondWithFilteredResult(_0x2e0174,_0x4a182d))[_0x44b8('0x42')](handleError(_0x2e0174,null));};exports['show']=function(_0xd424f8,_0x1054c5){var _0x229cc9={'raw':!![],'where':{'id':_0xd424f8[_0x44b8('0x43')]['id']}},_0x585a16={};_0x585a16[_0x44b8('0x2b')]=_[_0x44b8('0x2e')](db[_0x44b8('0x26')][_0x44b8('0x27')]);_0x585a16['query']=_['keys'](_0xd424f8[_0x44b8('0x2d')]);_0x585a16[_0x44b8('0x2f')]=_[_0x44b8('0x31')](_0x585a16[_0x44b8('0x2b')],_0x585a16[_0x44b8('0x2d')]);_0x229cc9[_0x44b8('0x30')]=_[_0x44b8('0x31')](_0x585a16[_0x44b8('0x2b')],qs[_0x44b8('0x32')](_0xd424f8[_0x44b8('0x2d')][_0x44b8('0x32')]));_0x229cc9[_0x44b8('0x30')]=_0x229cc9[_0x44b8('0x30')][_0x44b8('0x33')]?_0x229cc9[_0x44b8('0x30')]:_0x585a16[_0x44b8('0x2b')];if(_0xd424f8[_0x44b8('0x2d')][_0x44b8('0x3e')]){_0x229cc9[_0x44b8('0x3f')]=[{'all':!![]}];}_0x229cc9=_['merge']({},_0x229cc9,_0xd424f8['options']);return db[_0x44b8('0x26')][_0x44b8('0x44')](_0x229cc9)[_0x44b8('0x1d')](handleEntityNotFound(_0x1054c5,null))[_0x44b8('0x1d')](respondWithResult(_0x1054c5,null))[_0x44b8('0x42')](handleError(_0x1054c5,null));};exports[_0x44b8('0x45')]=function(_0x411ed6,_0x4fe73f){return db[_0x44b8('0x26')]['create'](_0x411ed6[_0x44b8('0x46')],{})[_0x44b8('0x1d')](function(_0x1dbc28){var _0x9207bf=_0x411ed6[_0x44b8('0x47')][_0x44b8('0x1e')]({'plain':!![]});if(!_0x9207bf)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x9207bf[_0x44b8('0x48')]===_0x44b8('0x47')){var _0x10602c=_0x1dbc28[_0x44b8('0x1e')]({'plain':!![]});var _0x4ccc77=_0x44b8('0x1f');return db[_0x44b8('0x49')][_0x44b8('0x44')]({'where':{'name':_0x4ccc77,'userProfileId':_0x9207bf[_0x44b8('0x4a')]},'raw':!![]})[_0x44b8('0x1d')](function(_0x470ebb){if(_0x470ebb&&_0x470ebb['autoAssociation']===0x0){return db[_0x44b8('0x4b')][_0x44b8('0x45')]({'name':_0x10602c[_0x44b8('0x23')],'resourceId':_0x10602c['id'],'type':_0x470ebb[_0x44b8('0x23')],'sectionId':_0x470ebb['id']},{})[_0x44b8('0x1d')](function(){return _0x1dbc28;});}else{return _0x1dbc28;}})['catch'](function(_0x493840){logger[_0x44b8('0x4c')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x493840);throw _0x493840;});}return _0x1dbc28;})[_0x44b8('0x1d')](respondWithResult(_0x4fe73f,0xc9))['catch'](handleError(_0x4fe73f,null));};exports[_0x44b8('0x1c')]=function(_0x434d6a,_0x1a29f6){if(_0x434d6a[_0x44b8('0x46')]['id']){delete _0x434d6a[_0x44b8('0x46')]['id'];}return db[_0x44b8('0x26')][_0x44b8('0x44')]({'where':{'id':_0x434d6a['params']['id']}})[_0x44b8('0x1d')](handleEntityNotFound(_0x1a29f6,null))[_0x44b8('0x1d')](saveUpdates(_0x434d6a[_0x44b8('0x46')],null))['then'](respondWithResult(_0x1a29f6,null))[_0x44b8('0x42')](handleError(_0x1a29f6,null));};exports[_0x44b8('0x20')]=function(_0x45f9a0,_0x2b256b){return db['ContactItemType'][_0x44b8('0x44')]({'where':{'id':_0x45f9a0[_0x44b8('0x43')]['id']}})['then'](handleEntityNotFound(_0x2b256b,null))[_0x44b8('0x1d')](removeEntity(_0x2b256b,null))[_0x44b8('0x42')](handleError(_0x2b256b,null));};