Built motion from commit (unavailable).|2.5.4
[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 _0xa2e7=['includeAll','include','findAll','rows','catch','show','rawAttributes','find','create','body','params','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','status','offset','limit','set','Content-Range','json','apply','save','update','then','destroy','end','sendStatus','stack','name','send','map','SugarcrmField','fieldName','type','query','keys','filters','intersection','attributes','fields','length','model','hasOwnProperty','order','sort','where','pick','filter','merge','count'];(function(_0x3f6c60,_0x486af8){var _0x2bbe6a=function(_0x25c875){while(--_0x25c875){_0x3f6c60['push'](_0x3f6c60['shift']());}};_0x2bbe6a(++_0x486af8);}(_0xa2e7,0x1c1));var _0x7a2e=function(_0x4f9567,_0x51c8ed){_0x4f9567=_0x4f9567-0x0;var _0x390709=_0xa2e7[_0x4f9567];return _0x390709;};'use strict';var pdf=require(_0x7a2e('0x0'));var emlformat=require(_0x7a2e('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x7a2e('0x2'));var jsonpatch=require(_0x7a2e('0x3'));var rp=require(_0x7a2e('0x4'));var moment=require('moment');var BPromise=require(_0x7a2e('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0x7a2e('0x6'));var sox=require(_0x7a2e('0x7'));var csv=require(_0x7a2e('0x8'));var ejs=require(_0x7a2e('0x9'));var fs=require('fs');var _=require(_0x7a2e('0xa'));var squel=require(_0x7a2e('0xb'));var crypto=require(_0x7a2e('0xc'));var jsforce=require(_0x7a2e('0xd'));var deskjs=require(_0x7a2e('0xe'));var toCsv=require(_0x7a2e('0x8'));var querystring=require(_0x7a2e('0xf'));var Papa=require('papaparse');var Redis=require(_0x7a2e('0x10'));var authService=require(_0x7a2e('0x11'));var qs=require(_0x7a2e('0x12'));var as=require(_0x7a2e('0x13'));var hardwareService=require(_0x7a2e('0x14'));var logger=require(_0x7a2e('0x15'))(_0x7a2e('0x16'));var utils=require(_0x7a2e('0x17'));var config=require(_0x7a2e('0x18'));var db=require(_0x7a2e('0x19'))['db'];function respondWithStatusCode(_0x4c9c28,_0x137663){_0x137663=_0x137663||0xcc;return function(_0x3df665){if(_0x3df665){return _0x4c9c28['sendStatus'](_0x137663);}return _0x4c9c28[_0x7a2e('0x1a')](_0x137663)['end']();};}function respondWithResult(_0x4f6f12,_0xb3536){_0xb3536=_0xb3536||0xc8;return function(_0x3a08cb){if(_0x3a08cb){return _0x4f6f12[_0x7a2e('0x1a')](_0xb3536)['json'](_0x3a08cb);}};}function respondWithFilteredResult(_0x470e02,_0x35163d){return function(_0x4d6eff){if(_0x4d6eff){var _0x1c25a8=_0x4d6eff['count'],_0xdd2bb=_0x35163d['offset'],_0x355f7b=_0x35163d[_0x7a2e('0x1b')]+_0x35163d[_0x7a2e('0x1c')],_0x36e15f;if(_0x355f7b>=_0x1c25a8){_0x355f7b=_0x1c25a8;_0x36e15f=0xc8;}else{_0x36e15f=0xce;}_0x470e02[_0x7a2e('0x1a')](_0x36e15f);return _0x470e02[_0x7a2e('0x1d')](_0x7a2e('0x1e'),_0xdd2bb+'-'+_0x355f7b+'/'+_0x1c25a8)[_0x7a2e('0x1f')](_0x4d6eff);}return null;};}function patchUpdates(_0x22d157){return function(_0xd11cfb){try{jsonpatch[_0x7a2e('0x20')](_0xd11cfb,_0x22d157,!![]);}catch(_0x100218){return BPromise['reject'](_0x100218);}return _0xd11cfb[_0x7a2e('0x21')]();};}function saveUpdates(_0x20cd63,_0x4c5212){return function(_0x345904){if(_0x345904){return _0x345904[_0x7a2e('0x22')](_0x20cd63)[_0x7a2e('0x23')](function(_0x3d0907){return _0x3d0907;});}return null;};}function removeEntity(_0x3fe136,_0x3ebc9c){return function(_0x20f31f){if(_0x20f31f){return _0x20f31f[_0x7a2e('0x24')]()[_0x7a2e('0x23')](function(){_0x3fe136['status'](0xcc)[_0x7a2e('0x25')]();});}};}function handleEntityNotFound(_0x32a4b9,_0x17e5ab){return function(_0x2bb4c8){if(!_0x2bb4c8){_0x32a4b9[_0x7a2e('0x26')](0x194);}return _0x2bb4c8;};}function handleError(_0x5e8d14,_0x3f14dd){_0x3f14dd=_0x3f14dd||0x1f4;return function(_0x4f7c75){logger['error'](_0x4f7c75[_0x7a2e('0x27')]);if(_0x4f7c75[_0x7a2e('0x28')]){delete _0x4f7c75[_0x7a2e('0x28')];}_0x5e8d14[_0x7a2e('0x1a')](_0x3f14dd)[_0x7a2e('0x29')](_0x4f7c75);};}exports['index']=function(_0x3f09ec,_0x1512e7){var _0x1f30e6={},_0x15891b={},_0xe14723={'count':0x0,'rows':[]};var _0x1343a4=_[_0x7a2e('0x2a')](db[_0x7a2e('0x2b')]['rawAttributes'],function(_0x22571d){return{'name':_0x22571d[_0x7a2e('0x2c')],'type':_0x22571d[_0x7a2e('0x2d')]['key']};});_0x15891b['model']=_[_0x7a2e('0x2a')](_0x1343a4,'name');_0x15891b[_0x7a2e('0x2e')]=_[_0x7a2e('0x2f')](_0x3f09ec[_0x7a2e('0x2e')]);_0x15891b[_0x7a2e('0x30')]=_[_0x7a2e('0x31')](_0x15891b['model'],_0x15891b[_0x7a2e('0x2e')]);_0x1f30e6[_0x7a2e('0x32')]=_[_0x7a2e('0x31')](_0x15891b['model'],qs[_0x7a2e('0x33')](_0x3f09ec[_0x7a2e('0x2e')][_0x7a2e('0x33')]));_0x1f30e6[_0x7a2e('0x32')]=_0x1f30e6[_0x7a2e('0x32')][_0x7a2e('0x34')]?_0x1f30e6[_0x7a2e('0x32')]:_0x15891b[_0x7a2e('0x35')];if(!_0x3f09ec[_0x7a2e('0x2e')][_0x7a2e('0x36')]('nolimit')){_0x1f30e6[_0x7a2e('0x1c')]=qs[_0x7a2e('0x1c')](_0x3f09ec[_0x7a2e('0x2e')][_0x7a2e('0x1c')]);_0x1f30e6[_0x7a2e('0x1b')]=qs[_0x7a2e('0x1b')](_0x3f09ec['query'][_0x7a2e('0x1b')]);}_0x1f30e6[_0x7a2e('0x37')]=qs[_0x7a2e('0x38')](_0x3f09ec['query']['sort']);_0x1f30e6[_0x7a2e('0x39')]=qs['filters'](_[_0x7a2e('0x3a')](_0x3f09ec[_0x7a2e('0x2e')],_0x15891b[_0x7a2e('0x30')]),_0x1343a4);if(_0x3f09ec[_0x7a2e('0x2e')][_0x7a2e('0x3b')]){_0x1f30e6['where']=_[_0x7a2e('0x3c')](_0x1f30e6[_0x7a2e('0x39')],{'$or':_[_0x7a2e('0x2a')](_0x1343a4,function(_0x305633){if(_0x305633[_0x7a2e('0x2d')]!=='VIRTUAL'){var _0x1f0680={};_0x1f0680[_0x305633[_0x7a2e('0x28')]]={'$like':'%'+_0x3f09ec[_0x7a2e('0x2e')][_0x7a2e('0x3b')]+'%'};return _0x1f0680;}})});}_0x1f30e6=_[_0x7a2e('0x3c')]({},_0x1f30e6,_0x3f09ec['options']);var _0x3e022b={'where':_0x1f30e6[_0x7a2e('0x39')]};return db['SugarcrmField'][_0x7a2e('0x3d')](_0x3e022b)['then'](function(_0x2c9358){_0xe14723[_0x7a2e('0x3d')]=_0x2c9358;if(_0x3f09ec['query'][_0x7a2e('0x3e')]){_0x1f30e6[_0x7a2e('0x3f')]=[{'all':!![]}];}return db[_0x7a2e('0x2b')][_0x7a2e('0x40')](_0x1f30e6);})[_0x7a2e('0x23')](function(_0x5455b6){_0xe14723[_0x7a2e('0x41')]=_0x5455b6;return _0xe14723;})['then'](respondWithFilteredResult(_0x1512e7,_0x1f30e6))[_0x7a2e('0x42')](handleError(_0x1512e7,null));};exports[_0x7a2e('0x43')]=function(_0x2b3020,_0x92ba5a){var _0xbf3693={'raw':!![],'where':{'id':_0x2b3020['params']['id']}},_0x3d5770={};_0x3d5770[_0x7a2e('0x35')]=_['keys'](db['SugarcrmField'][_0x7a2e('0x44')]);_0x3d5770[_0x7a2e('0x2e')]=_[_0x7a2e('0x2f')](_0x2b3020[_0x7a2e('0x2e')]);_0x3d5770['filters']=_[_0x7a2e('0x31')](_0x3d5770[_0x7a2e('0x35')],_0x3d5770[_0x7a2e('0x2e')]);_0xbf3693[_0x7a2e('0x32')]=_[_0x7a2e('0x31')](_0x3d5770[_0x7a2e('0x35')],qs[_0x7a2e('0x33')](_0x2b3020['query'][_0x7a2e('0x33')]));_0xbf3693[_0x7a2e('0x32')]=_0xbf3693[_0x7a2e('0x32')]['length']?_0xbf3693[_0x7a2e('0x32')]:_0x3d5770['model'];if(_0x2b3020['query']['includeAll']){_0xbf3693[_0x7a2e('0x3f')]=[{'all':!![]}];}_0xbf3693=_['merge']({},_0xbf3693,_0x2b3020['options']);return db[_0x7a2e('0x2b')][_0x7a2e('0x45')](_0xbf3693)['then'](handleEntityNotFound(_0x92ba5a,null))['then'](respondWithResult(_0x92ba5a,null))['catch'](handleError(_0x92ba5a,null));};exports[_0x7a2e('0x46')]=function(_0x28b91f,_0x31cbde){return db[_0x7a2e('0x2b')][_0x7a2e('0x46')](_0x28b91f[_0x7a2e('0x47')],{})['then'](respondWithResult(_0x31cbde,0xc9))[_0x7a2e('0x42')](handleError(_0x31cbde,null));};exports[_0x7a2e('0x22')]=function(_0x2f5350,_0x50d70c){if(_0x2f5350[_0x7a2e('0x47')]['id']){delete _0x2f5350[_0x7a2e('0x47')]['id'];}return db[_0x7a2e('0x2b')]['find']({'where':{'id':_0x2f5350[_0x7a2e('0x48')]['id']}})[_0x7a2e('0x23')](handleEntityNotFound(_0x50d70c,null))[_0x7a2e('0x23')](saveUpdates(_0x2f5350['body'],null))['then'](respondWithResult(_0x50d70c,null))['catch'](handleError(_0x50d70c,null));};exports[_0x7a2e('0x24')]=function(_0x4bed49,_0x3c47c1){return db[_0x7a2e('0x2b')][_0x7a2e('0x45')]({'where':{'id':_0x4bed49[_0x7a2e('0x48')]['id']}})['then'](handleEntityNotFound(_0x3c47c1,null))[_0x7a2e('0x23')](removeEntity(_0x3c47c1,null))[_0x7a2e('0x42')](handleError(_0x3c47c1,null));};