Built motion from commit 85328c08.|2.5.50
[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 _0x30f6=['status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','error','stack','name','send','index','CmCustomField','model','differenceBy','map','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','type','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','keys','rawAttributes','find','body','sequelize','transaction','create','Sequelize','TEXT','text','number','switch','BOOLEAN','defaultValue','queryInterface','addColumn','cm_contacts','format','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus'];(function(_0x53da6c,_0x5930d4){var _0x33c828=function(_0x4f8960){while(--_0x4f8960){_0x53da6c['push'](_0x53da6c['shift']());}};_0x33c828(++_0x5930d4);}(_0x30f6,0x1ac));var _0x630f=function(_0x44d5b7,_0x38c266){_0x44d5b7=_0x44d5b7-0x0;var _0x44f102=_0x30f6[_0x44d5b7];return _0x44f102;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x630f('0x0'));var rp=require(_0x630f('0x1'));var moment=require(_0x630f('0x2'));var BPromise=require(_0x630f('0x3'));var Mustache=require(_0x630f('0x4'));var util=require('util');var path=require(_0x630f('0x5'));var sox=require(_0x630f('0x6'));var csv=require(_0x630f('0x7'));var ejs=require(_0x630f('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x630f('0x9'));var squel=require(_0x630f('0xa'));var crypto=require(_0x630f('0xb'));var jsforce=require(_0x630f('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x630f('0x7'));var querystring=require(_0x630f('0xd'));var Papa=require(_0x630f('0xe'));var Redis=require(_0x630f('0xf'));var authService=require(_0x630f('0x10'));var qs=require(_0x630f('0x11'));var as=require(_0x630f('0x12'));var hardwareService=require(_0x630f('0x13'));var logger=require(_0x630f('0x14'))(_0x630f('0x15'));var utils=require(_0x630f('0x16'));var config=require(_0x630f('0x17'));var licenseUtil=require(_0x630f('0x18'));var db=require(_0x630f('0x19'))['db'];function respondWithStatusCode(_0x57e526,_0x423506){_0x423506=_0x423506||0xcc;return function(_0x1dba7a){if(_0x1dba7a){return _0x57e526[_0x630f('0x1a')](_0x423506);}return _0x57e526[_0x630f('0x1b')](_0x423506)[_0x630f('0x1c')]();};}function respondWithResult(_0x2ae8dd,_0x59b8d6){_0x59b8d6=_0x59b8d6||0xc8;return function(_0x22f169){if(_0x22f169){return _0x2ae8dd[_0x630f('0x1b')](_0x59b8d6)[_0x630f('0x1d')](_0x22f169);}};}function respondWithFilteredResult(_0x58ff40,_0x5ac35c){return function(_0x839b32){if(_0x839b32){var _0x1ea237=typeof _0x5ac35c[_0x630f('0x1e')]===_0x630f('0x1f')&&typeof _0x5ac35c[_0x630f('0x20')]==='undefined';var _0x46c747=_0x839b32[_0x630f('0x21')];var _0x1388ef=_0x1ea237?0x0:_0x5ac35c[_0x630f('0x1e')];var _0x18ca93=_0x1ea237?_0x839b32[_0x630f('0x21')]:_0x5ac35c[_0x630f('0x1e')]+_0x5ac35c['limit'];var _0x383951;if(_0x18ca93>=_0x46c747){_0x18ca93=_0x46c747;_0x383951=0xc8;}else{_0x383951=0xce;}_0x58ff40['status'](_0x383951);return _0x58ff40[_0x630f('0x22')](_0x630f('0x23'),_0x1388ef+'-'+_0x18ca93+'/'+_0x46c747)[_0x630f('0x1d')](_0x839b32);}return null;};}function patchUpdates(_0x81f344){return function(_0xd9480e){try{jsonpatch[_0x630f('0x24')](_0xd9480e,_0x81f344,!![]);}catch(_0x136fd6){return BPromise[_0x630f('0x25')](_0x136fd6);}return _0xd9480e[_0x630f('0x26')]();};}function saveUpdates(_0x21e04c,_0x396a58){return function(_0x6cf7b8){if(_0x6cf7b8){return _0x6cf7b8[_0x630f('0x27')](_0x21e04c)[_0x630f('0x28')](function(_0x45d171){return _0x45d171;});}return null;};}function removeEntity(_0x3bd679,_0x1aa7dc){return function(_0x4912d6){if(_0x4912d6){return _0x4912d6['destroy']()[_0x630f('0x28')](function(){_0x3bd679[_0x630f('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3a0c54,_0xbd296a){return function(_0x3c0035){if(!_0x3c0035){_0x3a0c54[_0x630f('0x1a')](0x194);}return _0x3c0035;};}function handleError(_0x1add50,_0x3642f0){_0x3642f0=_0x3642f0||0x1f4;return function(_0x529737){logger[_0x630f('0x29')](_0x529737[_0x630f('0x2a')]);if(_0x529737['name']){delete _0x529737[_0x630f('0x2b')];}_0x1add50[_0x630f('0x1b')](_0x3642f0)[_0x630f('0x2c')](_0x529737);};}exports[_0x630f('0x2d')]=function(_0x20fe4c,_0x4e5b6d){var _0x20392e={},_0x190703={},_0x194e6b={'count':0x0,'rows':[]};var _0x20eba5=_['map'](db[_0x630f('0x2e')]['rawAttributes'],function(_0x1a9d05){return{'name':_0x1a9d05['fieldName'],'type':_0x1a9d05['type']['key']};});_0x190703[_0x630f('0x2f')]=_[_0x630f('0x30')](_[_0x630f('0x31')](_0x20eba5,'name'),[_0x630f('0x2b')]);_0x190703[_0x630f('0x32')]=_['keys'](_0x20fe4c[_0x630f('0x32')]);_0x190703[_0x630f('0x33')]=_[_0x630f('0x34')](_0x190703[_0x630f('0x2f')],_0x190703[_0x630f('0x32')]);_0x20392e['attributes']=_[_0x630f('0x34')](_0x190703[_0x630f('0x2f')],qs['fields'](_0x20fe4c['query'][_0x630f('0x35')]));_0x20392e[_0x630f('0x36')]=_0x20392e[_0x630f('0x36')][_0x630f('0x37')]?_0x20392e[_0x630f('0x36')]:_0x190703[_0x630f('0x2f')];if(!_0x20fe4c[_0x630f('0x32')][_0x630f('0x38')](_0x630f('0x39'))){_0x20392e[_0x630f('0x20')]=qs[_0x630f('0x20')](_0x20fe4c[_0x630f('0x32')][_0x630f('0x20')]);_0x20392e[_0x630f('0x1e')]=qs['offset'](_0x20fe4c[_0x630f('0x32')][_0x630f('0x1e')]);}_0x20392e[_0x630f('0x3a')]=qs[_0x630f('0x3b')](_0x20fe4c['query'][_0x630f('0x3b')]);_0x20392e[_0x630f('0x3c')]=qs[_0x630f('0x33')](_['pick'](_0x20fe4c[_0x630f('0x32')],_0x190703[_0x630f('0x33')]),_0x20eba5);if(_0x20fe4c[_0x630f('0x32')][_0x630f('0x3d')]){_0x20392e['where']=_[_0x630f('0x3e')](_0x20392e['where'],{'$or':_[_0x630f('0x31')](_0x20eba5,function(_0x5f8b1d){if(_0x5f8b1d[_0x630f('0x3f')]!==_0x630f('0x40')){var _0x150904={};_0x150904[_0x5f8b1d[_0x630f('0x2b')]]={'$like':'%'+_0x20fe4c[_0x630f('0x32')][_0x630f('0x3d')]+'%'};return _0x150904;}})});}_0x20392e=_[_0x630f('0x3e')]({},_0x20392e,_0x20fe4c[_0x630f('0x41')]);var _0x3f6e7e={'where':_0x20392e['where']};return db[_0x630f('0x2e')][_0x630f('0x21')](_0x3f6e7e)[_0x630f('0x28')](function(_0x3e7e82){_0x194e6b['count']=_0x3e7e82;if(_0x20fe4c[_0x630f('0x32')][_0x630f('0x42')]){_0x20392e[_0x630f('0x43')]=[{'all':!![]}];}return db[_0x630f('0x2e')][_0x630f('0x44')](_0x20392e);})[_0x630f('0x28')](function(_0x4c422e){_0x194e6b[_0x630f('0x45')]=_0x4c422e;return _0x194e6b;})[_0x630f('0x28')](respondWithFilteredResult(_0x4e5b6d,_0x20392e))[_0x630f('0x46')](handleError(_0x4e5b6d,null));};exports[_0x630f('0x47')]=function(_0x43e27f,_0x341709){var _0x29c50c={'raw':!![],'where':{'id':_0x43e27f[_0x630f('0x48')]['id']}},_0x296fac={};_0x296fac[_0x630f('0x2f')]=_[_0x630f('0x49')](db[_0x630f('0x2e')][_0x630f('0x4a')]);_0x296fac[_0x630f('0x32')]=_[_0x630f('0x49')](_0x43e27f[_0x630f('0x32')]);_0x296fac['filters']=_[_0x630f('0x34')](_0x296fac[_0x630f('0x2f')],_0x296fac['query']);_0x29c50c[_0x630f('0x36')]=_[_0x630f('0x34')](_0x296fac[_0x630f('0x2f')],qs[_0x630f('0x35')](_0x43e27f[_0x630f('0x32')][_0x630f('0x35')]));_0x29c50c[_0x630f('0x36')]=_0x29c50c['attributes']['length']?_0x29c50c[_0x630f('0x36')]:_0x296fac['model'];if(_0x43e27f[_0x630f('0x32')][_0x630f('0x42')]){_0x29c50c[_0x630f('0x43')]=[{'all':!![]}];}_0x29c50c=_['merge']({},_0x29c50c,_0x43e27f[_0x630f('0x41')]);return db[_0x630f('0x2e')][_0x630f('0x4b')](_0x29c50c)[_0x630f('0x28')](handleEntityNotFound(_0x341709,null))[_0x630f('0x28')](respondWithResult(_0x341709,null))[_0x630f('0x46')](handleError(_0x341709,null));};exports['update']=function(_0xfe7452,_0x5a854c){if(_0xfe7452[_0x630f('0x4c')]['id']){delete _0xfe7452[_0x630f('0x4c')]['id'];}return db[_0x630f('0x2e')][_0x630f('0x4b')]({'where':{'id':_0xfe7452['params']['id']}})[_0x630f('0x28')](handleEntityNotFound(_0x5a854c,null))['then'](saveUpdates(_0xfe7452[_0x630f('0x4c')],null))[_0x630f('0x28')](respondWithResult(_0x5a854c,null))['catch'](handleError(_0x5a854c,null));};exports['destroy']=function(_0x321d4e,_0x4972bb){return db[_0x630f('0x2e')][_0x630f('0x4b')]({'where':{'id':_0x321d4e['params']['id']}})['then'](handleEntityNotFound(_0x4972bb,null))[_0x630f('0x28')](removeEntity(_0x4972bb,null))[_0x630f('0x46')](handleError(_0x4972bb,null));};exports['create']=function(_0x4d8848,_0x16ce9b){var _0x40dce3;return db[_0x630f('0x4d')][_0x630f('0x4e')](function(_0xa2ed82){return db[_0x630f('0x2e')][_0x630f('0x4f')](_0x4d8848[_0x630f('0x4c')],{'transaction':_0xa2ed82})['then'](function(_0x4b2683){_0x40dce3=_0x4b2683;var _0x1f78a4={'type':db[_0x630f('0x50')][_0x630f('0x51')],'transaction':_0xa2ed82};switch(_0x4d8848['body']['type']){case _0x630f('0x52'):_0x1f78a4[_0x630f('0x3f')]=db[_0x630f('0x50')][_0x630f('0x51')];break;case _0x630f('0x53'):_0x1f78a4[_0x630f('0x3f')]=db[_0x630f('0x50')]['INTEGER'];break;case _0x630f('0x54'):_0x1f78a4[_0x630f('0x3f')]=db['Sequelize'][_0x630f('0x55')];_0x1f78a4[_0x630f('0x56')]=![];break;default:}return db[_0x630f('0x4d')][_0x630f('0x57')][_0x630f('0x58')](_0x630f('0x59'),util[_0x630f('0x5a')]('cf_%d',_0x40dce3['id']),_0x1f78a4);})[_0x630f('0x28')](function(){return _0x40dce3;});})[_0x630f('0x28')](respondWithResult(_0x16ce9b,0xc9))[_0x630f('0x46')](handleError(_0x16ce9b,null));};