0341572fdb9ff6b7055d7dee4ecbbebc6ef1d786
[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 _0xba64=['to-csv','squel','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','count','offset','limit','set','Content-Range','json','reject','save','update','then','destroy','end','error','name','send','CmCustomField','rawAttributes','key','model','differenceBy','map','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','order','sort','where','VIRTUAL','filter','options','includeAll','include','findAll','rows','catch','show','params','find','body','create','Sequelize','TEXT','type','text','number','INTEGER','switch','defaultValue','sequelize','queryInterface','addColumn','cm_contacts','cf_%d','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','util','path','sox'];(function(_0x1f1500,_0x2085e0){var _0x28b555=function(_0x30fb64){while(--_0x30fb64){_0x1f1500['push'](_0x1f1500['shift']());}};_0x28b555(++_0x2085e0);}(_0xba64,0x1ef));var _0x4ba6=function(_0x3f3aff,_0x5ed722){_0x3f3aff=_0x3f3aff-0x0;var _0x453996=_0xba64[_0x3f3aff];return _0x453996;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x4ba6('0x0'));var rimraf=require(_0x4ba6('0x1'));var zipdir=require(_0x4ba6('0x2'));var jsonpatch=require(_0x4ba6('0x3'));var rp=require('request-promise');var moment=require(_0x4ba6('0x4'));var BPromise=require(_0x4ba6('0x5'));var Mustache=require('mustache');var util=require(_0x4ba6('0x6'));var path=require(_0x4ba6('0x7'));var sox=require(_0x4ba6('0x8'));var csv=require(_0x4ba6('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0x4ba6('0xa'));var crypto=require(_0x4ba6('0xb'));var jsforce=require(_0x4ba6('0xc'));var deskjs=require(_0x4ba6('0xd'));var toCsv=require(_0x4ba6('0x9'));var querystring=require(_0x4ba6('0xe'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x4ba6('0xf'));var qs=require(_0x4ba6('0x10'));var as=require(_0x4ba6('0x11'));var hardwareService=require(_0x4ba6('0x12'));var logger=require(_0x4ba6('0x13'))(_0x4ba6('0x14'));var utils=require(_0x4ba6('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0x4ba6('0x16'));var db=require(_0x4ba6('0x17'))['db'];function respondWithStatusCode(_0x303ff0,_0x1fc891){_0x1fc891=_0x1fc891||0xcc;return function(_0x2a2cf6){if(_0x2a2cf6){return _0x303ff0[_0x4ba6('0x18')](_0x1fc891);}return _0x303ff0[_0x4ba6('0x19')](_0x1fc891)['end']();};}function respondWithResult(_0xaa8888,_0x1d118d){_0x1d118d=_0x1d118d||0xc8;return function(_0x136027){if(_0x136027){return _0xaa8888[_0x4ba6('0x19')](_0x1d118d)['json'](_0x136027);}};}function respondWithFilteredResult(_0x26c50d,_0x3bbe47){return function(_0x546b91){if(_0x546b91){var _0x542571=_0x546b91[_0x4ba6('0x1a')],_0x3bc0f7=_0x3bbe47[_0x4ba6('0x1b')],_0x3a6ff4=_0x3bbe47['offset']+_0x3bbe47[_0x4ba6('0x1c')],_0x1460fd;if(_0x3a6ff4>=_0x542571){_0x3a6ff4=_0x542571;_0x1460fd=0xc8;}else{_0x1460fd=0xce;}_0x26c50d['status'](_0x1460fd);return _0x26c50d[_0x4ba6('0x1d')](_0x4ba6('0x1e'),_0x3bc0f7+'-'+_0x3a6ff4+'/'+_0x542571)[_0x4ba6('0x1f')](_0x546b91);}return null;};}function patchUpdates(_0x7e7a18){return function(_0x121a3e){try{jsonpatch['apply'](_0x121a3e,_0x7e7a18,!![]);}catch(_0x3787c9){return BPromise[_0x4ba6('0x20')](_0x3787c9);}return _0x121a3e[_0x4ba6('0x21')]();};}function saveUpdates(_0x35f1ab,_0x2febf9){return function(_0x55f468){if(_0x55f468){return _0x55f468[_0x4ba6('0x22')](_0x35f1ab)[_0x4ba6('0x23')](function(_0x3ca495){return _0x3ca495;});}return null;};}function removeEntity(_0x3cbbca,_0x2a3a8f){return function(_0x19da88){if(_0x19da88){return _0x19da88[_0x4ba6('0x24')]()['then'](function(){_0x3cbbca[_0x4ba6('0x19')](0xcc)[_0x4ba6('0x25')]();});}};}function handleEntityNotFound(_0xc32955,_0x38c341){return function(_0xb876cb){if(!_0xb876cb){_0xc32955[_0x4ba6('0x18')](0x194);}return _0xb876cb;};}function handleError(_0x24f611,_0x90f30b){_0x90f30b=_0x90f30b||0x1f4;return function(_0x247e9d){logger[_0x4ba6('0x26')](_0x247e9d['stack']);if(_0x247e9d[_0x4ba6('0x27')]){delete _0x247e9d[_0x4ba6('0x27')];}_0x24f611['status'](_0x90f30b)[_0x4ba6('0x28')](_0x247e9d);};}exports['index']=function(_0x2e4eac,_0xe97d02){var _0x2e442e={},_0x52b9f6={},_0x16ac90={'count':0x0,'rows':[]};var _0x570797=_['map'](db[_0x4ba6('0x29')][_0x4ba6('0x2a')],function(_0x57a26e){return{'name':_0x57a26e['fieldName'],'type':_0x57a26e['type'][_0x4ba6('0x2b')]};});_0x52b9f6[_0x4ba6('0x2c')]=_[_0x4ba6('0x2d')](_[_0x4ba6('0x2e')](_0x570797,_0x4ba6('0x27')),[_0x4ba6('0x27')]);_0x52b9f6[_0x4ba6('0x2f')]=_[_0x4ba6('0x30')](_0x2e4eac[_0x4ba6('0x2f')]);_0x52b9f6[_0x4ba6('0x31')]=_[_0x4ba6('0x32')](_0x52b9f6[_0x4ba6('0x2c')],_0x52b9f6[_0x4ba6('0x2f')]);_0x2e442e['attributes']=_[_0x4ba6('0x32')](_0x52b9f6['model'],qs[_0x4ba6('0x33')](_0x2e4eac[_0x4ba6('0x2f')]['fields']));_0x2e442e[_0x4ba6('0x34')]=_0x2e442e['attributes'][_0x4ba6('0x35')]?_0x2e442e[_0x4ba6('0x34')]:_0x52b9f6[_0x4ba6('0x2c')];if(!_0x2e4eac[_0x4ba6('0x2f')][_0x4ba6('0x36')]('nolimit')){_0x2e442e[_0x4ba6('0x1c')]=qs[_0x4ba6('0x1c')](_0x2e4eac[_0x4ba6('0x2f')][_0x4ba6('0x1c')]);_0x2e442e[_0x4ba6('0x1b')]=qs[_0x4ba6('0x1b')](_0x2e4eac[_0x4ba6('0x2f')][_0x4ba6('0x1b')]);}_0x2e442e[_0x4ba6('0x37')]=qs['sort'](_0x2e4eac[_0x4ba6('0x2f')][_0x4ba6('0x38')]);_0x2e442e[_0x4ba6('0x39')]=qs[_0x4ba6('0x31')](_['pick'](_0x2e4eac['query'],_0x52b9f6[_0x4ba6('0x31')]),_0x570797);if(_0x2e4eac[_0x4ba6('0x2f')]['filter']){_0x2e442e['where']=_['merge'](_0x2e442e[_0x4ba6('0x39')],{'$or':_[_0x4ba6('0x2e')](_0x570797,function(_0x5ea3c3){if(_0x5ea3c3['type']!==_0x4ba6('0x3a')){var _0x321e0d={};_0x321e0d[_0x5ea3c3[_0x4ba6('0x27')]]={'$like':'%'+_0x2e4eac[_0x4ba6('0x2f')][_0x4ba6('0x3b')]+'%'};return _0x321e0d;}})});}_0x2e442e=_['merge']({},_0x2e442e,_0x2e4eac[_0x4ba6('0x3c')]);var _0x44888a={'where':_0x2e442e[_0x4ba6('0x39')]};return db[_0x4ba6('0x29')][_0x4ba6('0x1a')](_0x44888a)[_0x4ba6('0x23')](function(_0x530579){_0x16ac90[_0x4ba6('0x1a')]=_0x530579;if(_0x2e4eac['query'][_0x4ba6('0x3d')]){_0x2e442e[_0x4ba6('0x3e')]=[{'all':!![]}];}return db[_0x4ba6('0x29')][_0x4ba6('0x3f')](_0x2e442e);})[_0x4ba6('0x23')](function(_0x13a8ed){_0x16ac90[_0x4ba6('0x40')]=_0x13a8ed;return _0x16ac90;})[_0x4ba6('0x23')](respondWithFilteredResult(_0xe97d02,_0x2e442e))[_0x4ba6('0x41')](handleError(_0xe97d02,null));};exports[_0x4ba6('0x42')]=function(_0x1bccc1,_0x2772dd){var _0x5b87a6={'raw':!![],'where':{'id':_0x1bccc1[_0x4ba6('0x43')]['id']}},_0x1255b1={};_0x1255b1['model']=_[_0x4ba6('0x30')](db['CmCustomField'][_0x4ba6('0x2a')]);_0x1255b1['query']=_[_0x4ba6('0x30')](_0x1bccc1[_0x4ba6('0x2f')]);_0x1255b1['filters']=_[_0x4ba6('0x32')](_0x1255b1[_0x4ba6('0x2c')],_0x1255b1[_0x4ba6('0x2f')]);_0x5b87a6[_0x4ba6('0x34')]=_[_0x4ba6('0x32')](_0x1255b1[_0x4ba6('0x2c')],qs['fields'](_0x1bccc1[_0x4ba6('0x2f')][_0x4ba6('0x33')]));_0x5b87a6[_0x4ba6('0x34')]=_0x5b87a6[_0x4ba6('0x34')][_0x4ba6('0x35')]?_0x5b87a6[_0x4ba6('0x34')]:_0x1255b1['model'];if(_0x1bccc1[_0x4ba6('0x2f')][_0x4ba6('0x3d')]){_0x5b87a6[_0x4ba6('0x3e')]=[{'all':!![]}];}_0x5b87a6=_['merge']({},_0x5b87a6,_0x1bccc1[_0x4ba6('0x3c')]);return db[_0x4ba6('0x29')][_0x4ba6('0x44')](_0x5b87a6)[_0x4ba6('0x23')](handleEntityNotFound(_0x2772dd,null))[_0x4ba6('0x23')](respondWithResult(_0x2772dd,null))[_0x4ba6('0x41')](handleError(_0x2772dd,null));};exports[_0x4ba6('0x22')]=function(_0x515c86,_0x5cb2c3){if(_0x515c86[_0x4ba6('0x45')]['id']){delete _0x515c86[_0x4ba6('0x45')]['id'];}return db[_0x4ba6('0x29')]['find']({'where':{'id':_0x515c86[_0x4ba6('0x43')]['id']}})[_0x4ba6('0x23')](handleEntityNotFound(_0x5cb2c3,null))[_0x4ba6('0x23')](saveUpdates(_0x515c86['body'],null))['then'](respondWithResult(_0x5cb2c3,null))['catch'](handleError(_0x5cb2c3,null));};exports[_0x4ba6('0x24')]=function(_0x2eec3a,_0x4c462e){return db[_0x4ba6('0x29')]['find']({'where':{'id':_0x2eec3a[_0x4ba6('0x43')]['id']}})[_0x4ba6('0x23')](handleEntityNotFound(_0x4c462e,null))[_0x4ba6('0x23')](removeEntity(_0x4c462e,null))[_0x4ba6('0x41')](handleError(_0x4c462e,null));};exports[_0x4ba6('0x46')]=function(_0x19d7b0,_0xf1822e){var _0x17d41a;return db['sequelize']['transaction'](function(_0x51bea5){return db[_0x4ba6('0x29')][_0x4ba6('0x46')](_0x19d7b0[_0x4ba6('0x45')],{'transaction':_0x51bea5})['then'](function(_0x2d0ea4){_0x17d41a=_0x2d0ea4;var _0xdaa48e={'type':db[_0x4ba6('0x47')][_0x4ba6('0x48')],'transaction':_0x51bea5};switch(_0x19d7b0[_0x4ba6('0x45')][_0x4ba6('0x49')]){case _0x4ba6('0x4a'):_0xdaa48e['type']=db['Sequelize']['TEXT'];break;case _0x4ba6('0x4b'):_0xdaa48e['type']=db[_0x4ba6('0x47')][_0x4ba6('0x4c')];break;case _0x4ba6('0x4d'):_0xdaa48e['type']=db[_0x4ba6('0x47')]['BOOLEAN'];_0xdaa48e[_0x4ba6('0x4e')]=![];break;default:}return db[_0x4ba6('0x4f')][_0x4ba6('0x50')][_0x4ba6('0x51')](_0x4ba6('0x52'),util['format'](_0x4ba6('0x53'),_0x17d41a['id']),_0xdaa48e);})[_0x4ba6('0x23')](function(){return _0x17d41a;});})[_0x4ba6('0x23')](respondWithResult(_0xf1822e,0xc9))[_0x4ba6('0x41')](handleError(_0xf1822e,null));};