Built motion from commit (unavailable).|2.5.28
[motion2.git] / server / api / intDeskField / intDeskField.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 _0xc0df=['fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','options','includeAll','include','rows','catch','show','find','create','body','params','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','limit','Content-Range','apply','reject','update','then','error','stack','name','send','index','map','DeskField','rawAttributes'];(function(_0x53307c,_0x5c940c){var _0x381cd1=function(_0x37254c){while(--_0x37254c){_0x53307c['push'](_0x53307c['shift']());}};_0x381cd1(++_0x5c940c);}(_0xc0df,0x155));var _0xfc0d=function(_0x167cc1,_0x56ef5a){_0x167cc1=_0x167cc1-0x0;var _0x10bc4b=_0xc0df[_0x167cc1];return _0x10bc4b;};'use strict';var emlformat=require(_0xfc0d('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xfc0d('0x1'));var jsonpatch=require(_0xfc0d('0x2'));var rp=require(_0xfc0d('0x3'));var moment=require(_0xfc0d('0x4'));var BPromise=require(_0xfc0d('0x5'));var Mustache=require(_0xfc0d('0x6'));var util=require(_0xfc0d('0x7'));var path=require(_0xfc0d('0x8'));var sox=require(_0xfc0d('0x9'));var csv=require(_0xfc0d('0xa'));var ejs=require(_0xfc0d('0xb'));var fs=require('fs');var fs_extra=require(_0xfc0d('0xc'));var _=require('lodash');var squel=require(_0xfc0d('0xd'));var crypto=require(_0xfc0d('0xe'));var jsforce=require(_0xfc0d('0xf'));var deskjs=require(_0xfc0d('0x10'));var toCsv=require(_0xfc0d('0xa'));var querystring=require(_0xfc0d('0x11'));var Papa=require(_0xfc0d('0x12'));var Redis=require('ioredis');var authService=require(_0xfc0d('0x13'));var qs=require(_0xfc0d('0x14'));var as=require(_0xfc0d('0x15'));var hardwareService=require(_0xfc0d('0x16'));var logger=require(_0xfc0d('0x17'))(_0xfc0d('0x18'));var utils=require(_0xfc0d('0x19'));var config=require(_0xfc0d('0x1a'));var licenseUtil=require(_0xfc0d('0x1b'));var db=require(_0xfc0d('0x1c'))['db'];function respondWithStatusCode(_0x2eb786,_0x40e31f){_0x40e31f=_0x40e31f||0xcc;return function(_0x469d5f){if(_0x469d5f){return _0x2eb786[_0xfc0d('0x1d')](_0x40e31f);}return _0x2eb786[_0xfc0d('0x1e')](_0x40e31f)[_0xfc0d('0x1f')]();};}function respondWithResult(_0x586bcd,_0xcb1fdd){_0xcb1fdd=_0xcb1fdd||0xc8;return function(_0x37e698){if(_0x37e698){return _0x586bcd[_0xfc0d('0x1e')](_0xcb1fdd)[_0xfc0d('0x20')](_0x37e698);}};}function respondWithFilteredResult(_0x2e37c9,_0x267750){return function(_0x828fa6){if(_0x828fa6){var _0x13e806=_0x828fa6[_0xfc0d('0x21')],_0x515cad=_0x267750['offset'],_0x3fc1c5=_0x267750[_0xfc0d('0x22')]+_0x267750[_0xfc0d('0x23')],_0x5f362a;if(_0x3fc1c5>=_0x13e806){_0x3fc1c5=_0x13e806;_0x5f362a=0xc8;}else{_0x5f362a=0xce;}_0x2e37c9[_0xfc0d('0x1e')](_0x5f362a);return _0x2e37c9['set'](_0xfc0d('0x24'),_0x515cad+'-'+_0x3fc1c5+'/'+_0x13e806)['json'](_0x828fa6);}return null;};}function patchUpdates(_0x418453){return function(_0x38c54b){try{jsonpatch[_0xfc0d('0x25')](_0x38c54b,_0x418453,!![]);}catch(_0x1fa461){return BPromise[_0xfc0d('0x26')](_0x1fa461);}return _0x38c54b['save']();};}function saveUpdates(_0x30576b,_0x1c010c){return function(_0x2056e5){if(_0x2056e5){return _0x2056e5[_0xfc0d('0x27')](_0x30576b)[_0xfc0d('0x28')](function(_0x57385e){return _0x57385e;});}return null;};}function removeEntity(_0x32a94b,_0x411c6d){return function(_0x4d19e1){if(_0x4d19e1){return _0x4d19e1['destroy']()[_0xfc0d('0x28')](function(){_0x32a94b['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x4e56d2,_0x317336){return function(_0x38d92b){if(!_0x38d92b){_0x4e56d2['sendStatus'](0x194);}return _0x38d92b;};}function handleError(_0x49241e,_0x57774a){_0x57774a=_0x57774a||0x1f4;return function(_0x33700b){logger[_0xfc0d('0x29')](_0x33700b[_0xfc0d('0x2a')]);if(_0x33700b[_0xfc0d('0x2b')]){delete _0x33700b[_0xfc0d('0x2b')];}_0x49241e[_0xfc0d('0x1e')](_0x57774a)[_0xfc0d('0x2c')](_0x33700b);};}exports[_0xfc0d('0x2d')]=function(_0x405ef7,_0x35e055){var _0x5de547={},_0x230bda={},_0x23759a={'count':0x0,'rows':[]};var _0x4c881f=_[_0xfc0d('0x2e')](db[_0xfc0d('0x2f')][_0xfc0d('0x30')],function(_0x4555f5){return{'name':_0x4555f5[_0xfc0d('0x31')],'type':_0x4555f5[_0xfc0d('0x32')][_0xfc0d('0x33')]};});_0x230bda[_0xfc0d('0x34')]=_[_0xfc0d('0x2e')](_0x4c881f,'name');_0x230bda[_0xfc0d('0x35')]=_[_0xfc0d('0x36')](_0x405ef7[_0xfc0d('0x35')]);_0x230bda[_0xfc0d('0x37')]=_[_0xfc0d('0x38')](_0x230bda[_0xfc0d('0x34')],_0x230bda['query']);_0x5de547['attributes']=_['intersection'](_0x230bda['model'],qs['fields'](_0x405ef7['query'][_0xfc0d('0x39')]));_0x5de547['attributes']=_0x5de547[_0xfc0d('0x3a')]['length']?_0x5de547[_0xfc0d('0x3a')]:_0x230bda['model'];if(!_0x405ef7[_0xfc0d('0x35')][_0xfc0d('0x3b')](_0xfc0d('0x3c'))){_0x5de547['limit']=qs[_0xfc0d('0x23')](_0x405ef7['query'][_0xfc0d('0x23')]);_0x5de547[_0xfc0d('0x22')]=qs[_0xfc0d('0x22')](_0x405ef7[_0xfc0d('0x35')][_0xfc0d('0x22')]);}_0x5de547[_0xfc0d('0x3d')]=qs[_0xfc0d('0x3e')](_0x405ef7['query'][_0xfc0d('0x3e')]);_0x5de547[_0xfc0d('0x3f')]=qs[_0xfc0d('0x37')](_[_0xfc0d('0x40')](_0x405ef7['query'],_0x230bda[_0xfc0d('0x37')]),_0x4c881f);if(_0x405ef7[_0xfc0d('0x35')][_0xfc0d('0x41')]){_0x5de547[_0xfc0d('0x3f')]=_['merge'](_0x5de547['where'],{'$or':_[_0xfc0d('0x2e')](_0x4c881f,function(_0x2db4de){if(_0x2db4de[_0xfc0d('0x32')]!==_0xfc0d('0x42')){var _0x3a0221={};_0x3a0221[_0x2db4de['name']]={'$like':'%'+_0x405ef7['query'][_0xfc0d('0x41')]+'%'};return _0x3a0221;}})});}_0x5de547=_[_0xfc0d('0x43')]({},_0x5de547,_0x405ef7[_0xfc0d('0x44')]);var _0x2c28e4={'where':_0x5de547['where']};return db[_0xfc0d('0x2f')][_0xfc0d('0x21')](_0x2c28e4)['then'](function(_0x508e3c){_0x23759a[_0xfc0d('0x21')]=_0x508e3c;if(_0x405ef7['query'][_0xfc0d('0x45')]){_0x5de547[_0xfc0d('0x46')]=[{'all':!![]}];}return db[_0xfc0d('0x2f')]['findAll'](_0x5de547);})[_0xfc0d('0x28')](function(_0xf2239e){_0x23759a[_0xfc0d('0x47')]=_0xf2239e;return _0x23759a;})[_0xfc0d('0x28')](respondWithFilteredResult(_0x35e055,_0x5de547))[_0xfc0d('0x48')](handleError(_0x35e055,null));};exports[_0xfc0d('0x49')]=function(_0x48d929,_0x440990){var _0x3c7023={'raw':!![],'where':{'id':_0x48d929['params']['id']}},_0x50dd86={};_0x50dd86['model']=_[_0xfc0d('0x36')](db[_0xfc0d('0x2f')][_0xfc0d('0x30')]);_0x50dd86[_0xfc0d('0x35')]=_[_0xfc0d('0x36')](_0x48d929['query']);_0x50dd86[_0xfc0d('0x37')]=_[_0xfc0d('0x38')](_0x50dd86['model'],_0x50dd86[_0xfc0d('0x35')]);_0x3c7023['attributes']=_[_0xfc0d('0x38')](_0x50dd86['model'],qs[_0xfc0d('0x39')](_0x48d929[_0xfc0d('0x35')][_0xfc0d('0x39')]));_0x3c7023[_0xfc0d('0x3a')]=_0x3c7023[_0xfc0d('0x3a')]['length']?_0x3c7023[_0xfc0d('0x3a')]:_0x50dd86[_0xfc0d('0x34')];if(_0x48d929[_0xfc0d('0x35')][_0xfc0d('0x45')]){_0x3c7023['include']=[{'all':!![]}];}_0x3c7023=_[_0xfc0d('0x43')]({},_0x3c7023,_0x48d929[_0xfc0d('0x44')]);return db[_0xfc0d('0x2f')][_0xfc0d('0x4a')](_0x3c7023)[_0xfc0d('0x28')](handleEntityNotFound(_0x440990,null))[_0xfc0d('0x28')](respondWithResult(_0x440990,null))['catch'](handleError(_0x440990,null));};exports[_0xfc0d('0x4b')]=function(_0x4480a9,_0x1f62e2){return db['DeskField'][_0xfc0d('0x4b')](_0x4480a9['body'],{})[_0xfc0d('0x28')](respondWithResult(_0x1f62e2,0xc9))['catch'](handleError(_0x1f62e2,null));};exports[_0xfc0d('0x27')]=function(_0xa69d30,_0x509ba3){if(_0xa69d30['body']['id']){delete _0xa69d30[_0xfc0d('0x4c')]['id'];}return db['DeskField'][_0xfc0d('0x4a')]({'where':{'id':_0xa69d30[_0xfc0d('0x4d')]['id']}})[_0xfc0d('0x28')](handleEntityNotFound(_0x509ba3,null))[_0xfc0d('0x28')](saveUpdates(_0xa69d30[_0xfc0d('0x4c')],null))[_0xfc0d('0x28')](respondWithResult(_0x509ba3,null))[_0xfc0d('0x48')](handleError(_0x509ba3,null));};exports['destroy']=function(_0x3efe5c,_0x2210e3){return db[_0xfc0d('0x2f')][_0xfc0d('0x4a')]({'where':{'id':_0x3efe5c[_0xfc0d('0x4d')]['id']}})[_0xfc0d('0x28')](handleEntityNotFound(_0x2210e3,null))[_0xfc0d('0x28')](removeEntity(_0x2210e3,null))[_0xfc0d('0x48')](handleError(_0x2210e3,null));};