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 _0xcc65=['CmCustomField','rawAttributes','type','model','differenceBy','query','keys','filters','intersection','fields','attributes','order','sort','pick','merge','VIRTUAL','filter','options','where','include','findAll','rows','catch','show','params','includeAll','find','body','create','sequelize','transaction','Sequelize','TEXT','number','INTEGER','switch','BOOLEAN','defaultValue','queryInterface','addColumn','cm_contacts','format','cf_%d','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','jsforce','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','undefined','count','set','Content-Range','apply','reject','save','update','then','destroy','stack','name','send','map'];(function(_0x5d51b3,_0x4d9069){var _0x1bad57=function(_0x43ec9a){while(--_0x43ec9a){_0x5d51b3['push'](_0x5d51b3['shift']());}};_0x1bad57(++_0x4d9069);}(_0xcc65,0x1e3));var _0x5cc6=function(_0x40d411,_0x4642f1){_0x40d411=_0x40d411-0x0;var _0x51fd22=_0xcc65[_0x40d411];return _0x51fd22;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x5cc6('0x0'));var zipdir=require(_0x5cc6('0x1'));var jsonpatch=require(_0x5cc6('0x2'));var rp=require(_0x5cc6('0x3'));var moment=require(_0x5cc6('0x4'));var BPromise=require(_0x5cc6('0x5'));var Mustache=require(_0x5cc6('0x6'));var util=require(_0x5cc6('0x7'));var path=require(_0x5cc6('0x8'));var sox=require(_0x5cc6('0x9'));var csv=require(_0x5cc6('0xa'));var ejs=require(_0x5cc6('0xb'));var fs=require('fs');var fs_extra=require(_0x5cc6('0xc'));var _=require('lodash');var squel=require(_0x5cc6('0xd'));var crypto=require('crypto');var jsforce=require(_0x5cc6('0xe'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x5cc6('0xf'));var Papa=require(_0x5cc6('0x10'));var Redis=require('ioredis');var authService=require(_0x5cc6('0x11'));var qs=require(_0x5cc6('0x12'));var as=require(_0x5cc6('0x13'));var hardwareService=require(_0x5cc6('0x14'));var logger=require('../../config/logger')('api');var utils=require(_0x5cc6('0x15'));var config=require(_0x5cc6('0x16'));var licenseUtil=require(_0x5cc6('0x17'));var db=require(_0x5cc6('0x18'))['db'];function respondWithStatusCode(_0x6cebf8,_0x179d9f){_0x179d9f=_0x179d9f||0xcc;return function(_0x7697fc){if(_0x7697fc){return _0x6cebf8[_0x5cc6('0x19')](_0x179d9f);}return _0x6cebf8[_0x5cc6('0x1a')](_0x179d9f)[_0x5cc6('0x1b')]();};}function respondWithResult(_0x148142,_0x2c642c){_0x2c642c=_0x2c642c||0xc8;return function(_0x26aa26){if(_0x26aa26){return _0x148142[_0x5cc6('0x1a')](_0x2c642c)[_0x5cc6('0x1c')](_0x26aa26);}};}function respondWithFilteredResult(_0x4a43f3,_0x5eb3ec){return function(_0x4c50ba){if(_0x4c50ba){var _0x16ca41=typeof _0x5eb3ec[_0x5cc6('0x1d')]==='undefined'&&typeof _0x5eb3ec[_0x5cc6('0x1e')]===_0x5cc6('0x1f');var _0x5f2cb7=_0x4c50ba[_0x5cc6('0x20')];var _0x3ae317=_0x16ca41?0x0:_0x5eb3ec[_0x5cc6('0x1d')];var _0x2ef292=_0x16ca41?_0x4c50ba[_0x5cc6('0x20')]:_0x5eb3ec[_0x5cc6('0x1d')]+_0x5eb3ec[_0x5cc6('0x1e')];var _0x437032;if(_0x2ef292>=_0x5f2cb7){_0x2ef292=_0x5f2cb7;_0x437032=0xc8;}else{_0x437032=0xce;}_0x4a43f3['status'](_0x437032);return _0x4a43f3[_0x5cc6('0x21')](_0x5cc6('0x22'),_0x3ae317+'-'+_0x2ef292+'/'+_0x5f2cb7)[_0x5cc6('0x1c')](_0x4c50ba);}return null;};}function patchUpdates(_0x5ea31c){return function(_0x5e09a4){try{jsonpatch[_0x5cc6('0x23')](_0x5e09a4,_0x5ea31c,!![]);}catch(_0x50a440){return BPromise[_0x5cc6('0x24')](_0x50a440);}return _0x5e09a4[_0x5cc6('0x25')]();};}function saveUpdates(_0x4cfbc7,_0x5cdbab){return function(_0x5aaea9){if(_0x5aaea9){return _0x5aaea9[_0x5cc6('0x26')](_0x4cfbc7)[_0x5cc6('0x27')](function(_0x455a69){return _0x455a69;});}return null;};}function removeEntity(_0x18b1d3,_0x16a3ac){return function(_0x2b4d77){if(_0x2b4d77){return _0x2b4d77[_0x5cc6('0x28')]()[_0x5cc6('0x27')](function(){_0x18b1d3[_0x5cc6('0x1a')](0xcc)[_0x5cc6('0x1b')]();});}};}function handleEntityNotFound(_0x525b55,_0x4bfef1){return function(_0x287a37){if(!_0x287a37){_0x525b55['sendStatus'](0x194);}return _0x287a37;};}function handleError(_0x261326,_0x179dc9){_0x179dc9=_0x179dc9||0x1f4;return function(_0x45dd0b){logger['error'](_0x45dd0b[_0x5cc6('0x29')]);if(_0x45dd0b[_0x5cc6('0x2a')]){delete _0x45dd0b[_0x5cc6('0x2a')];}_0x261326[_0x5cc6('0x1a')](_0x179dc9)[_0x5cc6('0x2b')](_0x45dd0b);};}exports['index']=function(_0x81f73b,_0x2772ca){var _0x586632={},_0x2f760a={},_0x17e3d2={'count':0x0,'rows':[]};var _0x803dc3=_[_0x5cc6('0x2c')](db[_0x5cc6('0x2d')][_0x5cc6('0x2e')],function(_0x294d21){return{'name':_0x294d21['fieldName'],'type':_0x294d21[_0x5cc6('0x2f')]['key']};});_0x2f760a[_0x5cc6('0x30')]=_[_0x5cc6('0x31')](_[_0x5cc6('0x2c')](_0x803dc3,'name'),['name']);_0x2f760a[_0x5cc6('0x32')]=_[_0x5cc6('0x33')](_0x81f73b[_0x5cc6('0x32')]);_0x2f760a[_0x5cc6('0x34')]=_[_0x5cc6('0x35')](_0x2f760a[_0x5cc6('0x30')],_0x2f760a['query']);_0x586632['attributes']=_[_0x5cc6('0x35')](_0x2f760a[_0x5cc6('0x30')],qs[_0x5cc6('0x36')](_0x81f73b[_0x5cc6('0x32')]['fields']));_0x586632['attributes']=_0x586632[_0x5cc6('0x37')]['length']?_0x586632[_0x5cc6('0x37')]:_0x2f760a[_0x5cc6('0x30')];if(!_0x81f73b[_0x5cc6('0x32')]['hasOwnProperty']('nolimit')){_0x586632[_0x5cc6('0x1e')]=qs[_0x5cc6('0x1e')](_0x81f73b[_0x5cc6('0x32')][_0x5cc6('0x1e')]);_0x586632[_0x5cc6('0x1d')]=qs[_0x5cc6('0x1d')](_0x81f73b[_0x5cc6('0x32')][_0x5cc6('0x1d')]);}_0x586632[_0x5cc6('0x38')]=qs[_0x5cc6('0x39')](_0x81f73b[_0x5cc6('0x32')][_0x5cc6('0x39')]);_0x586632['where']=qs[_0x5cc6('0x34')](_[_0x5cc6('0x3a')](_0x81f73b[_0x5cc6('0x32')],_0x2f760a[_0x5cc6('0x34')]),_0x803dc3);if(_0x81f73b['query']['filter']){_0x586632['where']=_[_0x5cc6('0x3b')](_0x586632['where'],{'$or':_[_0x5cc6('0x2c')](_0x803dc3,function(_0x3c9ee4){if(_0x3c9ee4[_0x5cc6('0x2f')]!==_0x5cc6('0x3c')){var _0x51bad0={};_0x51bad0[_0x3c9ee4[_0x5cc6('0x2a')]]={'$like':'%'+_0x81f73b[_0x5cc6('0x32')][_0x5cc6('0x3d')]+'%'};return _0x51bad0;}})});}_0x586632=_[_0x5cc6('0x3b')]({},_0x586632,_0x81f73b[_0x5cc6('0x3e')]);var _0x17674d={'where':_0x586632[_0x5cc6('0x3f')]};return db[_0x5cc6('0x2d')][_0x5cc6('0x20')](_0x17674d)[_0x5cc6('0x27')](function(_0x1b2474){_0x17e3d2[_0x5cc6('0x20')]=_0x1b2474;if(_0x81f73b['query']['includeAll']){_0x586632[_0x5cc6('0x40')]=[{'all':!![]}];}return db['CmCustomField'][_0x5cc6('0x41')](_0x586632);})[_0x5cc6('0x27')](function(_0x124118){_0x17e3d2[_0x5cc6('0x42')]=_0x124118;return _0x17e3d2;})[_0x5cc6('0x27')](respondWithFilteredResult(_0x2772ca,_0x586632))[_0x5cc6('0x43')](handleError(_0x2772ca,null));};exports[_0x5cc6('0x44')]=function(_0x4e7757,_0x308b81){var _0xec37b5={'raw':!![],'where':{'id':_0x4e7757[_0x5cc6('0x45')]['id']}},_0x18dabe={};_0x18dabe[_0x5cc6('0x30')]=_[_0x5cc6('0x33')](db[_0x5cc6('0x2d')]['rawAttributes']);_0x18dabe[_0x5cc6('0x32')]=_['keys'](_0x4e7757['query']);_0x18dabe[_0x5cc6('0x34')]=_[_0x5cc6('0x35')](_0x18dabe['model'],_0x18dabe[_0x5cc6('0x32')]);_0xec37b5[_0x5cc6('0x37')]=_[_0x5cc6('0x35')](_0x18dabe[_0x5cc6('0x30')],qs[_0x5cc6('0x36')](_0x4e7757[_0x5cc6('0x32')][_0x5cc6('0x36')]));_0xec37b5[_0x5cc6('0x37')]=_0xec37b5['attributes']['length']?_0xec37b5[_0x5cc6('0x37')]:_0x18dabe[_0x5cc6('0x30')];if(_0x4e7757[_0x5cc6('0x32')][_0x5cc6('0x46')]){_0xec37b5['include']=[{'all':!![]}];}_0xec37b5=_[_0x5cc6('0x3b')]({},_0xec37b5,_0x4e7757['options']);return db[_0x5cc6('0x2d')][_0x5cc6('0x47')](_0xec37b5)[_0x5cc6('0x27')](handleEntityNotFound(_0x308b81,null))['then'](respondWithResult(_0x308b81,null))['catch'](handleError(_0x308b81,null));};exports[_0x5cc6('0x26')]=function(_0x38fc28,_0x5f7046){if(_0x38fc28[_0x5cc6('0x48')]['id']){delete _0x38fc28[_0x5cc6('0x48')]['id'];}return db[_0x5cc6('0x2d')]['find']({'where':{'id':_0x38fc28[_0x5cc6('0x45')]['id']}})[_0x5cc6('0x27')](handleEntityNotFound(_0x5f7046,null))[_0x5cc6('0x27')](saveUpdates(_0x38fc28[_0x5cc6('0x48')],null))[_0x5cc6('0x27')](respondWithResult(_0x5f7046,null))[_0x5cc6('0x43')](handleError(_0x5f7046,null));};exports['destroy']=function(_0x80f271,_0x4de24f){return db[_0x5cc6('0x2d')][_0x5cc6('0x47')]({'where':{'id':_0x80f271[_0x5cc6('0x45')]['id']}})[_0x5cc6('0x27')](handleEntityNotFound(_0x4de24f,null))[_0x5cc6('0x27')](removeEntity(_0x4de24f,null))[_0x5cc6('0x43')](handleError(_0x4de24f,null));};exports[_0x5cc6('0x49')]=function(_0x2639c2,_0x330ac9){var _0x524706;return db[_0x5cc6('0x4a')][_0x5cc6('0x4b')](function(_0x2ecfb1){return db[_0x5cc6('0x2d')][_0x5cc6('0x49')](_0x2639c2['body'],{'transaction':_0x2ecfb1})[_0x5cc6('0x27')](function(_0x4b6021){_0x524706=_0x4b6021;var _0xb50199={'type':db[_0x5cc6('0x4c')]['TEXT'],'transaction':_0x2ecfb1};switch(_0x2639c2[_0x5cc6('0x48')]['type']){case'text':_0xb50199['type']=db[_0x5cc6('0x4c')][_0x5cc6('0x4d')];break;case _0x5cc6('0x4e'):_0xb50199[_0x5cc6('0x2f')]=db['Sequelize'][_0x5cc6('0x4f')];break;case _0x5cc6('0x50'):_0xb50199[_0x5cc6('0x2f')]=db[_0x5cc6('0x4c')][_0x5cc6('0x51')];_0xb50199[_0x5cc6('0x52')]=![];break;default:}return db['sequelize'][_0x5cc6('0x53')][_0x5cc6('0x54')](_0x5cc6('0x55'),util[_0x5cc6('0x56')](_0x5cc6('0x57'),_0x524706['id']),_0xb50199);})['then'](function(){return _0x524706;});})[_0x5cc6('0x27')](respondWithResult(_0x330ac9,0xc9))[_0x5cc6('0x43')](handleError(_0x330ac9,null));};