1011c6530e5085a2f0f3ec749b0f44e4462ebcd6
[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 _0x3ab5=['destroy','then','error','stack','name','send','index','map','CmCustomField','rawAttributes','fieldName','type','key','model','differenceBy','query','keys','intersection','attributes','length','order','sort','where','filters','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','fields','find','update','body','params','create','sequelize','transaction','Sequelize','TEXT','text','INTEGER','switch','BOOLEAN','queryInterface','addColumn','cm_contacts','format','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','path','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','status','json','offset','undefined','limit','count','Content-Range','apply','reject','save'];(function(_0x499dd8,_0xeb6484){var _0x390e65=function(_0x4e00fa){while(--_0x4e00fa){_0x499dd8['push'](_0x499dd8['shift']());}};_0x390e65(++_0xeb6484);}(_0x3ab5,0x88));var _0x53ab=function(_0x30ae5e,_0x391fc4){_0x30ae5e=_0x30ae5e-0x0;var _0x1f2e93=_0x3ab5[_0x30ae5e];return _0x1f2e93;};'use strict';var emlformat=require(_0x53ab('0x0'));var rimraf=require(_0x53ab('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x53ab('0x2'));var rp=require(_0x53ab('0x3'));var moment=require(_0x53ab('0x4'));var BPromise=require(_0x53ab('0x5'));var Mustache=require(_0x53ab('0x6'));var util=require('util');var path=require(_0x53ab('0x7'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x53ab('0x8'));var fs=require('fs');var fs_extra=require(_0x53ab('0x9'));var _=require(_0x53ab('0xa'));var squel=require(_0x53ab('0xb'));var crypto=require(_0x53ab('0xc'));var jsforce=require(_0x53ab('0xd'));var deskjs=require(_0x53ab('0xe'));var toCsv=require(_0x53ab('0xf'));var querystring=require(_0x53ab('0x10'));var Papa=require(_0x53ab('0x11'));var Redis=require('ioredis');var authService=require(_0x53ab('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x53ab('0x13'));var hardwareService=require(_0x53ab('0x14'));var logger=require('../../config/logger')('api');var utils=require(_0x53ab('0x15'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x6423e4,_0x3d07a0){_0x3d07a0=_0x3d07a0||0xcc;return function(_0x15cf64){if(_0x15cf64){return _0x6423e4['sendStatus'](_0x3d07a0);}return _0x6423e4[_0x53ab('0x16')](_0x3d07a0)['end']();};}function respondWithResult(_0x4b1715,_0xf697f7){_0xf697f7=_0xf697f7||0xc8;return function(_0x4c3649){if(_0x4c3649){return _0x4b1715[_0x53ab('0x16')](_0xf697f7)[_0x53ab('0x17')](_0x4c3649);}};}function respondWithFilteredResult(_0x14aafa,_0x6ddd){return function(_0x3d623c){if(_0x3d623c){var _0x234173=typeof _0x6ddd[_0x53ab('0x18')]===_0x53ab('0x19')&&typeof _0x6ddd[_0x53ab('0x1a')]===_0x53ab('0x19');var _0x3aa58c=_0x3d623c[_0x53ab('0x1b')];var _0x485fbb=_0x234173?0x0:_0x6ddd['offset'];var _0x4adbd9=_0x234173?_0x3d623c[_0x53ab('0x1b')]:_0x6ddd[_0x53ab('0x18')]+_0x6ddd[_0x53ab('0x1a')];var _0x1cda94;if(_0x4adbd9>=_0x3aa58c){_0x4adbd9=_0x3aa58c;_0x1cda94=0xc8;}else{_0x1cda94=0xce;}_0x14aafa[_0x53ab('0x16')](_0x1cda94);return _0x14aafa['set'](_0x53ab('0x1c'),_0x485fbb+'-'+_0x4adbd9+'/'+_0x3aa58c)[_0x53ab('0x17')](_0x3d623c);}return null;};}function patchUpdates(_0x1b151d){return function(_0x266742){try{jsonpatch[_0x53ab('0x1d')](_0x266742,_0x1b151d,!![]);}catch(_0x1450c7){return BPromise[_0x53ab('0x1e')](_0x1450c7);}return _0x266742[_0x53ab('0x1f')]();};}function saveUpdates(_0x5eb82e,_0x11cbcb){return function(_0x3c0e10){if(_0x3c0e10){return _0x3c0e10['update'](_0x5eb82e)['then'](function(_0x19f08a){return _0x19f08a;});}return null;};}function removeEntity(_0x42f57c,_0x2d4e5c){return function(_0x524d07){if(_0x524d07){return _0x524d07[_0x53ab('0x20')]()[_0x53ab('0x21')](function(){_0x42f57c[_0x53ab('0x16')](0xcc)['end']();});}};}function handleEntityNotFound(_0x26d139,_0x38100a){return function(_0x4e79d1){if(!_0x4e79d1){_0x26d139['sendStatus'](0x194);}return _0x4e79d1;};}function handleError(_0x195314,_0x1d4ba8){_0x1d4ba8=_0x1d4ba8||0x1f4;return function(_0x443f1c){logger[_0x53ab('0x22')](_0x443f1c[_0x53ab('0x23')]);if(_0x443f1c[_0x53ab('0x24')]){delete _0x443f1c['name'];}_0x195314[_0x53ab('0x16')](_0x1d4ba8)[_0x53ab('0x25')](_0x443f1c);};}exports[_0x53ab('0x26')]=function(_0x5e5dd0,_0x54e54c){var _0x4f4996={},_0x215c64={},_0x290a82={'count':0x0,'rows':[]};var _0x16dbc6=_[_0x53ab('0x27')](db[_0x53ab('0x28')][_0x53ab('0x29')],function(_0x4042f0){return{'name':_0x4042f0[_0x53ab('0x2a')],'type':_0x4042f0[_0x53ab('0x2b')][_0x53ab('0x2c')]};});_0x215c64[_0x53ab('0x2d')]=_[_0x53ab('0x2e')](_[_0x53ab('0x27')](_0x16dbc6,_0x53ab('0x24')),[_0x53ab('0x24')]);_0x215c64[_0x53ab('0x2f')]=_[_0x53ab('0x30')](_0x5e5dd0[_0x53ab('0x2f')]);_0x215c64['filters']=_[_0x53ab('0x31')](_0x215c64[_0x53ab('0x2d')],_0x215c64['query']);_0x4f4996['attributes']=_[_0x53ab('0x31')](_0x215c64[_0x53ab('0x2d')],qs['fields'](_0x5e5dd0[_0x53ab('0x2f')]['fields']));_0x4f4996[_0x53ab('0x32')]=_0x4f4996['attributes'][_0x53ab('0x33')]?_0x4f4996['attributes']:_0x215c64[_0x53ab('0x2d')];if(!_0x5e5dd0[_0x53ab('0x2f')]['hasOwnProperty']('nolimit')){_0x4f4996[_0x53ab('0x1a')]=qs['limit'](_0x5e5dd0[_0x53ab('0x2f')]['limit']);_0x4f4996[_0x53ab('0x18')]=qs[_0x53ab('0x18')](_0x5e5dd0[_0x53ab('0x2f')][_0x53ab('0x18')]);}_0x4f4996[_0x53ab('0x34')]=qs[_0x53ab('0x35')](_0x5e5dd0[_0x53ab('0x2f')][_0x53ab('0x35')]);_0x4f4996[_0x53ab('0x36')]=qs[_0x53ab('0x37')](_['pick'](_0x5e5dd0[_0x53ab('0x2f')],_0x215c64[_0x53ab('0x37')]),_0x16dbc6);if(_0x5e5dd0[_0x53ab('0x2f')][_0x53ab('0x38')]){_0x4f4996['where']=_[_0x53ab('0x39')](_0x4f4996[_0x53ab('0x36')],{'$or':_[_0x53ab('0x27')](_0x16dbc6,function(_0x1d12d1){if(_0x1d12d1[_0x53ab('0x2b')]!==_0x53ab('0x3a')){var _0x84b48d={};_0x84b48d[_0x1d12d1['name']]={'$like':'%'+_0x5e5dd0['query'][_0x53ab('0x38')]+'%'};return _0x84b48d;}})});}_0x4f4996=_['merge']({},_0x4f4996,_0x5e5dd0[_0x53ab('0x3b')]);var _0x29a952={'where':_0x4f4996[_0x53ab('0x36')]};return db[_0x53ab('0x28')][_0x53ab('0x1b')](_0x29a952)[_0x53ab('0x21')](function(_0x420354){_0x290a82[_0x53ab('0x1b')]=_0x420354;if(_0x5e5dd0[_0x53ab('0x2f')][_0x53ab('0x3c')]){_0x4f4996[_0x53ab('0x3d')]=[{'all':!![]}];}return db[_0x53ab('0x28')][_0x53ab('0x3e')](_0x4f4996);})[_0x53ab('0x21')](function(_0x3516e1){_0x290a82[_0x53ab('0x3f')]=_0x3516e1;return _0x290a82;})[_0x53ab('0x21')](respondWithFilteredResult(_0x54e54c,_0x4f4996))[_0x53ab('0x40')](handleError(_0x54e54c,null));};exports[_0x53ab('0x41')]=function(_0x882e5c,_0x5eb3c5){var _0x426b47={'raw':!![],'where':{'id':_0x882e5c['params']['id']}},_0x4bf581={};_0x4bf581['model']=_['keys'](db[_0x53ab('0x28')][_0x53ab('0x29')]);_0x4bf581[_0x53ab('0x2f')]=_[_0x53ab('0x30')](_0x882e5c['query']);_0x4bf581[_0x53ab('0x37')]=_[_0x53ab('0x31')](_0x4bf581['model'],_0x4bf581[_0x53ab('0x2f')]);_0x426b47['attributes']=_[_0x53ab('0x31')](_0x4bf581['model'],qs[_0x53ab('0x42')](_0x882e5c[_0x53ab('0x2f')]['fields']));_0x426b47[_0x53ab('0x32')]=_0x426b47['attributes'][_0x53ab('0x33')]?_0x426b47['attributes']:_0x4bf581[_0x53ab('0x2d')];if(_0x882e5c[_0x53ab('0x2f')][_0x53ab('0x3c')]){_0x426b47[_0x53ab('0x3d')]=[{'all':!![]}];}_0x426b47=_[_0x53ab('0x39')]({},_0x426b47,_0x882e5c[_0x53ab('0x3b')]);return db[_0x53ab('0x28')][_0x53ab('0x43')](_0x426b47)[_0x53ab('0x21')](handleEntityNotFound(_0x5eb3c5,null))[_0x53ab('0x21')](respondWithResult(_0x5eb3c5,null))[_0x53ab('0x40')](handleError(_0x5eb3c5,null));};exports[_0x53ab('0x44')]=function(_0xa7a6d7,_0x37cdfe){if(_0xa7a6d7[_0x53ab('0x45')]['id']){delete _0xa7a6d7[_0x53ab('0x45')]['id'];}return db[_0x53ab('0x28')][_0x53ab('0x43')]({'where':{'id':_0xa7a6d7[_0x53ab('0x46')]['id']}})[_0x53ab('0x21')](handleEntityNotFound(_0x37cdfe,null))[_0x53ab('0x21')](saveUpdates(_0xa7a6d7[_0x53ab('0x45')],null))[_0x53ab('0x21')](respondWithResult(_0x37cdfe,null))[_0x53ab('0x40')](handleError(_0x37cdfe,null));};exports[_0x53ab('0x20')]=function(_0x5936f5,_0x19f04b){return db[_0x53ab('0x28')][_0x53ab('0x43')]({'where':{'id':_0x5936f5[_0x53ab('0x46')]['id']}})['then'](handleEntityNotFound(_0x19f04b,null))[_0x53ab('0x21')](removeEntity(_0x19f04b,null))[_0x53ab('0x40')](handleError(_0x19f04b,null));};exports[_0x53ab('0x47')]=function(_0xb44640,_0x572499){var _0x613190;return db[_0x53ab('0x48')][_0x53ab('0x49')](function(_0x15429a){return db['CmCustomField'][_0x53ab('0x47')](_0xb44640[_0x53ab('0x45')],{'transaction':_0x15429a})[_0x53ab('0x21')](function(_0x43b78a){_0x613190=_0x43b78a;var _0x1d347e={'type':db[_0x53ab('0x4a')][_0x53ab('0x4b')],'transaction':_0x15429a};switch(_0xb44640[_0x53ab('0x45')][_0x53ab('0x2b')]){case _0x53ab('0x4c'):_0x1d347e[_0x53ab('0x2b')]=db[_0x53ab('0x4a')]['TEXT'];break;case'number':_0x1d347e[_0x53ab('0x2b')]=db['Sequelize'][_0x53ab('0x4d')];break;case _0x53ab('0x4e'):_0x1d347e[_0x53ab('0x2b')]=db[_0x53ab('0x4a')][_0x53ab('0x4f')];_0x1d347e['defaultValue']=![];break;default:}return db[_0x53ab('0x48')][_0x53ab('0x50')][_0x53ab('0x51')](_0x53ab('0x52'),util[_0x53ab('0x53')]('cf_%d',_0x613190['id']),_0x1d347e);})['then'](function(){return _0x613190;});})[_0x53ab('0x21')](respondWithResult(_0x572499,0xc9))['catch'](handleError(_0x572499,null));};