Built motion from commit (unavailable).|2.5.11
[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 _0x312f=['where','filters','filter','merge','VIRTUAL','options','includeAll','include','catch','show','params','keys','find','create','sequelize','transaction','body','Sequelize','TEXT','text','number','INTEGER','switch','defaultValue','queryInterface','addColumn','cm_contacts','format','cf_%d','html-pdf','eml-format','zip-dir','request-promise','moment','mustache','path','to-csv','ejs','squel','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','json','limit','set','reject','save','update','destroy','then','status','error','stack','name','send','index','map','CmCustomField','rawAttributes','fieldName','type','query','intersection','attributes','model','fields','length','hasOwnProperty','nolimit','offset','sort'];(function(_0x5c7ba6,_0x544cb1){var _0x1eab97=function(_0x2595b0){while(--_0x2595b0){_0x5c7ba6['push'](_0x5c7ba6['shift']());}};_0x1eab97(++_0x544cb1);}(_0x312f,0xbf));var _0xf312=function(_0x3e7ae4,_0x91f9c5){_0x3e7ae4=_0x3e7ae4-0x0;var _0x3ddbbc=_0x312f[_0x3e7ae4];return _0x3ddbbc;};'use strict';var pdf=require(_0xf312('0x0'));var emlformat=require(_0xf312('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xf312('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf312('0x3'));var moment=require(_0xf312('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xf312('0x5'));var util=require('util');var path=require(_0xf312('0x6'));var sox=require('sox');var csv=require(_0xf312('0x7'));var ejs=require(_0xf312('0x8'));var fs=require('fs');var _=require('lodash');var squel=require(_0xf312('0x9'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xf312('0x7'));var querystring=require(_0xf312('0xa'));var Papa=require(_0xf312('0xb'));var Redis=require(_0xf312('0xc'));var authService=require(_0xf312('0xd'));var qs=require('../../components/parsers/qs');var as=require(_0xf312('0xe'));var hardwareService=require(_0xf312('0xf'));var logger=require(_0xf312('0x10'))(_0xf312('0x11'));var utils=require(_0xf312('0x12'));var config=require(_0xf312('0x13'));var licenseUtil=require('../../config/license/util');var db=require(_0xf312('0x14'))['db'];function respondWithStatusCode(_0x4e14ad,_0x49793a){_0x49793a=_0x49793a||0xcc;return function(_0x59625b){if(_0x59625b){return _0x4e14ad[_0xf312('0x15')](_0x49793a);}return _0x4e14ad['status'](_0x49793a)[_0xf312('0x16')]();};}function respondWithResult(_0x55ab94,_0x12156f){_0x12156f=_0x12156f||0xc8;return function(_0x11810e){if(_0x11810e){return _0x55ab94['status'](_0x12156f)[_0xf312('0x17')](_0x11810e);}};}function respondWithFilteredResult(_0x5b460e,_0x25a3cc){return function(_0x288661){if(_0x288661){var _0x4b45ee=_0x288661['count'],_0xb14543=_0x25a3cc['offset'],_0x2f3708=_0x25a3cc['offset']+_0x25a3cc[_0xf312('0x18')],_0x43e5eb;if(_0x2f3708>=_0x4b45ee){_0x2f3708=_0x4b45ee;_0x43e5eb=0xc8;}else{_0x43e5eb=0xce;}_0x5b460e['status'](_0x43e5eb);return _0x5b460e[_0xf312('0x19')]('Content-Range',_0xb14543+'-'+_0x2f3708+'/'+_0x4b45ee)[_0xf312('0x17')](_0x288661);}return null;};}function patchUpdates(_0x1166f7){return function(_0x519649){try{jsonpatch['apply'](_0x519649,_0x1166f7,!![]);}catch(_0x111495){return BPromise[_0xf312('0x1a')](_0x111495);}return _0x519649[_0xf312('0x1b')]();};}function saveUpdates(_0x42c68a,_0x502543){return function(_0x2a5e3d){if(_0x2a5e3d){return _0x2a5e3d[_0xf312('0x1c')](_0x42c68a)['then'](function(_0x226649){return _0x226649;});}return null;};}function removeEntity(_0xee436e,_0x561294){return function(_0x1b9581){if(_0x1b9581){return _0x1b9581[_0xf312('0x1d')]()[_0xf312('0x1e')](function(){_0xee436e[_0xf312('0x1f')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5542b4,_0x51a2e5){return function(_0x551b6e){if(!_0x551b6e){_0x5542b4['sendStatus'](0x194);}return _0x551b6e;};}function handleError(_0x24c54c,_0x55a38b){_0x55a38b=_0x55a38b||0x1f4;return function(_0x573b4d){logger[_0xf312('0x20')](_0x573b4d[_0xf312('0x21')]);if(_0x573b4d[_0xf312('0x22')]){delete _0x573b4d[_0xf312('0x22')];}_0x24c54c['status'](_0x55a38b)[_0xf312('0x23')](_0x573b4d);};}exports[_0xf312('0x24')]=function(_0xd07ba6,_0x5a805c){var _0x2bb678={},_0x40a5a3={},_0x5dd787={'count':0x0,'rows':[]};var _0x34ca35=_[_0xf312('0x25')](db[_0xf312('0x26')][_0xf312('0x27')],function(_0x20f75c){return{'name':_0x20f75c[_0xf312('0x28')],'type':_0x20f75c[_0xf312('0x29')]['key']};});_0x40a5a3['model']=_['differenceBy'](_[_0xf312('0x25')](_0x34ca35,_0xf312('0x22')),[_0xf312('0x22')]);_0x40a5a3[_0xf312('0x2a')]=_['keys'](_0xd07ba6[_0xf312('0x2a')]);_0x40a5a3['filters']=_[_0xf312('0x2b')](_0x40a5a3['model'],_0x40a5a3[_0xf312('0x2a')]);_0x2bb678[_0xf312('0x2c')]=_[_0xf312('0x2b')](_0x40a5a3[_0xf312('0x2d')],qs[_0xf312('0x2e')](_0xd07ba6[_0xf312('0x2a')][_0xf312('0x2e')]));_0x2bb678[_0xf312('0x2c')]=_0x2bb678[_0xf312('0x2c')][_0xf312('0x2f')]?_0x2bb678[_0xf312('0x2c')]:_0x40a5a3[_0xf312('0x2d')];if(!_0xd07ba6[_0xf312('0x2a')][_0xf312('0x30')](_0xf312('0x31'))){_0x2bb678[_0xf312('0x18')]=qs[_0xf312('0x18')](_0xd07ba6[_0xf312('0x2a')][_0xf312('0x18')]);_0x2bb678[_0xf312('0x32')]=qs[_0xf312('0x32')](_0xd07ba6[_0xf312('0x2a')][_0xf312('0x32')]);}_0x2bb678['order']=qs[_0xf312('0x33')](_0xd07ba6[_0xf312('0x2a')][_0xf312('0x33')]);_0x2bb678[_0xf312('0x34')]=qs['filters'](_['pick'](_0xd07ba6[_0xf312('0x2a')],_0x40a5a3[_0xf312('0x35')]),_0x34ca35);if(_0xd07ba6[_0xf312('0x2a')][_0xf312('0x36')]){_0x2bb678[_0xf312('0x34')]=_[_0xf312('0x37')](_0x2bb678['where'],{'$or':_[_0xf312('0x25')](_0x34ca35,function(_0x5ef78d){if(_0x5ef78d['type']!==_0xf312('0x38')){var _0x171a06={};_0x171a06[_0x5ef78d[_0xf312('0x22')]]={'$like':'%'+_0xd07ba6[_0xf312('0x2a')][_0xf312('0x36')]+'%'};return _0x171a06;}})});}_0x2bb678=_[_0xf312('0x37')]({},_0x2bb678,_0xd07ba6[_0xf312('0x39')]);var _0x26addb={'where':_0x2bb678[_0xf312('0x34')]};return db[_0xf312('0x26')]['count'](_0x26addb)[_0xf312('0x1e')](function(_0x4fffd2){_0x5dd787['count']=_0x4fffd2;if(_0xd07ba6[_0xf312('0x2a')][_0xf312('0x3a')]){_0x2bb678[_0xf312('0x3b')]=[{'all':!![]}];}return db['CmCustomField']['findAll'](_0x2bb678);})[_0xf312('0x1e')](function(_0x4a4a78){_0x5dd787['rows']=_0x4a4a78;return _0x5dd787;})[_0xf312('0x1e')](respondWithFilteredResult(_0x5a805c,_0x2bb678))[_0xf312('0x3c')](handleError(_0x5a805c,null));};exports[_0xf312('0x3d')]=function(_0x51929d,_0x31f3c2){var _0x1e0036={'raw':!![],'where':{'id':_0x51929d[_0xf312('0x3e')]['id']}},_0x16ff07={};_0x16ff07[_0xf312('0x2d')]=_[_0xf312('0x3f')](db[_0xf312('0x26')]['rawAttributes']);_0x16ff07[_0xf312('0x2a')]=_[_0xf312('0x3f')](_0x51929d[_0xf312('0x2a')]);_0x16ff07[_0xf312('0x35')]=_[_0xf312('0x2b')](_0x16ff07[_0xf312('0x2d')],_0x16ff07['query']);_0x1e0036[_0xf312('0x2c')]=_[_0xf312('0x2b')](_0x16ff07[_0xf312('0x2d')],qs['fields'](_0x51929d[_0xf312('0x2a')]['fields']));_0x1e0036['attributes']=_0x1e0036[_0xf312('0x2c')][_0xf312('0x2f')]?_0x1e0036[_0xf312('0x2c')]:_0x16ff07[_0xf312('0x2d')];if(_0x51929d[_0xf312('0x2a')][_0xf312('0x3a')]){_0x1e0036[_0xf312('0x3b')]=[{'all':!![]}];}_0x1e0036=_[_0xf312('0x37')]({},_0x1e0036,_0x51929d[_0xf312('0x39')]);return db['CmCustomField'][_0xf312('0x40')](_0x1e0036)[_0xf312('0x1e')](handleEntityNotFound(_0x31f3c2,null))['then'](respondWithResult(_0x31f3c2,null))[_0xf312('0x3c')](handleError(_0x31f3c2,null));};exports[_0xf312('0x1c')]=function(_0x85a507,_0x21fb1d){if(_0x85a507['body']['id']){delete _0x85a507['body']['id'];}return db[_0xf312('0x26')][_0xf312('0x40')]({'where':{'id':_0x85a507['params']['id']}})[_0xf312('0x1e')](handleEntityNotFound(_0x21fb1d,null))[_0xf312('0x1e')](saveUpdates(_0x85a507['body'],null))[_0xf312('0x1e')](respondWithResult(_0x21fb1d,null))[_0xf312('0x3c')](handleError(_0x21fb1d,null));};exports[_0xf312('0x1d')]=function(_0x5f021f,_0x35ca62){return db[_0xf312('0x26')][_0xf312('0x40')]({'where':{'id':_0x5f021f['params']['id']}})['then'](handleEntityNotFound(_0x35ca62,null))[_0xf312('0x1e')](removeEntity(_0x35ca62,null))[_0xf312('0x3c')](handleError(_0x35ca62,null));};exports[_0xf312('0x41')]=function(_0x38e3a8,_0x976bc1){var _0x17b25a;return db[_0xf312('0x42')][_0xf312('0x43')](function(_0x346a20){return db[_0xf312('0x26')][_0xf312('0x41')](_0x38e3a8[_0xf312('0x44')],{'transaction':_0x346a20})[_0xf312('0x1e')](function(_0x270559){_0x17b25a=_0x270559;var _0x55e290={'type':db[_0xf312('0x45')][_0xf312('0x46')],'transaction':_0x346a20};switch(_0x38e3a8[_0xf312('0x44')][_0xf312('0x29')]){case _0xf312('0x47'):_0x55e290[_0xf312('0x29')]=db[_0xf312('0x45')][_0xf312('0x46')];break;case _0xf312('0x48'):_0x55e290[_0xf312('0x29')]=db[_0xf312('0x45')][_0xf312('0x49')];break;case _0xf312('0x4a'):_0x55e290[_0xf312('0x29')]=db[_0xf312('0x45')]['BOOLEAN'];_0x55e290[_0xf312('0x4b')]=![];break;default:}return db[_0xf312('0x42')][_0xf312('0x4c')][_0xf312('0x4d')](_0xf312('0x4e'),util[_0xf312('0x4f')](_0xf312('0x50'),_0x17b25a['id']),_0x55e290);})['then'](function(){return _0x17b25a;});})[_0xf312('0x1e')](respondWithResult(_0x976bc1,0xc9))[_0xf312('0x3c')](handleError(_0x976bc1,null));};