cb776cd510467491c0a12cc8dc5e974f9b89c588
[motion2.git] / server / api / cmCustomField / cmCustomField.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 _0x3bf5=['../../config/logger','api','../../config/utils','../../config/license/util','sendStatus','end','status','json','count','offset','set','reject','save','update','then','error','name','send','index','map','CmCustomField','fieldName','type','key','model','differenceBy','query','attributes','intersection','fields','hasOwnProperty','limit','order','sort','where','filters','merge','filter','options','includeAll','include','findAll','rows','catch','show','params','keys','body','destroy','find','create','transaction','Sequelize','TEXT','number','INTEGER','defaultValue','queryInterface','addColumn','cm_contacts','format','cf_%d','html-pdf','eml-format','zip-dir','fast-json-patch','moment','util','path','sox','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware'];(function(_0x2bdf52,_0x3da2d5){var _0x1ae793=function(_0x372fa8){while(--_0x372fa8){_0x2bdf52['push'](_0x2bdf52['shift']());}};_0x1ae793(++_0x3da2d5);}(_0x3bf5,0x17e));var _0x53bf=function(_0x38ced4,_0x24263f){_0x38ced4=_0x38ced4-0x0;var _0x547c07=_0x3bf5[_0x38ced4];return _0x547c07;};'use strict';var pdf=require(_0x53bf('0x0'));var emlformat=require(_0x53bf('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x53bf('0x2'));var jsonpatch=require(_0x53bf('0x3'));var rp=require('request-promise');var moment=require(_0x53bf('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x53bf('0x5'));var path=require(_0x53bf('0x6'));var sox=require(_0x53bf('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0x53bf('0x8'));var squel=require(_0x53bf('0x9'));var crypto=require(_0x53bf('0xa'));var jsforce=require(_0x53bf('0xb'));var deskjs=require('desk.js');var toCsv=require(_0x53bf('0xc'));var querystring=require(_0x53bf('0xd'));var Papa=require(_0x53bf('0xe'));var Redis=require('ioredis');var authService=require(_0x53bf('0xf'));var qs=require(_0x53bf('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x53bf('0x11'));var logger=require(_0x53bf('0x12'))(_0x53bf('0x13'));var utils=require(_0x53bf('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0x53bf('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0xf3fa47,_0x2a1596){_0x2a1596=_0x2a1596||0xcc;return function(_0x37b4dd){if(_0x37b4dd){return _0xf3fa47[_0x53bf('0x16')](_0x2a1596);}return _0xf3fa47['status'](_0x2a1596)[_0x53bf('0x17')]();};}function respondWithResult(_0x7413a9,_0x14ebcc){_0x14ebcc=_0x14ebcc||0xc8;return function(_0x51c9d0){if(_0x51c9d0){return _0x7413a9[_0x53bf('0x18')](_0x14ebcc)[_0x53bf('0x19')](_0x51c9d0);}};}function respondWithFilteredResult(_0x2a3638,_0x4d304c){return function(_0x19dd62){if(_0x19dd62){var _0x5b7fbe=_0x19dd62[_0x53bf('0x1a')],_0x2804b1=_0x4d304c[_0x53bf('0x1b')],_0x46c7a5=_0x4d304c['offset']+_0x4d304c['limit'],_0x1c7787;if(_0x46c7a5>=_0x5b7fbe){_0x46c7a5=_0x5b7fbe;_0x1c7787=0xc8;}else{_0x1c7787=0xce;}_0x2a3638[_0x53bf('0x18')](_0x1c7787);return _0x2a3638[_0x53bf('0x1c')]('Content-Range',_0x2804b1+'-'+_0x46c7a5+'/'+_0x5b7fbe)[_0x53bf('0x19')](_0x19dd62);}return null;};}function patchUpdates(_0x38ea97){return function(_0xf6f7b0){try{jsonpatch['apply'](_0xf6f7b0,_0x38ea97,!![]);}catch(_0x5248d1){return BPromise[_0x53bf('0x1d')](_0x5248d1);}return _0xf6f7b0[_0x53bf('0x1e')]();};}function saveUpdates(_0x12c3fc,_0x31fe18){return function(_0x3be89e){if(_0x3be89e){return _0x3be89e[_0x53bf('0x1f')](_0x12c3fc)['then'](function(_0x3f4d70){return _0x3f4d70;});}return null;};}function removeEntity(_0xe381f3,_0x5bb33a){return function(_0x4478a0){if(_0x4478a0){return _0x4478a0['destroy']()[_0x53bf('0x20')](function(){_0xe381f3[_0x53bf('0x18')](0xcc)[_0x53bf('0x17')]();});}};}function handleEntityNotFound(_0x2b9bde,_0xdd4f0){return function(_0x30e863){if(!_0x30e863){_0x2b9bde[_0x53bf('0x16')](0x194);}return _0x30e863;};}function handleError(_0x280dda,_0x31221d){_0x31221d=_0x31221d||0x1f4;return function(_0x23807d){logger[_0x53bf('0x21')](_0x23807d['stack']);if(_0x23807d[_0x53bf('0x22')]){delete _0x23807d[_0x53bf('0x22')];}_0x280dda['status'](_0x31221d)[_0x53bf('0x23')](_0x23807d);};}exports[_0x53bf('0x24')]=function(_0x578124,_0x35eccb){var _0x2b5a6e={},_0x428ec1={},_0x3ac2f4={'count':0x0,'rows':[]};var _0x544b9c=_[_0x53bf('0x25')](db[_0x53bf('0x26')]['rawAttributes'],function(_0x46555b){return{'name':_0x46555b[_0x53bf('0x27')],'type':_0x46555b[_0x53bf('0x28')][_0x53bf('0x29')]};});_0x428ec1[_0x53bf('0x2a')]=_[_0x53bf('0x2b')](_['map'](_0x544b9c,_0x53bf('0x22')),[_0x53bf('0x22')]);_0x428ec1[_0x53bf('0x2c')]=_['keys'](_0x578124[_0x53bf('0x2c')]);_0x428ec1['filters']=_['intersection'](_0x428ec1[_0x53bf('0x2a')],_0x428ec1[_0x53bf('0x2c')]);_0x2b5a6e[_0x53bf('0x2d')]=_[_0x53bf('0x2e')](_0x428ec1[_0x53bf('0x2a')],qs[_0x53bf('0x2f')](_0x578124['query'][_0x53bf('0x2f')]));_0x2b5a6e[_0x53bf('0x2d')]=_0x2b5a6e[_0x53bf('0x2d')]['length']?_0x2b5a6e[_0x53bf('0x2d')]:_0x428ec1[_0x53bf('0x2a')];if(!_0x578124[_0x53bf('0x2c')][_0x53bf('0x30')]('nolimit')){_0x2b5a6e[_0x53bf('0x31')]=qs[_0x53bf('0x31')](_0x578124[_0x53bf('0x2c')][_0x53bf('0x31')]);_0x2b5a6e[_0x53bf('0x1b')]=qs[_0x53bf('0x1b')](_0x578124['query'][_0x53bf('0x1b')]);}_0x2b5a6e[_0x53bf('0x32')]=qs[_0x53bf('0x33')](_0x578124[_0x53bf('0x2c')][_0x53bf('0x33')]);_0x2b5a6e[_0x53bf('0x34')]=qs[_0x53bf('0x35')](_['pick'](_0x578124[_0x53bf('0x2c')],_0x428ec1['filters']),_0x544b9c);if(_0x578124[_0x53bf('0x2c')]['filter']){_0x2b5a6e[_0x53bf('0x34')]=_[_0x53bf('0x36')](_0x2b5a6e[_0x53bf('0x34')],{'$or':_['map'](_0x544b9c,function(_0x378c64){if(_0x378c64[_0x53bf('0x28')]!=='VIRTUAL'){var _0x33ca38={};_0x33ca38[_0x378c64[_0x53bf('0x22')]]={'$like':'%'+_0x578124[_0x53bf('0x2c')][_0x53bf('0x37')]+'%'};return _0x33ca38;}})});}_0x2b5a6e=_[_0x53bf('0x36')]({},_0x2b5a6e,_0x578124[_0x53bf('0x38')]);var _0x7d09b5={'where':_0x2b5a6e[_0x53bf('0x34')]};return db['CmCustomField'][_0x53bf('0x1a')](_0x7d09b5)[_0x53bf('0x20')](function(_0x21c023){_0x3ac2f4['count']=_0x21c023;if(_0x578124['query'][_0x53bf('0x39')]){_0x2b5a6e[_0x53bf('0x3a')]=[{'all':!![]}];}return db[_0x53bf('0x26')][_0x53bf('0x3b')](_0x2b5a6e);})[_0x53bf('0x20')](function(_0x4b00aa){_0x3ac2f4[_0x53bf('0x3c')]=_0x4b00aa;return _0x3ac2f4;})[_0x53bf('0x20')](respondWithFilteredResult(_0x35eccb,_0x2b5a6e))[_0x53bf('0x3d')](handleError(_0x35eccb,null));};exports[_0x53bf('0x3e')]=function(_0x385e1b,_0x5282ee){var _0x47ee2d={'raw':!![],'where':{'id':_0x385e1b[_0x53bf('0x3f')]['id']}},_0x209813={};_0x209813['model']=_[_0x53bf('0x40')](db['CmCustomField']['rawAttributes']);_0x209813['query']=_[_0x53bf('0x40')](_0x385e1b[_0x53bf('0x2c')]);_0x209813['filters']=_[_0x53bf('0x2e')](_0x209813['model'],_0x209813['query']);_0x47ee2d[_0x53bf('0x2d')]=_[_0x53bf('0x2e')](_0x209813[_0x53bf('0x2a')],qs['fields'](_0x385e1b[_0x53bf('0x2c')]['fields']));_0x47ee2d['attributes']=_0x47ee2d[_0x53bf('0x2d')]['length']?_0x47ee2d[_0x53bf('0x2d')]:_0x209813[_0x53bf('0x2a')];if(_0x385e1b[_0x53bf('0x2c')][_0x53bf('0x39')]){_0x47ee2d[_0x53bf('0x3a')]=[{'all':!![]}];}_0x47ee2d=_[_0x53bf('0x36')]({},_0x47ee2d,_0x385e1b['options']);return db['CmCustomField']['find'](_0x47ee2d)[_0x53bf('0x20')](handleEntityNotFound(_0x5282ee,null))['then'](respondWithResult(_0x5282ee,null))[_0x53bf('0x3d')](handleError(_0x5282ee,null));};exports[_0x53bf('0x1f')]=function(_0x59792d,_0x11f06f){if(_0x59792d[_0x53bf('0x41')]['id']){delete _0x59792d['body']['id'];}return db[_0x53bf('0x26')]['find']({'where':{'id':_0x59792d[_0x53bf('0x3f')]['id']}})['then'](handleEntityNotFound(_0x11f06f,null))[_0x53bf('0x20')](saveUpdates(_0x59792d[_0x53bf('0x41')],null))['then'](respondWithResult(_0x11f06f,null))[_0x53bf('0x3d')](handleError(_0x11f06f,null));};exports[_0x53bf('0x42')]=function(_0x2553ff,_0xbf16b9){return db[_0x53bf('0x26')][_0x53bf('0x43')]({'where':{'id':_0x2553ff[_0x53bf('0x3f')]['id']}})[_0x53bf('0x20')](handleEntityNotFound(_0xbf16b9,null))[_0x53bf('0x20')](removeEntity(_0xbf16b9,null))[_0x53bf('0x3d')](handleError(_0xbf16b9,null));};exports[_0x53bf('0x44')]=function(_0x570d03,_0x401382){var _0x2f4386;return db['sequelize'][_0x53bf('0x45')](function(_0x1006dd){return db[_0x53bf('0x26')]['create'](_0x570d03[_0x53bf('0x41')],{'transaction':_0x1006dd})[_0x53bf('0x20')](function(_0x5716d3){_0x2f4386=_0x5716d3;var _0x1241d4={'type':db[_0x53bf('0x46')][_0x53bf('0x47')],'transaction':_0x1006dd};switch(_0x570d03[_0x53bf('0x41')][_0x53bf('0x28')]){case'text':_0x1241d4['type']=db[_0x53bf('0x46')][_0x53bf('0x47')];break;case _0x53bf('0x48'):_0x1241d4[_0x53bf('0x28')]=db[_0x53bf('0x46')][_0x53bf('0x49')];break;case'switch':_0x1241d4[_0x53bf('0x28')]=db[_0x53bf('0x46')]['BOOLEAN'];_0x1241d4[_0x53bf('0x4a')]=![];break;default:}return db['sequelize'][_0x53bf('0x4b')][_0x53bf('0x4c')](_0x53bf('0x4d'),util[_0x53bf('0x4e')](_0x53bf('0x4f'),_0x2f4386['id']),_0x1241d4);})[_0x53bf('0x20')](function(){return _0x2f4386;});})[_0x53bf('0x20')](respondWithResult(_0x401382,0xc9))[_0x53bf('0x3d')](handleError(_0x401382,null));};