Built motion from commit 19a84241.|2.5.34
[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 _0x065f=['findAll','rows','catch','show','params','includeAll','find','body','create','sequelize','transaction','Sequelize','TEXT','text','INTEGER','switch','defaultValue','queryInterface','addColumn','cm_contacts','format','cf_%d','eml-format','fast-json-patch','request-promise','moment','mustache','util','path','sox','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','map','CmCustomField','rawAttributes','fieldName','type','key','model','query','keys','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','filters','pick','where','merge','filter','options','include'];(function(_0x23be7a,_0x32d514){var _0x1fcb72=function(_0xd55d){while(--_0xd55d){_0x23be7a['push'](_0x23be7a['shift']());}};_0x1fcb72(++_0x32d514);}(_0x065f,0x176));var _0xf065=function(_0x17d9e3,_0x1f969c){_0x17d9e3=_0x17d9e3-0x0;var _0x14192d=_0x065f[_0x17d9e3];return _0x14192d;};'use strict';var emlformat=require(_0xf065('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xf065('0x1'));var rp=require(_0xf065('0x2'));var moment=require(_0xf065('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xf065('0x4'));var util=require(_0xf065('0x5'));var path=require(_0xf065('0x6'));var sox=require(_0xf065('0x7'));var csv=require('to-csv');var ejs=require(_0xf065('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xf065('0x9'));var squel=require(_0xf065('0xa'));var crypto=require(_0xf065('0xb'));var jsforce=require(_0xf065('0xc'));var deskjs=require(_0xf065('0xd'));var toCsv=require(_0xf065('0xe'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xf065('0xf'));var authService=require(_0xf065('0x10'));var qs=require(_0xf065('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf065('0x12'));var logger=require(_0xf065('0x13'))(_0xf065('0x14'));var utils=require(_0xf065('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0xf065('0x16'));var db=require(_0xf065('0x17'))['db'];function respondWithStatusCode(_0x3e34d9,_0x191392){_0x191392=_0x191392||0xcc;return function(_0x20c563){if(_0x20c563){return _0x3e34d9[_0xf065('0x18')](_0x191392);}return _0x3e34d9['status'](_0x191392)[_0xf065('0x19')]();};}function respondWithResult(_0x7ef875,_0x2097f5){_0x2097f5=_0x2097f5||0xc8;return function(_0x574b8a){if(_0x574b8a){return _0x7ef875[_0xf065('0x1a')](_0x2097f5)[_0xf065('0x1b')](_0x574b8a);}};}function respondWithFilteredResult(_0xf13710,_0x126d09){return function(_0x1e6735){if(_0x1e6735){var _0x4b33be=typeof _0x126d09[_0xf065('0x1c')]==='undefined'&&typeof _0x126d09[_0xf065('0x1d')]==='undefined';var _0x40be12=_0x1e6735[_0xf065('0x1e')];var _0x1fd513=_0x4b33be?0x0:_0x126d09[_0xf065('0x1c')];var _0xd8753f=_0x4b33be?_0x1e6735[_0xf065('0x1e')]:_0x126d09[_0xf065('0x1c')]+_0x126d09[_0xf065('0x1d')];var _0x435049;if(_0xd8753f>=_0x40be12){_0xd8753f=_0x40be12;_0x435049=0xc8;}else{_0x435049=0xce;}_0xf13710[_0xf065('0x1a')](_0x435049);return _0xf13710[_0xf065('0x1f')](_0xf065('0x20'),_0x1fd513+'-'+_0xd8753f+'/'+_0x40be12)[_0xf065('0x1b')](_0x1e6735);}return null;};}function patchUpdates(_0x39bee1){return function(_0xa06f06){try{jsonpatch[_0xf065('0x21')](_0xa06f06,_0x39bee1,!![]);}catch(_0x2e53a7){return BPromise[_0xf065('0x22')](_0x2e53a7);}return _0xa06f06[_0xf065('0x23')]();};}function saveUpdates(_0x5d5329,_0xf7081d){return function(_0x373e4f){if(_0x373e4f){return _0x373e4f[_0xf065('0x24')](_0x5d5329)[_0xf065('0x25')](function(_0x17bc53){return _0x17bc53;});}return null;};}function removeEntity(_0x4fce10,_0x1e89a6){return function(_0x55826b){if(_0x55826b){return _0x55826b[_0xf065('0x26')]()[_0xf065('0x25')](function(){_0x4fce10['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x5966a6,_0x5bc3f6){return function(_0x29b684){if(!_0x29b684){_0x5966a6[_0xf065('0x18')](0x194);}return _0x29b684;};}function handleError(_0x574d0b,_0x4798c9){_0x4798c9=_0x4798c9||0x1f4;return function(_0x2952b5){logger[_0xf065('0x27')](_0x2952b5[_0xf065('0x28')]);if(_0x2952b5[_0xf065('0x29')]){delete _0x2952b5[_0xf065('0x29')];}_0x574d0b[_0xf065('0x1a')](_0x4798c9)['send'](_0x2952b5);};}exports['index']=function(_0x18d28d,_0x427119){var _0xf4427e={},_0x27a09d={},_0x276685={'count':0x0,'rows':[]};var _0x374437=_[_0xf065('0x2a')](db[_0xf065('0x2b')][_0xf065('0x2c')],function(_0x17094f){return{'name':_0x17094f[_0xf065('0x2d')],'type':_0x17094f[_0xf065('0x2e')][_0xf065('0x2f')]};});_0x27a09d[_0xf065('0x30')]=_['differenceBy'](_[_0xf065('0x2a')](_0x374437,_0xf065('0x29')),[_0xf065('0x29')]);_0x27a09d[_0xf065('0x31')]=_[_0xf065('0x32')](_0x18d28d[_0xf065('0x31')]);_0x27a09d['filters']=_[_0xf065('0x33')](_0x27a09d['model'],_0x27a09d[_0xf065('0x31')]);_0xf4427e['attributes']=_[_0xf065('0x33')](_0x27a09d[_0xf065('0x30')],qs[_0xf065('0x34')](_0x18d28d['query'][_0xf065('0x34')]));_0xf4427e[_0xf065('0x35')]=_0xf4427e['attributes'][_0xf065('0x36')]?_0xf4427e[_0xf065('0x35')]:_0x27a09d[_0xf065('0x30')];if(!_0x18d28d[_0xf065('0x31')][_0xf065('0x37')](_0xf065('0x38'))){_0xf4427e[_0xf065('0x1d')]=qs[_0xf065('0x1d')](_0x18d28d[_0xf065('0x31')][_0xf065('0x1d')]);_0xf4427e['offset']=qs[_0xf065('0x1c')](_0x18d28d['query']['offset']);}_0xf4427e[_0xf065('0x39')]=qs[_0xf065('0x3a')](_0x18d28d[_0xf065('0x31')][_0xf065('0x3a')]);_0xf4427e['where']=qs[_0xf065('0x3b')](_[_0xf065('0x3c')](_0x18d28d[_0xf065('0x31')],_0x27a09d[_0xf065('0x3b')]),_0x374437);if(_0x18d28d[_0xf065('0x31')]['filter']){_0xf4427e[_0xf065('0x3d')]=_[_0xf065('0x3e')](_0xf4427e[_0xf065('0x3d')],{'$or':_['map'](_0x374437,function(_0x26a6e3){if(_0x26a6e3['type']!=='VIRTUAL'){var _0x1940ef={};_0x1940ef[_0x26a6e3[_0xf065('0x29')]]={'$like':'%'+_0x18d28d['query'][_0xf065('0x3f')]+'%'};return _0x1940ef;}})});}_0xf4427e=_[_0xf065('0x3e')]({},_0xf4427e,_0x18d28d[_0xf065('0x40')]);var _0x48eb8b={'where':_0xf4427e[_0xf065('0x3d')]};return db[_0xf065('0x2b')][_0xf065('0x1e')](_0x48eb8b)[_0xf065('0x25')](function(_0x1eb2b2){_0x276685['count']=_0x1eb2b2;if(_0x18d28d[_0xf065('0x31')]['includeAll']){_0xf4427e[_0xf065('0x41')]=[{'all':!![]}];}return db[_0xf065('0x2b')][_0xf065('0x42')](_0xf4427e);})[_0xf065('0x25')](function(_0x328219){_0x276685[_0xf065('0x43')]=_0x328219;return _0x276685;})[_0xf065('0x25')](respondWithFilteredResult(_0x427119,_0xf4427e))[_0xf065('0x44')](handleError(_0x427119,null));};exports[_0xf065('0x45')]=function(_0x5aa5a3,_0x4f12d5){var _0x24da78={'raw':!![],'where':{'id':_0x5aa5a3[_0xf065('0x46')]['id']}},_0x207616={};_0x207616[_0xf065('0x30')]=_[_0xf065('0x32')](db['CmCustomField'][_0xf065('0x2c')]);_0x207616[_0xf065('0x31')]=_['keys'](_0x5aa5a3['query']);_0x207616[_0xf065('0x3b')]=_[_0xf065('0x33')](_0x207616[_0xf065('0x30')],_0x207616[_0xf065('0x31')]);_0x24da78['attributes']=_[_0xf065('0x33')](_0x207616[_0xf065('0x30')],qs[_0xf065('0x34')](_0x5aa5a3['query'][_0xf065('0x34')]));_0x24da78['attributes']=_0x24da78[_0xf065('0x35')][_0xf065('0x36')]?_0x24da78[_0xf065('0x35')]:_0x207616[_0xf065('0x30')];if(_0x5aa5a3['query'][_0xf065('0x47')]){_0x24da78['include']=[{'all':!![]}];}_0x24da78=_[_0xf065('0x3e')]({},_0x24da78,_0x5aa5a3[_0xf065('0x40')]);return db[_0xf065('0x2b')][_0xf065('0x48')](_0x24da78)[_0xf065('0x25')](handleEntityNotFound(_0x4f12d5,null))[_0xf065('0x25')](respondWithResult(_0x4f12d5,null))['catch'](handleError(_0x4f12d5,null));};exports[_0xf065('0x24')]=function(_0x48f317,_0x387721){if(_0x48f317[_0xf065('0x49')]['id']){delete _0x48f317['body']['id'];}return db['CmCustomField'][_0xf065('0x48')]({'where':{'id':_0x48f317[_0xf065('0x46')]['id']}})['then'](handleEntityNotFound(_0x387721,null))[_0xf065('0x25')](saveUpdates(_0x48f317[_0xf065('0x49')],null))[_0xf065('0x25')](respondWithResult(_0x387721,null))[_0xf065('0x44')](handleError(_0x387721,null));};exports[_0xf065('0x26')]=function(_0x38afa5,_0x1c56ee){return db[_0xf065('0x2b')][_0xf065('0x48')]({'where':{'id':_0x38afa5[_0xf065('0x46')]['id']}})[_0xf065('0x25')](handleEntityNotFound(_0x1c56ee,null))[_0xf065('0x25')](removeEntity(_0x1c56ee,null))[_0xf065('0x44')](handleError(_0x1c56ee,null));};exports[_0xf065('0x4a')]=function(_0x5e4b3e,_0x59fb97){var _0x4c69f6;return db[_0xf065('0x4b')][_0xf065('0x4c')](function(_0x319033){return db['CmCustomField'][_0xf065('0x4a')](_0x5e4b3e['body'],{'transaction':_0x319033})[_0xf065('0x25')](function(_0x474db8){_0x4c69f6=_0x474db8;var _0x19973a={'type':db[_0xf065('0x4d')][_0xf065('0x4e')],'transaction':_0x319033};switch(_0x5e4b3e[_0xf065('0x49')]['type']){case _0xf065('0x4f'):_0x19973a['type']=db[_0xf065('0x4d')][_0xf065('0x4e')];break;case'number':_0x19973a[_0xf065('0x2e')]=db[_0xf065('0x4d')][_0xf065('0x50')];break;case _0xf065('0x51'):_0x19973a[_0xf065('0x2e')]=db['Sequelize']['BOOLEAN'];_0x19973a[_0xf065('0x52')]=![];break;default:}return db[_0xf065('0x4b')][_0xf065('0x53')][_0xf065('0x54')](_0xf065('0x55'),util[_0xf065('0x56')](_0xf065('0x57'),_0x4c69f6['id']),_0x19973a);})[_0xf065('0x25')](function(){return _0x4c69f6;});})[_0xf065('0x25')](respondWithResult(_0x59fb97,0xc9))[_0xf065('0x44')](handleError(_0x59fb97,null));};