85eafd8fa238f1041c5a70d8e633fc8249b7c3e9
[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 _0x6f54=['differenceBy','keys','query','filters','intersection','model','fields','attributes','hasOwnProperty','nolimit','limit','order','sort','pick','filter','merge','where','VIRTUAL','options','findAll','catch','show','include','find','body','destroy','params','sequelize','transaction','create','Sequelize','text','switch','BOOLEAN','defaultValue','queryInterface','addColumn','cf_%d','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','to-csv','ejs','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/license/util','sendStatus','status','end','json','count','offset','set','apply','reject','save','update','then','error','stack','name','send','map','CmCustomField','rawAttributes','fieldName','type'];(function(_0x407b07,_0x525c69){var _0x2c9b12=function(_0x54b368){while(--_0x54b368){_0x407b07['push'](_0x407b07['shift']());}};_0x2c9b12(++_0x525c69);}(_0x6f54,0xc6));var _0x46f5=function(_0x3baac8,_0x251192){_0x3baac8=_0x3baac8-0x0;var _0x20964d=_0x6f54[_0x3baac8];return _0x20964d;};'use strict';var pdf=require(_0x46f5('0x0'));var emlformat=require(_0x46f5('0x1'));var rimraf=require(_0x46f5('0x2'));var zipdir=require(_0x46f5('0x3'));var jsonpatch=require(_0x46f5('0x4'));var rp=require(_0x46f5('0x5'));var moment=require('moment');var BPromise=require(_0x46f5('0x6'));var Mustache=require(_0x46f5('0x7'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require(_0x46f5('0x8'));var ejs=require(_0x46f5('0x9'));var fs=require('fs');var _=require('lodash');var squel=require(_0x46f5('0xa'));var crypto=require(_0x46f5('0xb'));var jsforce=require(_0x46f5('0xc'));var deskjs=require(_0x46f5('0xd'));var toCsv=require(_0x46f5('0x8'));var querystring=require('querystring');var Papa=require(_0x46f5('0xe'));var Redis=require(_0x46f5('0xf'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x46f5('0x10'));var hardwareService=require(_0x46f5('0x11'));var logger=require(_0x46f5('0x12'))(_0x46f5('0x13'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x46f5('0x14'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3a497e,_0x2cfe79){_0x2cfe79=_0x2cfe79||0xcc;return function(_0x292234){if(_0x292234){return _0x3a497e[_0x46f5('0x15')](_0x2cfe79);}return _0x3a497e[_0x46f5('0x16')](_0x2cfe79)[_0x46f5('0x17')]();};}function respondWithResult(_0x24c7ab,_0x43b847){_0x43b847=_0x43b847||0xc8;return function(_0x2d01f0){if(_0x2d01f0){return _0x24c7ab[_0x46f5('0x16')](_0x43b847)[_0x46f5('0x18')](_0x2d01f0);}};}function respondWithFilteredResult(_0x15507c,_0x33df2e){return function(_0x17134f){if(_0x17134f){var _0xaf3243=_0x17134f[_0x46f5('0x19')],_0x2e5f44=_0x33df2e['offset'],_0x42a92c=_0x33df2e[_0x46f5('0x1a')]+_0x33df2e['limit'],_0x1ee391;if(_0x42a92c>=_0xaf3243){_0x42a92c=_0xaf3243;_0x1ee391=0xc8;}else{_0x1ee391=0xce;}_0x15507c['status'](_0x1ee391);return _0x15507c[_0x46f5('0x1b')]('Content-Range',_0x2e5f44+'-'+_0x42a92c+'/'+_0xaf3243)[_0x46f5('0x18')](_0x17134f);}return null;};}function patchUpdates(_0x92e901){return function(_0x4c4ed0){try{jsonpatch[_0x46f5('0x1c')](_0x4c4ed0,_0x92e901,!![]);}catch(_0x1999a9){return BPromise[_0x46f5('0x1d')](_0x1999a9);}return _0x4c4ed0[_0x46f5('0x1e')]();};}function saveUpdates(_0x4dcf22,_0x5e9c7d){return function(_0x2f2091){if(_0x2f2091){return _0x2f2091[_0x46f5('0x1f')](_0x4dcf22)['then'](function(_0x2915c3){return _0x2915c3;});}return null;};}function removeEntity(_0x107caa,_0x4e0c8a){return function(_0x1638d6){if(_0x1638d6){return _0x1638d6['destroy']()[_0x46f5('0x20')](function(){_0x107caa[_0x46f5('0x16')](0xcc)[_0x46f5('0x17')]();});}};}function handleEntityNotFound(_0x5322f0,_0x4e04e8){return function(_0x1c8b45){if(!_0x1c8b45){_0x5322f0[_0x46f5('0x15')](0x194);}return _0x1c8b45;};}function handleError(_0x247252,_0x38ef0e){_0x38ef0e=_0x38ef0e||0x1f4;return function(_0x104ba3){logger[_0x46f5('0x21')](_0x104ba3[_0x46f5('0x22')]);if(_0x104ba3[_0x46f5('0x23')]){delete _0x104ba3[_0x46f5('0x23')];}_0x247252[_0x46f5('0x16')](_0x38ef0e)[_0x46f5('0x24')](_0x104ba3);};}exports['index']=function(_0x3af38f,_0x140d87){var _0x50b3c0={},_0x1ce46e={},_0x7f52e5={'count':0x0,'rows':[]};var _0x121c11=_[_0x46f5('0x25')](db[_0x46f5('0x26')][_0x46f5('0x27')],function(_0x502294){return{'name':_0x502294[_0x46f5('0x28')],'type':_0x502294[_0x46f5('0x29')]['key']};});_0x1ce46e['model']=_[_0x46f5('0x2a')](_['map'](_0x121c11,_0x46f5('0x23')),[_0x46f5('0x23')]);_0x1ce46e['query']=_[_0x46f5('0x2b')](_0x3af38f[_0x46f5('0x2c')]);_0x1ce46e[_0x46f5('0x2d')]=_[_0x46f5('0x2e')](_0x1ce46e['model'],_0x1ce46e[_0x46f5('0x2c')]);_0x50b3c0['attributes']=_[_0x46f5('0x2e')](_0x1ce46e[_0x46f5('0x2f')],qs[_0x46f5('0x30')](_0x3af38f[_0x46f5('0x2c')][_0x46f5('0x30')]));_0x50b3c0[_0x46f5('0x31')]=_0x50b3c0[_0x46f5('0x31')]['length']?_0x50b3c0[_0x46f5('0x31')]:_0x1ce46e[_0x46f5('0x2f')];if(!_0x3af38f['query'][_0x46f5('0x32')](_0x46f5('0x33'))){_0x50b3c0['limit']=qs[_0x46f5('0x34')](_0x3af38f[_0x46f5('0x2c')][_0x46f5('0x34')]);_0x50b3c0['offset']=qs[_0x46f5('0x1a')](_0x3af38f[_0x46f5('0x2c')][_0x46f5('0x1a')]);}_0x50b3c0[_0x46f5('0x35')]=qs[_0x46f5('0x36')](_0x3af38f[_0x46f5('0x2c')][_0x46f5('0x36')]);_0x50b3c0['where']=qs[_0x46f5('0x2d')](_[_0x46f5('0x37')](_0x3af38f[_0x46f5('0x2c')],_0x1ce46e['filters']),_0x121c11);if(_0x3af38f[_0x46f5('0x2c')][_0x46f5('0x38')]){_0x50b3c0['where']=_[_0x46f5('0x39')](_0x50b3c0[_0x46f5('0x3a')],{'$or':_[_0x46f5('0x25')](_0x121c11,function(_0x28fd67){if(_0x28fd67[_0x46f5('0x29')]!==_0x46f5('0x3b')){var _0x2143cd={};_0x2143cd[_0x28fd67[_0x46f5('0x23')]]={'$like':'%'+_0x3af38f[_0x46f5('0x2c')]['filter']+'%'};return _0x2143cd;}})});}_0x50b3c0=_[_0x46f5('0x39')]({},_0x50b3c0,_0x3af38f[_0x46f5('0x3c')]);var _0x19824f={'where':_0x50b3c0[_0x46f5('0x3a')]};return db[_0x46f5('0x26')]['count'](_0x19824f)[_0x46f5('0x20')](function(_0x32ffe7){_0x7f52e5[_0x46f5('0x19')]=_0x32ffe7;if(_0x3af38f[_0x46f5('0x2c')]['includeAll']){_0x50b3c0['include']=[{'all':!![]}];}return db[_0x46f5('0x26')][_0x46f5('0x3d')](_0x50b3c0);})[_0x46f5('0x20')](function(_0x3a6f68){_0x7f52e5['rows']=_0x3a6f68;return _0x7f52e5;})[_0x46f5('0x20')](respondWithFilteredResult(_0x140d87,_0x50b3c0))[_0x46f5('0x3e')](handleError(_0x140d87,null));};exports[_0x46f5('0x3f')]=function(_0x1dd63d,_0x35b56c){var _0x3024a7={'raw':!![],'where':{'id':_0x1dd63d['params']['id']}},_0x2dfc6d={};_0x2dfc6d[_0x46f5('0x2f')]=_[_0x46f5('0x2b')](db[_0x46f5('0x26')][_0x46f5('0x27')]);_0x2dfc6d[_0x46f5('0x2c')]=_[_0x46f5('0x2b')](_0x1dd63d[_0x46f5('0x2c')]);_0x2dfc6d[_0x46f5('0x2d')]=_['intersection'](_0x2dfc6d[_0x46f5('0x2f')],_0x2dfc6d[_0x46f5('0x2c')]);_0x3024a7[_0x46f5('0x31')]=_['intersection'](_0x2dfc6d[_0x46f5('0x2f')],qs['fields'](_0x1dd63d[_0x46f5('0x2c')][_0x46f5('0x30')]));_0x3024a7['attributes']=_0x3024a7[_0x46f5('0x31')]['length']?_0x3024a7[_0x46f5('0x31')]:_0x2dfc6d[_0x46f5('0x2f')];if(_0x1dd63d['query']['includeAll']){_0x3024a7[_0x46f5('0x40')]=[{'all':!![]}];}_0x3024a7=_[_0x46f5('0x39')]({},_0x3024a7,_0x1dd63d[_0x46f5('0x3c')]);return db[_0x46f5('0x26')][_0x46f5('0x41')](_0x3024a7)[_0x46f5('0x20')](handleEntityNotFound(_0x35b56c,null))[_0x46f5('0x20')](respondWithResult(_0x35b56c,null))[_0x46f5('0x3e')](handleError(_0x35b56c,null));};exports['update']=function(_0x2db716,_0x404dcd){if(_0x2db716['body']['id']){delete _0x2db716[_0x46f5('0x42')]['id'];}return db[_0x46f5('0x26')]['find']({'where':{'id':_0x2db716['params']['id']}})[_0x46f5('0x20')](handleEntityNotFound(_0x404dcd,null))['then'](saveUpdates(_0x2db716[_0x46f5('0x42')],null))[_0x46f5('0x20')](respondWithResult(_0x404dcd,null))[_0x46f5('0x3e')](handleError(_0x404dcd,null));};exports[_0x46f5('0x43')]=function(_0x4975da,_0x3d2442){return db[_0x46f5('0x26')]['find']({'where':{'id':_0x4975da[_0x46f5('0x44')]['id']}})[_0x46f5('0x20')](handleEntityNotFound(_0x3d2442,null))[_0x46f5('0x20')](removeEntity(_0x3d2442,null))[_0x46f5('0x3e')](handleError(_0x3d2442,null));};exports['create']=function(_0x4ae2fa,_0x4fc4b9){var _0x5d81ca;return db[_0x46f5('0x45')][_0x46f5('0x46')](function(_0x5cac4c){return db[_0x46f5('0x26')][_0x46f5('0x47')](_0x4ae2fa[_0x46f5('0x42')],{'transaction':_0x5cac4c})['then'](function(_0x48b47b){_0x5d81ca=_0x48b47b;var _0x46d36c={'type':db[_0x46f5('0x48')]['TEXT'],'transaction':_0x5cac4c};switch(_0x4ae2fa[_0x46f5('0x42')][_0x46f5('0x29')]){case _0x46f5('0x49'):_0x46d36c[_0x46f5('0x29')]=db[_0x46f5('0x48')]['TEXT'];break;case'number':_0x46d36c[_0x46f5('0x29')]=db[_0x46f5('0x48')]['INTEGER'];break;case _0x46f5('0x4a'):_0x46d36c[_0x46f5('0x29')]=db[_0x46f5('0x48')][_0x46f5('0x4b')];_0x46d36c[_0x46f5('0x4c')]=![];break;default:}return db[_0x46f5('0x45')][_0x46f5('0x4d')][_0x46f5('0x4e')]('cm_contacts',util['format'](_0x46f5('0x4f'),_0x5d81ca['id']),_0x46d36c);})[_0x46f5('0x20')](function(){return _0x5d81ca;});})[_0x46f5('0x20')](respondWithResult(_0x4fc4b9,0xc9))[_0x46f5('0x3e')](handleError(_0x4fc4b9,null));};