Built motion from commit 3c2ce842.|2.6.31
[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 _0x6f25=['body','create','sequelize','transaction','TEXT','switch','Sequelize','BOOLEAN','cm_contacts','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset','undefined','limit','count','set','apply','reject','save','update','then','destroy','error','map','rawAttributes','fieldName','type','key','model','differenceBy','name','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','where','pick','merge','VIRTUAL','filter','includeAll','include','CmCustomField','catch','params','keys','find'];(function(_0x479509,_0x1daf8a){var _0x382da8=function(_0x39d77c){while(--_0x39d77c){_0x479509['push'](_0x479509['shift']());}};_0x382da8(++_0x1daf8a);}(_0x6f25,0x199));var _0x56f2=function(_0x3f3a3a,_0x5e4af1){_0x3f3a3a=_0x3f3a3a-0x0;var _0x1eea67=_0x6f25[_0x3f3a3a];return _0x1eea67;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x56f2('0x0'));var jsonpatch=require(_0x56f2('0x1'));var rp=require(_0x56f2('0x2'));var moment=require(_0x56f2('0x3'));var BPromise=require(_0x56f2('0x4'));var Mustache=require('mustache');var util=require(_0x56f2('0x5'));var path=require(_0x56f2('0x6'));var sox=require('sox');var csv=require(_0x56f2('0x7'));var ejs=require(_0x56f2('0x8'));var fs=require('fs');var fs_extra=require(_0x56f2('0x9'));var _=require(_0x56f2('0xa'));var squel=require(_0x56f2('0xb'));var crypto=require(_0x56f2('0xc'));var jsforce=require(_0x56f2('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x56f2('0x7'));var querystring=require(_0x56f2('0xe'));var Papa=require(_0x56f2('0xf'));var Redis=require('ioredis');var authService=require(_0x56f2('0x10'));var qs=require(_0x56f2('0x11'));var as=require(_0x56f2('0x12'));var hardwareService=require(_0x56f2('0x13'));var logger=require(_0x56f2('0x14'))(_0x56f2('0x15'));var utils=require(_0x56f2('0x16'));var config=require(_0x56f2('0x17'));var licenseUtil=require(_0x56f2('0x18'));var db=require(_0x56f2('0x19'))['db'];function respondWithStatusCode(_0x56d894,_0x188687){_0x188687=_0x188687||0xcc;return function(_0x100617){if(_0x100617){return _0x56d894[_0x56f2('0x1a')](_0x188687);}return _0x56d894['status'](_0x188687)[_0x56f2('0x1b')]();};}function respondWithResult(_0x3d8afe,_0x16e5e8){_0x16e5e8=_0x16e5e8||0xc8;return function(_0x11072f){if(_0x11072f){return _0x3d8afe[_0x56f2('0x1c')](_0x16e5e8)[_0x56f2('0x1d')](_0x11072f);}};}function respondWithFilteredResult(_0x4261e3,_0x251098){return function(_0xed0aed){if(_0xed0aed){var _0x4aab05=typeof _0x251098[_0x56f2('0x1e')]===_0x56f2('0x1f')&&typeof _0x251098[_0x56f2('0x20')]===_0x56f2('0x1f');var _0xbb9acf=_0xed0aed[_0x56f2('0x21')];var _0x562877=_0x4aab05?0x0:_0x251098[_0x56f2('0x1e')];var _0x32ac25=_0x4aab05?_0xed0aed[_0x56f2('0x21')]:_0x251098[_0x56f2('0x1e')]+_0x251098[_0x56f2('0x20')];var _0x4fd4e9;if(_0x32ac25>=_0xbb9acf){_0x32ac25=_0xbb9acf;_0x4fd4e9=0xc8;}else{_0x4fd4e9=0xce;}_0x4261e3['status'](_0x4fd4e9);return _0x4261e3[_0x56f2('0x22')]('Content-Range',_0x562877+'-'+_0x32ac25+'/'+_0xbb9acf)[_0x56f2('0x1d')](_0xed0aed);}return null;};}function patchUpdates(_0x42bf36){return function(_0x2a10f9){try{jsonpatch[_0x56f2('0x23')](_0x2a10f9,_0x42bf36,!![]);}catch(_0x5103bb){return BPromise[_0x56f2('0x24')](_0x5103bb);}return _0x2a10f9[_0x56f2('0x25')]();};}function saveUpdates(_0x46532d,_0xde0d18){return function(_0x22599c){if(_0x22599c){return _0x22599c[_0x56f2('0x26')](_0x46532d)[_0x56f2('0x27')](function(_0x3a7962){return _0x3a7962;});}return null;};}function removeEntity(_0x5f3dc3,_0x5dd6f7){return function(_0x1713e2){if(_0x1713e2){return _0x1713e2[_0x56f2('0x28')]()[_0x56f2('0x27')](function(){_0x5f3dc3[_0x56f2('0x1c')](0xcc)[_0x56f2('0x1b')]();});}};}function handleEntityNotFound(_0x4ef047,_0x553d25){return function(_0x28fc5c){if(!_0x28fc5c){_0x4ef047['sendStatus'](0x194);}return _0x28fc5c;};}function handleError(_0x1eefc0,_0x37ba29){_0x37ba29=_0x37ba29||0x1f4;return function(_0xc2cbf9){logger[_0x56f2('0x29')](_0xc2cbf9['stack']);if(_0xc2cbf9['name']){delete _0xc2cbf9['name'];}_0x1eefc0[_0x56f2('0x1c')](_0x37ba29)['send'](_0xc2cbf9);};}exports['index']=function(_0x511fc2,_0x183993){var _0x999abd={},_0x4f2d9f={},_0x860543={'count':0x0,'rows':[]};var _0x367a4f=_[_0x56f2('0x2a')](db['CmCustomField'][_0x56f2('0x2b')],function(_0x2e827d){return{'name':_0x2e827d[_0x56f2('0x2c')],'type':_0x2e827d[_0x56f2('0x2d')][_0x56f2('0x2e')]};});_0x4f2d9f[_0x56f2('0x2f')]=_[_0x56f2('0x30')](_[_0x56f2('0x2a')](_0x367a4f,'name'),[_0x56f2('0x31')]);_0x4f2d9f['query']=_['keys'](_0x511fc2[_0x56f2('0x32')]);_0x4f2d9f[_0x56f2('0x33')]=_[_0x56f2('0x34')](_0x4f2d9f[_0x56f2('0x2f')],_0x4f2d9f[_0x56f2('0x32')]);_0x999abd['attributes']=_[_0x56f2('0x34')](_0x4f2d9f[_0x56f2('0x2f')],qs[_0x56f2('0x35')](_0x511fc2[_0x56f2('0x32')][_0x56f2('0x35')]));_0x999abd[_0x56f2('0x36')]=_0x999abd[_0x56f2('0x36')][_0x56f2('0x37')]?_0x999abd['attributes']:_0x4f2d9f[_0x56f2('0x2f')];if(!_0x511fc2['query'][_0x56f2('0x38')](_0x56f2('0x39'))){_0x999abd[_0x56f2('0x20')]=qs[_0x56f2('0x20')](_0x511fc2[_0x56f2('0x32')][_0x56f2('0x20')]);_0x999abd[_0x56f2('0x1e')]=qs[_0x56f2('0x1e')](_0x511fc2[_0x56f2('0x32')][_0x56f2('0x1e')]);}_0x999abd[_0x56f2('0x3a')]=qs['sort'](_0x511fc2[_0x56f2('0x32')]['sort']);_0x999abd[_0x56f2('0x3b')]=qs[_0x56f2('0x33')](_[_0x56f2('0x3c')](_0x511fc2[_0x56f2('0x32')],_0x4f2d9f[_0x56f2('0x33')]),_0x367a4f);if(_0x511fc2[_0x56f2('0x32')]['filter']){_0x999abd[_0x56f2('0x3b')]=_[_0x56f2('0x3d')](_0x999abd[_0x56f2('0x3b')],{'$or':_[_0x56f2('0x2a')](_0x367a4f,function(_0x487928){if(_0x487928['type']!==_0x56f2('0x3e')){var _0xf1c778={};_0xf1c778[_0x487928[_0x56f2('0x31')]]={'$like':'%'+_0x511fc2[_0x56f2('0x32')][_0x56f2('0x3f')]+'%'};return _0xf1c778;}})});}_0x999abd=_[_0x56f2('0x3d')]({},_0x999abd,_0x511fc2['options']);var _0x36f469={'where':_0x999abd[_0x56f2('0x3b')]};return db['CmCustomField'][_0x56f2('0x21')](_0x36f469)[_0x56f2('0x27')](function(_0x56d127){_0x860543['count']=_0x56d127;if(_0x511fc2[_0x56f2('0x32')][_0x56f2('0x40')]){_0x999abd[_0x56f2('0x41')]=[{'all':!![]}];}return db[_0x56f2('0x42')]['findAll'](_0x999abd);})[_0x56f2('0x27')](function(_0x3e60da){_0x860543['rows']=_0x3e60da;return _0x860543;})[_0x56f2('0x27')](respondWithFilteredResult(_0x183993,_0x999abd))[_0x56f2('0x43')](handleError(_0x183993,null));};exports['show']=function(_0x2511f6,_0x261a43){var _0x4cc61e={'raw':!![],'where':{'id':_0x2511f6[_0x56f2('0x44')]['id']}},_0x5d49a1={};_0x5d49a1['model']=_[_0x56f2('0x45')](db[_0x56f2('0x42')][_0x56f2('0x2b')]);_0x5d49a1['query']=_[_0x56f2('0x45')](_0x2511f6['query']);_0x5d49a1[_0x56f2('0x33')]=_[_0x56f2('0x34')](_0x5d49a1[_0x56f2('0x2f')],_0x5d49a1[_0x56f2('0x32')]);_0x4cc61e[_0x56f2('0x36')]=_[_0x56f2('0x34')](_0x5d49a1['model'],qs[_0x56f2('0x35')](_0x2511f6['query'][_0x56f2('0x35')]));_0x4cc61e[_0x56f2('0x36')]=_0x4cc61e[_0x56f2('0x36')][_0x56f2('0x37')]?_0x4cc61e[_0x56f2('0x36')]:_0x5d49a1['model'];if(_0x2511f6[_0x56f2('0x32')]['includeAll']){_0x4cc61e[_0x56f2('0x41')]=[{'all':!![]}];}_0x4cc61e=_[_0x56f2('0x3d')]({},_0x4cc61e,_0x2511f6['options']);return db[_0x56f2('0x42')][_0x56f2('0x46')](_0x4cc61e)[_0x56f2('0x27')](handleEntityNotFound(_0x261a43,null))[_0x56f2('0x27')](respondWithResult(_0x261a43,null))[_0x56f2('0x43')](handleError(_0x261a43,null));};exports[_0x56f2('0x26')]=function(_0x39c9d5,_0x36a39d){if(_0x39c9d5[_0x56f2('0x47')]['id']){delete _0x39c9d5['body']['id'];}return db[_0x56f2('0x42')]['find']({'where':{'id':_0x39c9d5[_0x56f2('0x44')]['id']}})[_0x56f2('0x27')](handleEntityNotFound(_0x36a39d,null))[_0x56f2('0x27')](saveUpdates(_0x39c9d5['body'],null))['then'](respondWithResult(_0x36a39d,null))[_0x56f2('0x43')](handleError(_0x36a39d,null));};exports[_0x56f2('0x28')]=function(_0x37adb5,_0x2c38d6){return db[_0x56f2('0x42')][_0x56f2('0x46')]({'where':{'id':_0x37adb5[_0x56f2('0x44')]['id']}})[_0x56f2('0x27')](handleEntityNotFound(_0x2c38d6,null))['then'](removeEntity(_0x2c38d6,null))['catch'](handleError(_0x2c38d6,null));};exports[_0x56f2('0x48')]=function(_0x2f217f,_0x496323){var _0x44d077;return db[_0x56f2('0x49')][_0x56f2('0x4a')](function(_0x5a7464){return db[_0x56f2('0x42')][_0x56f2('0x48')](_0x2f217f['body'],{'transaction':_0x5a7464})['then'](function(_0x524bac){_0x44d077=_0x524bac;var _0x56418c={'type':db['Sequelize'][_0x56f2('0x4b')],'transaction':_0x5a7464};switch(_0x2f217f[_0x56f2('0x47')][_0x56f2('0x2d')]){case'text':_0x56418c[_0x56f2('0x2d')]=db['Sequelize'][_0x56f2('0x4b')];break;case'number':_0x56418c[_0x56f2('0x2d')]=db['Sequelize']['INTEGER'];break;case _0x56f2('0x4c'):_0x56418c[_0x56f2('0x2d')]=db[_0x56f2('0x4d')][_0x56f2('0x4e')];_0x56418c['defaultValue']=![];break;default:}return db[_0x56f2('0x49')]['queryInterface']['addColumn'](_0x56f2('0x4f'),util['format']('cf_%d',_0x44d077['id']),_0x56418c);})[_0x56f2('0x27')](function(){return _0x44d077;});})[_0x56f2('0x27')](respondWithResult(_0x496323,0xc9))[_0x56f2('0x43')](handleError(_0x496323,null));};