cdd63dde0d09af5b921c92f4b090c1ff2ec2bd72
[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 _0xace9=['model','fields','query','attributes','length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','include','rows','catch','params','rawAttributes','find','update','body','create','sequelize','transaction','Sequelize','TEXT','text','INTEGER','switch','defaultValue','queryInterface','addColumn','cm_contacts','format','cf_%d','eml-format','rimraf','moment','mustache','path','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','status','end','json','offset','undefined','limit','count','set','reject','save','destroy','then','sendStatus','error','stack','name','send','index','map','CmCustomField','type','key','differenceBy','keys','filters','intersection'];(function(_0x17c483,_0xc69535){var _0x112bdb=function(_0x19adb9){while(--_0x19adb9){_0x17c483['push'](_0x17c483['shift']());}};_0x112bdb(++_0xc69535);}(_0xace9,0x1b9));var _0x9ace=function(_0x4a151d,_0x3b1d73){_0x4a151d=_0x4a151d-0x0;var _0x4c2e94=_0xace9[_0x4a151d];return _0x4c2e94;};'use strict';var emlformat=require(_0x9ace('0x0'));var rimraf=require(_0x9ace('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x9ace('0x2'));var BPromise=require('bluebird');var Mustache=require(_0x9ace('0x3'));var util=require('util');var path=require(_0x9ace('0x4'));var sox=require('sox');var csv=require(_0x9ace('0x5'));var ejs=require(_0x9ace('0x6'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x9ace('0x7'));var squel=require(_0x9ace('0x8'));var crypto=require(_0x9ace('0x9'));var jsforce=require(_0x9ace('0xa'));var deskjs=require('desk.js');var toCsv=require(_0x9ace('0x5'));var querystring=require(_0x9ace('0xb'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x9ace('0xc'));var qs=require('../../components/parsers/qs');var as=require(_0x9ace('0xd'));var hardwareService=require(_0x9ace('0xe'));var logger=require(_0x9ace('0xf'))(_0x9ace('0x10'));var utils=require('../../config/utils');var config=require(_0x9ace('0x11'));var licenseUtil=require('../../config/license/util');var db=require(_0x9ace('0x12'))['db'];function respondWithStatusCode(_0x4844dc,_0x1f5831){_0x1f5831=_0x1f5831||0xcc;return function(_0xeb1b45){if(_0xeb1b45){return _0x4844dc['sendStatus'](_0x1f5831);}return _0x4844dc[_0x9ace('0x13')](_0x1f5831)[_0x9ace('0x14')]();};}function respondWithResult(_0x15b1ee,_0x2e84d0){_0x2e84d0=_0x2e84d0||0xc8;return function(_0x43b188){if(_0x43b188){return _0x15b1ee['status'](_0x2e84d0)[_0x9ace('0x15')](_0x43b188);}};}function respondWithFilteredResult(_0x1b59b4,_0x3a1b8d){return function(_0x3498e4){if(_0x3498e4){var _0x44b605=typeof _0x3a1b8d[_0x9ace('0x16')]===_0x9ace('0x17')&&typeof _0x3a1b8d[_0x9ace('0x18')]===_0x9ace('0x17');var _0x1d72bf=_0x3498e4[_0x9ace('0x19')];var _0x5522e8=_0x44b605?0x0:_0x3a1b8d[_0x9ace('0x16')];var _0x3ee521=_0x44b605?_0x3498e4[_0x9ace('0x19')]:_0x3a1b8d[_0x9ace('0x16')]+_0x3a1b8d[_0x9ace('0x18')];var _0x441ce5;if(_0x3ee521>=_0x1d72bf){_0x3ee521=_0x1d72bf;_0x441ce5=0xc8;}else{_0x441ce5=0xce;}_0x1b59b4['status'](_0x441ce5);return _0x1b59b4[_0x9ace('0x1a')]('Content-Range',_0x5522e8+'-'+_0x3ee521+'/'+_0x1d72bf)[_0x9ace('0x15')](_0x3498e4);}return null;};}function patchUpdates(_0xaa6b52){return function(_0x3010f8){try{jsonpatch['apply'](_0x3010f8,_0xaa6b52,!![]);}catch(_0x2ff0b3){return BPromise[_0x9ace('0x1b')](_0x2ff0b3);}return _0x3010f8[_0x9ace('0x1c')]();};}function saveUpdates(_0x2129d3,_0x19316e){return function(_0x2c40d5){if(_0x2c40d5){return _0x2c40d5['update'](_0x2129d3)['then'](function(_0x4b92cb){return _0x4b92cb;});}return null;};}function removeEntity(_0x123545,_0x16ee0b){return function(_0x327f99){if(_0x327f99){return _0x327f99[_0x9ace('0x1d')]()[_0x9ace('0x1e')](function(){_0x123545[_0x9ace('0x13')](0xcc)[_0x9ace('0x14')]();});}};}function handleEntityNotFound(_0x3b70cb,_0x52d03e){return function(_0x51c15d){if(!_0x51c15d){_0x3b70cb[_0x9ace('0x1f')](0x194);}return _0x51c15d;};}function handleError(_0x4d996b,_0xf7cffb){_0xf7cffb=_0xf7cffb||0x1f4;return function(_0xe95f4f){logger[_0x9ace('0x20')](_0xe95f4f[_0x9ace('0x21')]);if(_0xe95f4f[_0x9ace('0x22')]){delete _0xe95f4f[_0x9ace('0x22')];}_0x4d996b['status'](_0xf7cffb)[_0x9ace('0x23')](_0xe95f4f);};}exports[_0x9ace('0x24')]=function(_0x309d1e,_0x4ac050){var _0xd145a9={},_0x5089c5={},_0xb83f76={'count':0x0,'rows':[]};var _0x5e53c2=_[_0x9ace('0x25')](db[_0x9ace('0x26')]['rawAttributes'],function(_0x49a2a0){return{'name':_0x49a2a0['fieldName'],'type':_0x49a2a0[_0x9ace('0x27')][_0x9ace('0x28')]};});_0x5089c5['model']=_[_0x9ace('0x29')](_[_0x9ace('0x25')](_0x5e53c2,_0x9ace('0x22')),[_0x9ace('0x22')]);_0x5089c5['query']=_[_0x9ace('0x2a')](_0x309d1e['query']);_0x5089c5[_0x9ace('0x2b')]=_[_0x9ace('0x2c')](_0x5089c5['model'],_0x5089c5['query']);_0xd145a9['attributes']=_[_0x9ace('0x2c')](_0x5089c5[_0x9ace('0x2d')],qs[_0x9ace('0x2e')](_0x309d1e[_0x9ace('0x2f')][_0x9ace('0x2e')]));_0xd145a9[_0x9ace('0x30')]=_0xd145a9[_0x9ace('0x30')][_0x9ace('0x31')]?_0xd145a9[_0x9ace('0x30')]:_0x5089c5[_0x9ace('0x2d')];if(!_0x309d1e['query']['hasOwnProperty'](_0x9ace('0x32'))){_0xd145a9[_0x9ace('0x18')]=qs[_0x9ace('0x18')](_0x309d1e[_0x9ace('0x2f')][_0x9ace('0x18')]);_0xd145a9['offset']=qs[_0x9ace('0x16')](_0x309d1e['query'][_0x9ace('0x16')]);}_0xd145a9[_0x9ace('0x33')]=qs[_0x9ace('0x34')](_0x309d1e[_0x9ace('0x2f')][_0x9ace('0x34')]);_0xd145a9[_0x9ace('0x35')]=qs[_0x9ace('0x2b')](_[_0x9ace('0x36')](_0x309d1e['query'],_0x5089c5[_0x9ace('0x2b')]),_0x5e53c2);if(_0x309d1e[_0x9ace('0x2f')][_0x9ace('0x37')]){_0xd145a9[_0x9ace('0x35')]=_[_0x9ace('0x38')](_0xd145a9['where'],{'$or':_[_0x9ace('0x25')](_0x5e53c2,function(_0x22f2db){if(_0x22f2db[_0x9ace('0x27')]!==_0x9ace('0x39')){var _0x5b9b94={};_0x5b9b94[_0x22f2db[_0x9ace('0x22')]]={'$like':'%'+_0x309d1e[_0x9ace('0x2f')]['filter']+'%'};return _0x5b9b94;}})});}_0xd145a9=_[_0x9ace('0x38')]({},_0xd145a9,_0x309d1e[_0x9ace('0x3a')]);var _0x23a0fa={'where':_0xd145a9[_0x9ace('0x35')]};return db['CmCustomField']['count'](_0x23a0fa)[_0x9ace('0x1e')](function(_0x28e01b){_0xb83f76[_0x9ace('0x19')]=_0x28e01b;if(_0x309d1e[_0x9ace('0x2f')]['includeAll']){_0xd145a9[_0x9ace('0x3b')]=[{'all':!![]}];}return db[_0x9ace('0x26')]['findAll'](_0xd145a9);})[_0x9ace('0x1e')](function(_0x24dc59){_0xb83f76[_0x9ace('0x3c')]=_0x24dc59;return _0xb83f76;})[_0x9ace('0x1e')](respondWithFilteredResult(_0x4ac050,_0xd145a9))[_0x9ace('0x3d')](handleError(_0x4ac050,null));};exports['show']=function(_0x58dcf5,_0x536596){var _0x27c0d1={'raw':!![],'where':{'id':_0x58dcf5[_0x9ace('0x3e')]['id']}},_0x5700f6={};_0x5700f6['model']=_[_0x9ace('0x2a')](db['CmCustomField'][_0x9ace('0x3f')]);_0x5700f6[_0x9ace('0x2f')]=_[_0x9ace('0x2a')](_0x58dcf5[_0x9ace('0x2f')]);_0x5700f6[_0x9ace('0x2b')]=_[_0x9ace('0x2c')](_0x5700f6[_0x9ace('0x2d')],_0x5700f6[_0x9ace('0x2f')]);_0x27c0d1[_0x9ace('0x30')]=_[_0x9ace('0x2c')](_0x5700f6[_0x9ace('0x2d')],qs[_0x9ace('0x2e')](_0x58dcf5[_0x9ace('0x2f')][_0x9ace('0x2e')]));_0x27c0d1[_0x9ace('0x30')]=_0x27c0d1[_0x9ace('0x30')][_0x9ace('0x31')]?_0x27c0d1['attributes']:_0x5700f6[_0x9ace('0x2d')];if(_0x58dcf5[_0x9ace('0x2f')]['includeAll']){_0x27c0d1['include']=[{'all':!![]}];}_0x27c0d1=_[_0x9ace('0x38')]({},_0x27c0d1,_0x58dcf5['options']);return db[_0x9ace('0x26')][_0x9ace('0x40')](_0x27c0d1)[_0x9ace('0x1e')](handleEntityNotFound(_0x536596,null))[_0x9ace('0x1e')](respondWithResult(_0x536596,null))[_0x9ace('0x3d')](handleError(_0x536596,null));};exports[_0x9ace('0x41')]=function(_0x133fc8,_0xaca453){if(_0x133fc8[_0x9ace('0x42')]['id']){delete _0x133fc8[_0x9ace('0x42')]['id'];}return db[_0x9ace('0x26')][_0x9ace('0x40')]({'where':{'id':_0x133fc8[_0x9ace('0x3e')]['id']}})[_0x9ace('0x1e')](handleEntityNotFound(_0xaca453,null))['then'](saveUpdates(_0x133fc8[_0x9ace('0x42')],null))[_0x9ace('0x1e')](respondWithResult(_0xaca453,null))['catch'](handleError(_0xaca453,null));};exports[_0x9ace('0x1d')]=function(_0x231ed1,_0x4bcf45){return db['CmCustomField'][_0x9ace('0x40')]({'where':{'id':_0x231ed1[_0x9ace('0x3e')]['id']}})[_0x9ace('0x1e')](handleEntityNotFound(_0x4bcf45,null))[_0x9ace('0x1e')](removeEntity(_0x4bcf45,null))[_0x9ace('0x3d')](handleError(_0x4bcf45,null));};exports[_0x9ace('0x43')]=function(_0x43165c,_0x4c0b1d){var _0x1cf4a5;return db[_0x9ace('0x44')][_0x9ace('0x45')](function(_0x3de391){return db[_0x9ace('0x26')][_0x9ace('0x43')](_0x43165c[_0x9ace('0x42')],{'transaction':_0x3de391})['then'](function(_0x373915){_0x1cf4a5=_0x373915;var _0x38e65b={'type':db[_0x9ace('0x46')][_0x9ace('0x47')],'transaction':_0x3de391};switch(_0x43165c[_0x9ace('0x42')][_0x9ace('0x27')]){case _0x9ace('0x48'):_0x38e65b['type']=db['Sequelize'][_0x9ace('0x47')];break;case'number':_0x38e65b['type']=db[_0x9ace('0x46')][_0x9ace('0x49')];break;case _0x9ace('0x4a'):_0x38e65b[_0x9ace('0x27')]=db[_0x9ace('0x46')]['BOOLEAN'];_0x38e65b[_0x9ace('0x4b')]=![];break;default:}return db[_0x9ace('0x44')][_0x9ace('0x4c')][_0x9ace('0x4d')](_0x9ace('0x4e'),util[_0x9ace('0x4f')](_0x9ace('0x50'),_0x1cf4a5['id']),_0x38e65b);})[_0x9ace('0x1e')](function(){return _0x1cf4a5;});})[_0x9ace('0x1e')](respondWithResult(_0x4c0b1d,0xc9))[_0x9ace('0x3d')](handleError(_0x4c0b1d,null));};