Built motion from commit 753c950e.|2.5.42
[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 _0xf123=['squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','end','status','offset','undefined','count','limit','set','Content-Range','json','apply','reject','save','then','destroy','sendStatus','stack','name','send','index','map','CmCustomField','rawAttributes','fieldName','key','model','differenceBy','query','keys','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','filters','pick','filter','where','merge','type','VIRTUAL','options','includeAll','findAll','catch','params','include','update','body','find','transaction','create','Sequelize','TEXT','number','INTEGER','switch','defaultValue','sequelize','queryInterface','addColumn','cm_contacts','cf_%d','fast-json-patch','request-promise','moment','util','path','sox','ejs','fs-extra','lodash'];(function(_0x2fc4db,_0x34003f){var _0x1f8e51=function(_0x153a4f){while(--_0x153a4f){_0x2fc4db['push'](_0x2fc4db['shift']());}};_0x1f8e51(++_0x34003f);}(_0xf123,0x1aa));var _0x3f12=function(_0x1a3e23,_0xce45e){_0x1a3e23=_0x1a3e23-0x0;var _0x5ee0d8=_0xf123[_0x1a3e23];return _0x5ee0d8;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x3f12('0x0'));var rp=require(_0x3f12('0x1'));var moment=require(_0x3f12('0x2'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x3f12('0x3'));var path=require(_0x3f12('0x4'));var sox=require(_0x3f12('0x5'));var csv=require('to-csv');var ejs=require(_0x3f12('0x6'));var fs=require('fs');var fs_extra=require(_0x3f12('0x7'));var _=require(_0x3f12('0x8'));var squel=require(_0x3f12('0x9'));var crypto=require(_0x3f12('0xa'));var jsforce=require(_0x3f12('0xb'));var deskjs=require('desk.js');var toCsv=require(_0x3f12('0xc'));var querystring=require(_0x3f12('0xd'));var Papa=require(_0x3f12('0xe'));var Redis=require(_0x3f12('0xf'));var authService=require('../../components/auth/service');var qs=require(_0x3f12('0x10'));var as=require(_0x3f12('0x11'));var hardwareService=require(_0x3f12('0x12'));var logger=require(_0x3f12('0x13'))('api');var utils=require('../../config/utils');var config=require(_0x3f12('0x14'));var licenseUtil=require(_0x3f12('0x15'));var db=require(_0x3f12('0x16'))['db'];function respondWithStatusCode(_0x16ce4a,_0xf10879){_0xf10879=_0xf10879||0xcc;return function(_0x1cde6b){if(_0x1cde6b){return _0x16ce4a['sendStatus'](_0xf10879);}return _0x16ce4a['status'](_0xf10879)[_0x3f12('0x17')]();};}function respondWithResult(_0x3bf1f2,_0x325122){_0x325122=_0x325122||0xc8;return function(_0x5ca74e){if(_0x5ca74e){return _0x3bf1f2[_0x3f12('0x18')](_0x325122)['json'](_0x5ca74e);}};}function respondWithFilteredResult(_0x2513d1,_0x31a0de){return function(_0x13b56e){if(_0x13b56e){var _0x36e31a=typeof _0x31a0de[_0x3f12('0x19')]===_0x3f12('0x1a')&&typeof _0x31a0de['limit']==='undefined';var _0x3b1c90=_0x13b56e[_0x3f12('0x1b')];var _0x1ca537=_0x36e31a?0x0:_0x31a0de['offset'];var _0x4c7f8a=_0x36e31a?_0x13b56e[_0x3f12('0x1b')]:_0x31a0de[_0x3f12('0x19')]+_0x31a0de[_0x3f12('0x1c')];var _0x286c49;if(_0x4c7f8a>=_0x3b1c90){_0x4c7f8a=_0x3b1c90;_0x286c49=0xc8;}else{_0x286c49=0xce;}_0x2513d1[_0x3f12('0x18')](_0x286c49);return _0x2513d1[_0x3f12('0x1d')](_0x3f12('0x1e'),_0x1ca537+'-'+_0x4c7f8a+'/'+_0x3b1c90)[_0x3f12('0x1f')](_0x13b56e);}return null;};}function patchUpdates(_0x1422d4){return function(_0x1759a9){try{jsonpatch[_0x3f12('0x20')](_0x1759a9,_0x1422d4,!![]);}catch(_0x11de66){return BPromise[_0x3f12('0x21')](_0x11de66);}return _0x1759a9[_0x3f12('0x22')]();};}function saveUpdates(_0x315cf9,_0x235269){return function(_0x27f710){if(_0x27f710){return _0x27f710['update'](_0x315cf9)[_0x3f12('0x23')](function(_0x3d50e3){return _0x3d50e3;});}return null;};}function removeEntity(_0x43cef4,_0x1ce0fc){return function(_0x5ed4f3){if(_0x5ed4f3){return _0x5ed4f3[_0x3f12('0x24')]()[_0x3f12('0x23')](function(){_0x43cef4['status'](0xcc)[_0x3f12('0x17')]();});}};}function handleEntityNotFound(_0x1fb0e9,_0x50b228){return function(_0x3350fb){if(!_0x3350fb){_0x1fb0e9[_0x3f12('0x25')](0x194);}return _0x3350fb;};}function handleError(_0x480174,_0x3dfd94){_0x3dfd94=_0x3dfd94||0x1f4;return function(_0x4aff22){logger['error'](_0x4aff22[_0x3f12('0x26')]);if(_0x4aff22[_0x3f12('0x27')]){delete _0x4aff22[_0x3f12('0x27')];}_0x480174[_0x3f12('0x18')](_0x3dfd94)[_0x3f12('0x28')](_0x4aff22);};}exports[_0x3f12('0x29')]=function(_0x382b72,_0xf916cb){var _0x26780d={},_0x5e5ad0={},_0x2bf64e={'count':0x0,'rows':[]};var _0x409338=_[_0x3f12('0x2a')](db[_0x3f12('0x2b')][_0x3f12('0x2c')],function(_0x57c353){return{'name':_0x57c353[_0x3f12('0x2d')],'type':_0x57c353['type'][_0x3f12('0x2e')]};});_0x5e5ad0[_0x3f12('0x2f')]=_[_0x3f12('0x30')](_[_0x3f12('0x2a')](_0x409338,_0x3f12('0x27')),[_0x3f12('0x27')]);_0x5e5ad0[_0x3f12('0x31')]=_[_0x3f12('0x32')](_0x382b72[_0x3f12('0x31')]);_0x5e5ad0['filters']=_[_0x3f12('0x33')](_0x5e5ad0[_0x3f12('0x2f')],_0x5e5ad0[_0x3f12('0x31')]);_0x26780d['attributes']=_[_0x3f12('0x33')](_0x5e5ad0[_0x3f12('0x2f')],qs[_0x3f12('0x34')](_0x382b72['query'][_0x3f12('0x34')]));_0x26780d['attributes']=_0x26780d[_0x3f12('0x35')][_0x3f12('0x36')]?_0x26780d['attributes']:_0x5e5ad0[_0x3f12('0x2f')];if(!_0x382b72[_0x3f12('0x31')][_0x3f12('0x37')](_0x3f12('0x38'))){_0x26780d[_0x3f12('0x1c')]=qs['limit'](_0x382b72[_0x3f12('0x31')][_0x3f12('0x1c')]);_0x26780d[_0x3f12('0x19')]=qs[_0x3f12('0x19')](_0x382b72[_0x3f12('0x31')][_0x3f12('0x19')]);}_0x26780d['order']=qs['sort'](_0x382b72['query'][_0x3f12('0x39')]);_0x26780d['where']=qs[_0x3f12('0x3a')](_[_0x3f12('0x3b')](_0x382b72[_0x3f12('0x31')],_0x5e5ad0[_0x3f12('0x3a')]),_0x409338);if(_0x382b72[_0x3f12('0x31')][_0x3f12('0x3c')]){_0x26780d[_0x3f12('0x3d')]=_[_0x3f12('0x3e')](_0x26780d['where'],{'$or':_['map'](_0x409338,function(_0x5cf34e){if(_0x5cf34e[_0x3f12('0x3f')]!==_0x3f12('0x40')){var _0x4eee8a={};_0x4eee8a[_0x5cf34e['name']]={'$like':'%'+_0x382b72[_0x3f12('0x31')][_0x3f12('0x3c')]+'%'};return _0x4eee8a;}})});}_0x26780d=_[_0x3f12('0x3e')]({},_0x26780d,_0x382b72[_0x3f12('0x41')]);var _0x28d28d={'where':_0x26780d[_0x3f12('0x3d')]};return db['CmCustomField']['count'](_0x28d28d)[_0x3f12('0x23')](function(_0x48f708){_0x2bf64e[_0x3f12('0x1b')]=_0x48f708;if(_0x382b72[_0x3f12('0x31')][_0x3f12('0x42')]){_0x26780d['include']=[{'all':!![]}];}return db[_0x3f12('0x2b')][_0x3f12('0x43')](_0x26780d);})[_0x3f12('0x23')](function(_0x395e4d){_0x2bf64e['rows']=_0x395e4d;return _0x2bf64e;})['then'](respondWithFilteredResult(_0xf916cb,_0x26780d))[_0x3f12('0x44')](handleError(_0xf916cb,null));};exports['show']=function(_0x5384c9,_0x4ea82e){var _0x75c3a7={'raw':!![],'where':{'id':_0x5384c9[_0x3f12('0x45')]['id']}},_0xbb82a1={};_0xbb82a1[_0x3f12('0x2f')]=_[_0x3f12('0x32')](db[_0x3f12('0x2b')][_0x3f12('0x2c')]);_0xbb82a1[_0x3f12('0x31')]=_[_0x3f12('0x32')](_0x5384c9[_0x3f12('0x31')]);_0xbb82a1[_0x3f12('0x3a')]=_[_0x3f12('0x33')](_0xbb82a1[_0x3f12('0x2f')],_0xbb82a1['query']);_0x75c3a7['attributes']=_['intersection'](_0xbb82a1[_0x3f12('0x2f')],qs['fields'](_0x5384c9[_0x3f12('0x31')]['fields']));_0x75c3a7['attributes']=_0x75c3a7[_0x3f12('0x35')]['length']?_0x75c3a7[_0x3f12('0x35')]:_0xbb82a1[_0x3f12('0x2f')];if(_0x5384c9[_0x3f12('0x31')][_0x3f12('0x42')]){_0x75c3a7[_0x3f12('0x46')]=[{'all':!![]}];}_0x75c3a7=_['merge']({},_0x75c3a7,_0x5384c9['options']);return db[_0x3f12('0x2b')]['find'](_0x75c3a7)[_0x3f12('0x23')](handleEntityNotFound(_0x4ea82e,null))[_0x3f12('0x23')](respondWithResult(_0x4ea82e,null))['catch'](handleError(_0x4ea82e,null));};exports[_0x3f12('0x47')]=function(_0x2cc597,_0x2eebfe){if(_0x2cc597[_0x3f12('0x48')]['id']){delete _0x2cc597[_0x3f12('0x48')]['id'];}return db[_0x3f12('0x2b')][_0x3f12('0x49')]({'where':{'id':_0x2cc597[_0x3f12('0x45')]['id']}})[_0x3f12('0x23')](handleEntityNotFound(_0x2eebfe,null))[_0x3f12('0x23')](saveUpdates(_0x2cc597['body'],null))[_0x3f12('0x23')](respondWithResult(_0x2eebfe,null))[_0x3f12('0x44')](handleError(_0x2eebfe,null));};exports['destroy']=function(_0x4b3f93,_0x33ac42){return db[_0x3f12('0x2b')]['find']({'where':{'id':_0x4b3f93[_0x3f12('0x45')]['id']}})[_0x3f12('0x23')](handleEntityNotFound(_0x33ac42,null))[_0x3f12('0x23')](removeEntity(_0x33ac42,null))[_0x3f12('0x44')](handleError(_0x33ac42,null));};exports['create']=function(_0x46bad7,_0xfcd8a9){var _0x5b4e37;return db['sequelize'][_0x3f12('0x4a')](function(_0x2c0e2a){return db['CmCustomField'][_0x3f12('0x4b')](_0x46bad7[_0x3f12('0x48')],{'transaction':_0x2c0e2a})['then'](function(_0x55286a){_0x5b4e37=_0x55286a;var _0x1ad68d={'type':db[_0x3f12('0x4c')][_0x3f12('0x4d')],'transaction':_0x2c0e2a};switch(_0x46bad7[_0x3f12('0x48')][_0x3f12('0x3f')]){case'text':_0x1ad68d[_0x3f12('0x3f')]=db['Sequelize'][_0x3f12('0x4d')];break;case _0x3f12('0x4e'):_0x1ad68d['type']=db['Sequelize'][_0x3f12('0x4f')];break;case _0x3f12('0x50'):_0x1ad68d[_0x3f12('0x3f')]=db[_0x3f12('0x4c')]['BOOLEAN'];_0x1ad68d[_0x3f12('0x51')]=![];break;default:}return db[_0x3f12('0x52')][_0x3f12('0x53')][_0x3f12('0x54')](_0x3f12('0x55'),util['format'](_0x3f12('0x56'),_0x5b4e37['id']),_0x1ad68d);})[_0x3f12('0x23')](function(){return _0x5b4e37;});})[_0x3f12('0x23')](respondWithResult(_0xfcd8a9,0xc9))['catch'](handleError(_0xfcd8a9,null));};