Built motion from commit fe909640.|2.6.8
[motion2.git] / server / api / intSugarcrmField / intSugarcrmField.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 _0x161a=['findAll','rows','params','length','includeAll','find','catch','create','body','eml-format','request-promise','bluebird','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../mysqldb','status','end','json','offset','undefined','count','limit','set','Content-Range','apply','reject','update','then','destroy','sendStatus','error','name','send','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','order','sort','where','pick','filter','merge','VIRTUAL','options','include','SugarcrmField'];(function(_0x3b5250,_0x7a0b2c){var _0xc844a1=function(_0x2fbc98){while(--_0x2fbc98){_0x3b5250['push'](_0x3b5250['shift']());}};_0xc844a1(++_0x7a0b2c);}(_0x161a,0x16c));var _0xa161=function(_0x3e0763,_0x3d12be){_0x3e0763=_0x3e0763-0x0;var _0x351ca2=_0x161a[_0x3e0763];return _0x351ca2;};'use strict';var emlformat=require(_0xa161('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xa161('0x1'));var moment=require('moment');var BPromise=require(_0xa161('0x2'));var Mustache=require('mustache');var util=require(_0xa161('0x3'));var path=require(_0xa161('0x4'));var sox=require(_0xa161('0x5'));var csv=require(_0xa161('0x6'));var ejs=require(_0xa161('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xa161('0x8'));var squel=require(_0xa161('0x9'));var crypto=require(_0xa161('0xa'));var jsforce=require(_0xa161('0xb'));var deskjs=require('desk.js');var toCsv=require(_0xa161('0x6'));var querystring=require('querystring');var Papa=require(_0xa161('0xc'));var Redis=require(_0xa161('0xd'));var authService=require(_0xa161('0xe'));var qs=require(_0xa161('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xa161('0x10'));var logger=require(_0xa161('0x11'))(_0xa161('0x12'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xa161('0x13'))['db'];function respondWithStatusCode(_0x1aee40,_0x3e3020){_0x3e3020=_0x3e3020||0xcc;return function(_0x1a3773){if(_0x1a3773){return _0x1aee40['sendStatus'](_0x3e3020);}return _0x1aee40[_0xa161('0x14')](_0x3e3020)[_0xa161('0x15')]();};}function respondWithResult(_0x4547b9,_0x1eb938){_0x1eb938=_0x1eb938||0xc8;return function(_0x411429){if(_0x411429){return _0x4547b9[_0xa161('0x14')](_0x1eb938)[_0xa161('0x16')](_0x411429);}};}function respondWithFilteredResult(_0x3e38f8,_0x48d01f){return function(_0x3c6ce3){if(_0x3c6ce3){var _0x1f1e45=typeof _0x48d01f[_0xa161('0x17')]===_0xa161('0x18')&&typeof _0x48d01f['limit']===_0xa161('0x18');var _0x58aa12=_0x3c6ce3[_0xa161('0x19')];var _0x172b92=_0x1f1e45?0x0:_0x48d01f[_0xa161('0x17')];var _0x331008=_0x1f1e45?_0x3c6ce3['count']:_0x48d01f[_0xa161('0x17')]+_0x48d01f[_0xa161('0x1a')];var _0x58183e;if(_0x331008>=_0x58aa12){_0x331008=_0x58aa12;_0x58183e=0xc8;}else{_0x58183e=0xce;}_0x3e38f8['status'](_0x58183e);return _0x3e38f8[_0xa161('0x1b')](_0xa161('0x1c'),_0x172b92+'-'+_0x331008+'/'+_0x58aa12)[_0xa161('0x16')](_0x3c6ce3);}return null;};}function patchUpdates(_0x306ee4){return function(_0x137fb9){try{jsonpatch[_0xa161('0x1d')](_0x137fb9,_0x306ee4,!![]);}catch(_0x16b4d6){return BPromise[_0xa161('0x1e')](_0x16b4d6);}return _0x137fb9['save']();};}function saveUpdates(_0x5e323c,_0x508691){return function(_0x3c5e5c){if(_0x3c5e5c){return _0x3c5e5c[_0xa161('0x1f')](_0x5e323c)[_0xa161('0x20')](function(_0x4f9eb2){return _0x4f9eb2;});}return null;};}function removeEntity(_0x5f2be3,_0x527bb8){return function(_0xaf78ff){if(_0xaf78ff){return _0xaf78ff[_0xa161('0x21')]()[_0xa161('0x20')](function(){_0x5f2be3[_0xa161('0x14')](0xcc)[_0xa161('0x15')]();});}};}function handleEntityNotFound(_0x423372,_0x4a6075){return function(_0x2d43cf){if(!_0x2d43cf){_0x423372[_0xa161('0x22')](0x194);}return _0x2d43cf;};}function handleError(_0x1fb4de,_0x29c9df){_0x29c9df=_0x29c9df||0x1f4;return function(_0xab4ec4){logger[_0xa161('0x23')](_0xab4ec4['stack']);if(_0xab4ec4[_0xa161('0x24')]){delete _0xab4ec4[_0xa161('0x24')];}_0x1fb4de[_0xa161('0x14')](_0x29c9df)[_0xa161('0x25')](_0xab4ec4);};}exports[_0xa161('0x26')]=function(_0x1c2336,_0x38e47c){var _0x4d1799={},_0x3cf9e3={},_0x2ae06c={'count':0x0,'rows':[]};var _0x196d40=_[_0xa161('0x27')](db['SugarcrmField'][_0xa161('0x28')],function(_0xf3ca7d){return{'name':_0xf3ca7d[_0xa161('0x29')],'type':_0xf3ca7d[_0xa161('0x2a')][_0xa161('0x2b')]};});_0x3cf9e3[_0xa161('0x2c')]=_[_0xa161('0x27')](_0x196d40,_0xa161('0x24'));_0x3cf9e3[_0xa161('0x2d')]=_[_0xa161('0x2e')](_0x1c2336[_0xa161('0x2d')]);_0x3cf9e3[_0xa161('0x2f')]=_[_0xa161('0x30')](_0x3cf9e3[_0xa161('0x2c')],_0x3cf9e3[_0xa161('0x2d')]);_0x4d1799[_0xa161('0x31')]=_[_0xa161('0x30')](_0x3cf9e3[_0xa161('0x2c')],qs[_0xa161('0x32')](_0x1c2336[_0xa161('0x2d')][_0xa161('0x32')]));_0x4d1799[_0xa161('0x31')]=_0x4d1799[_0xa161('0x31')]['length']?_0x4d1799['attributes']:_0x3cf9e3[_0xa161('0x2c')];if(!_0x1c2336[_0xa161('0x2d')][_0xa161('0x33')]('nolimit')){_0x4d1799[_0xa161('0x1a')]=qs[_0xa161('0x1a')](_0x1c2336[_0xa161('0x2d')][_0xa161('0x1a')]);_0x4d1799[_0xa161('0x17')]=qs[_0xa161('0x17')](_0x1c2336[_0xa161('0x2d')][_0xa161('0x17')]);}_0x4d1799[_0xa161('0x34')]=qs[_0xa161('0x35')](_0x1c2336[_0xa161('0x2d')][_0xa161('0x35')]);_0x4d1799[_0xa161('0x36')]=qs[_0xa161('0x2f')](_[_0xa161('0x37')](_0x1c2336[_0xa161('0x2d')],_0x3cf9e3[_0xa161('0x2f')]),_0x196d40);if(_0x1c2336[_0xa161('0x2d')][_0xa161('0x38')]){_0x4d1799[_0xa161('0x36')]=_[_0xa161('0x39')](_0x4d1799[_0xa161('0x36')],{'$or':_[_0xa161('0x27')](_0x196d40,function(_0x214a5d){if(_0x214a5d[_0xa161('0x2a')]!==_0xa161('0x3a')){var _0x1c4aec={};_0x1c4aec[_0x214a5d[_0xa161('0x24')]]={'$like':'%'+_0x1c2336[_0xa161('0x2d')]['filter']+'%'};return _0x1c4aec;}})});}_0x4d1799=_[_0xa161('0x39')]({},_0x4d1799,_0x1c2336[_0xa161('0x3b')]);var _0x19b26b={'where':_0x4d1799[_0xa161('0x36')]};return db['SugarcrmField'][_0xa161('0x19')](_0x19b26b)[_0xa161('0x20')](function(_0x14c29a){_0x2ae06c[_0xa161('0x19')]=_0x14c29a;if(_0x1c2336[_0xa161('0x2d')]['includeAll']){_0x4d1799[_0xa161('0x3c')]=[{'all':!![]}];}return db[_0xa161('0x3d')][_0xa161('0x3e')](_0x4d1799);})[_0xa161('0x20')](function(_0x4dcceb){_0x2ae06c[_0xa161('0x3f')]=_0x4dcceb;return _0x2ae06c;})['then'](respondWithFilteredResult(_0x38e47c,_0x4d1799))['catch'](handleError(_0x38e47c,null));};exports['show']=function(_0x514f16,_0x279791){var _0x45bfbd={'raw':!![],'where':{'id':_0x514f16[_0xa161('0x40')]['id']}},_0x4db536={};_0x4db536[_0xa161('0x2c')]=_['keys'](db[_0xa161('0x3d')][_0xa161('0x28')]);_0x4db536[_0xa161('0x2d')]=_['keys'](_0x514f16['query']);_0x4db536[_0xa161('0x2f')]=_['intersection'](_0x4db536['model'],_0x4db536[_0xa161('0x2d')]);_0x45bfbd[_0xa161('0x31')]=_['intersection'](_0x4db536[_0xa161('0x2c')],qs[_0xa161('0x32')](_0x514f16[_0xa161('0x2d')][_0xa161('0x32')]));_0x45bfbd['attributes']=_0x45bfbd[_0xa161('0x31')][_0xa161('0x41')]?_0x45bfbd[_0xa161('0x31')]:_0x4db536[_0xa161('0x2c')];if(_0x514f16[_0xa161('0x2d')][_0xa161('0x42')]){_0x45bfbd[_0xa161('0x3c')]=[{'all':!![]}];}_0x45bfbd=_[_0xa161('0x39')]({},_0x45bfbd,_0x514f16['options']);return db['SugarcrmField'][_0xa161('0x43')](_0x45bfbd)[_0xa161('0x20')](handleEntityNotFound(_0x279791,null))[_0xa161('0x20')](respondWithResult(_0x279791,null))[_0xa161('0x44')](handleError(_0x279791,null));};exports[_0xa161('0x45')]=function(_0x2ee83a,_0x2cc9e2){return db[_0xa161('0x3d')][_0xa161('0x45')](_0x2ee83a[_0xa161('0x46')],{})[_0xa161('0x20')](respondWithResult(_0x2cc9e2,0xc9))[_0xa161('0x44')](handleError(_0x2cc9e2,null));};exports[_0xa161('0x1f')]=function(_0x35644a,_0x26d226){if(_0x35644a[_0xa161('0x46')]['id']){delete _0x35644a[_0xa161('0x46')]['id'];}return db[_0xa161('0x3d')]['find']({'where':{'id':_0x35644a[_0xa161('0x40')]['id']}})[_0xa161('0x20')](handleEntityNotFound(_0x26d226,null))[_0xa161('0x20')](saveUpdates(_0x35644a[_0xa161('0x46')],null))[_0xa161('0x20')](respondWithResult(_0x26d226,null))[_0xa161('0x44')](handleError(_0x26d226,null));};exports[_0xa161('0x21')]=function(_0x10d9d5,_0x4520a5){return db['SugarcrmField'][_0xa161('0x43')]({'where':{'id':_0x10d9d5['params']['id']}})[_0xa161('0x20')](handleEntityNotFound(_0x4520a5,null))[_0xa161('0x20')](removeEntity(_0x4520a5,null))[_0xa161('0x44')](handleError(_0x4520a5,null));};