Built motion from commit (unavailable).|2.5.0
[motion2.git] / server / api / intFreshsalesField / intFreshsalesField.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 _0x39cb=['filter','merge','include','findAll','rows','catch','show','params','includeAll','options','create','body','find','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','ejs','lodash','squel','crypto','to-csv','querystring','papaparse','ioredis','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','save','update','then','destroy','error','stack','name','index','map','FreshsalesField','rawAttributes','fieldName','type','model','query','keys','filters','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick'];(function(_0x1928c9,_0x13a6d1){var _0x51b5fb=function(_0x24cf70){while(--_0x24cf70){_0x1928c9['push'](_0x1928c9['shift']());}};_0x51b5fb(++_0x13a6d1);}(_0x39cb,0x1bd));var _0xb39c=function(_0x19950b,_0x53d0d7){_0x19950b=_0x19950b-0x0;var _0x3c6b41=_0x39cb[_0x19950b];return _0x3c6b41;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xb39c('0x0'));var rimraf=require(_0xb39c('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xb39c('0x2'));var rp=require(_0xb39c('0x3'));var moment=require('moment');var BPromise=require(_0xb39c('0x4'));var Mustache=require(_0xb39c('0x5'));var util=require(_0xb39c('0x6'));var path=require(_0xb39c('0x7'));var sox=require(_0xb39c('0x8'));var csv=require('to-csv');var ejs=require(_0xb39c('0x9'));var fs=require('fs');var _=require(_0xb39c('0xa'));var squel=require(_0xb39c('0xb'));var crypto=require(_0xb39c('0xc'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xb39c('0xd'));var querystring=require(_0xb39c('0xe'));var Papa=require(_0xb39c('0xf'));var Redis=require(_0xb39c('0x10'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xb39c('0x11'));var logger=require(_0xb39c('0x12'))(_0xb39c('0x13'));var utils=require(_0xb39c('0x14'));var config=require(_0xb39c('0x15'));var db=require(_0xb39c('0x16'))['db'];function respondWithStatusCode(_0x2a5c79,_0x18d12e){_0x18d12e=_0x18d12e||0xcc;return function(_0x51ff24){if(_0x51ff24){return _0x2a5c79[_0xb39c('0x17')](_0x18d12e);}return _0x2a5c79[_0xb39c('0x18')](_0x18d12e)[_0xb39c('0x19')]();};}function respondWithResult(_0x5e4caf,_0xf4662a){_0xf4662a=_0xf4662a||0xc8;return function(_0x40a6d3){if(_0x40a6d3){return _0x5e4caf[_0xb39c('0x18')](_0xf4662a)[_0xb39c('0x1a')](_0x40a6d3);}};}function respondWithFilteredResult(_0x469fa9,_0x27c22a){return function(_0x8e9181){if(_0x8e9181){var _0x5277ce=_0x8e9181[_0xb39c('0x1b')],_0x316c9b=_0x27c22a[_0xb39c('0x1c')],_0x3223f6=_0x27c22a[_0xb39c('0x1c')]+_0x27c22a[_0xb39c('0x1d')],_0x10989d;if(_0x3223f6>=_0x5277ce){_0x3223f6=_0x5277ce;_0x10989d=0xc8;}else{_0x10989d=0xce;}_0x469fa9[_0xb39c('0x18')](_0x10989d);return _0x469fa9[_0xb39c('0x1e')](_0xb39c('0x1f'),_0x316c9b+'-'+_0x3223f6+'/'+_0x5277ce)['json'](_0x8e9181);}return null;};}function patchUpdates(_0x1d2f49){return function(_0x1a8e12){try{jsonpatch[_0xb39c('0x20')](_0x1a8e12,_0x1d2f49,!![]);}catch(_0x447352){return BPromise['reject'](_0x447352);}return _0x1a8e12[_0xb39c('0x21')]();};}function saveUpdates(_0x2da46a,_0x5e4a0b){return function(_0x2d8e93){if(_0x2d8e93){return _0x2d8e93[_0xb39c('0x22')](_0x2da46a)[_0xb39c('0x23')](function(_0x4ebfca){return _0x4ebfca;});}return null;};}function removeEntity(_0x539d27,_0x2789fd){return function(_0x1a5b9d){if(_0x1a5b9d){return _0x1a5b9d[_0xb39c('0x24')]()['then'](function(){_0x539d27[_0xb39c('0x18')](0xcc)[_0xb39c('0x19')]();});}};}function handleEntityNotFound(_0x1bb895,_0x16f3b0){return function(_0x3b03ed){if(!_0x3b03ed){_0x1bb895['sendStatus'](0x194);}return _0x3b03ed;};}function handleError(_0x3036f5,_0xbeab7e){_0xbeab7e=_0xbeab7e||0x1f4;return function(_0x583ee5){logger[_0xb39c('0x25')](_0x583ee5[_0xb39c('0x26')]);if(_0x583ee5[_0xb39c('0x27')]){delete _0x583ee5[_0xb39c('0x27')];}_0x3036f5[_0xb39c('0x18')](_0xbeab7e)['send'](_0x583ee5);};}exports[_0xb39c('0x28')]=function(_0x299c27,_0x132769){var _0x4c06fa={},_0x41fff2={},_0x337532={'count':0x0,'rows':[]};var _0x52eb5e=_[_0xb39c('0x29')](db[_0xb39c('0x2a')][_0xb39c('0x2b')],function(_0x4e9672){return{'name':_0x4e9672[_0xb39c('0x2c')],'type':_0x4e9672[_0xb39c('0x2d')]['key']};});_0x41fff2[_0xb39c('0x2e')]=_['map'](_0x52eb5e,_0xb39c('0x27'));_0x41fff2[_0xb39c('0x2f')]=_[_0xb39c('0x30')](_0x299c27[_0xb39c('0x2f')]);_0x41fff2[_0xb39c('0x31')]=_['intersection'](_0x41fff2[_0xb39c('0x2e')],_0x41fff2['query']);_0x4c06fa[_0xb39c('0x32')]=_['intersection'](_0x41fff2[_0xb39c('0x2e')],qs[_0xb39c('0x33')](_0x299c27[_0xb39c('0x2f')][_0xb39c('0x33')]));_0x4c06fa['attributes']=_0x4c06fa['attributes'][_0xb39c('0x34')]?_0x4c06fa[_0xb39c('0x32')]:_0x41fff2['model'];if(!_0x299c27[_0xb39c('0x2f')][_0xb39c('0x35')](_0xb39c('0x36'))){_0x4c06fa[_0xb39c('0x1d')]=qs[_0xb39c('0x1d')](_0x299c27[_0xb39c('0x2f')][_0xb39c('0x1d')]);_0x4c06fa[_0xb39c('0x1c')]=qs[_0xb39c('0x1c')](_0x299c27[_0xb39c('0x2f')][_0xb39c('0x1c')]);}_0x4c06fa[_0xb39c('0x37')]=qs[_0xb39c('0x38')](_0x299c27[_0xb39c('0x2f')][_0xb39c('0x38')]);_0x4c06fa[_0xb39c('0x39')]=qs[_0xb39c('0x31')](_[_0xb39c('0x3a')](_0x299c27[_0xb39c('0x2f')],_0x41fff2['filters']));if(_0x299c27[_0xb39c('0x2f')][_0xb39c('0x3b')]){_0x4c06fa['where']=_['merge'](_0x4c06fa['where'],{'$or':_[_0xb39c('0x29')](_0x52eb5e,function(_0x33e468){if(_0x33e468[_0xb39c('0x2d')]!=='VIRTUAL'){var _0x3071dd={};_0x3071dd[_0x33e468[_0xb39c('0x27')]]={'$like':'%'+_0x299c27[_0xb39c('0x2f')][_0xb39c('0x3b')]+'%'};return _0x3071dd;}})});}_0x4c06fa=_[_0xb39c('0x3c')]({},_0x4c06fa,_0x299c27['options']);var _0x3cdeeb={'where':_0x4c06fa[_0xb39c('0x39')]};return db['FreshsalesField'][_0xb39c('0x1b')](_0x3cdeeb)['then'](function(_0x1ee418){_0x337532[_0xb39c('0x1b')]=_0x1ee418;if(_0x299c27[_0xb39c('0x2f')]['includeAll']){_0x4c06fa[_0xb39c('0x3d')]=[{'all':!![]}];}return db[_0xb39c('0x2a')][_0xb39c('0x3e')](_0x4c06fa);})[_0xb39c('0x23')](function(_0x10b87b){_0x337532[_0xb39c('0x3f')]=_0x10b87b;return _0x337532;})[_0xb39c('0x23')](respondWithFilteredResult(_0x132769,_0x4c06fa))[_0xb39c('0x40')](handleError(_0x132769,null));};exports[_0xb39c('0x41')]=function(_0x263544,_0x38359d){var _0xd1136f={'raw':!![],'where':{'id':_0x263544[_0xb39c('0x42')]['id']}},_0x53347e={};_0x53347e[_0xb39c('0x2e')]=_[_0xb39c('0x30')](db[_0xb39c('0x2a')][_0xb39c('0x2b')]);_0x53347e[_0xb39c('0x2f')]=_[_0xb39c('0x30')](_0x263544[_0xb39c('0x2f')]);_0x53347e[_0xb39c('0x31')]=_['intersection'](_0x53347e['model'],_0x53347e[_0xb39c('0x2f')]);_0xd1136f[_0xb39c('0x32')]=_['intersection'](_0x53347e['model'],qs[_0xb39c('0x33')](_0x263544['query'][_0xb39c('0x33')]));_0xd1136f[_0xb39c('0x32')]=_0xd1136f[_0xb39c('0x32')][_0xb39c('0x34')]?_0xd1136f[_0xb39c('0x32')]:_0x53347e['model'];if(_0x263544[_0xb39c('0x2f')][_0xb39c('0x43')]){_0xd1136f['include']=[{'all':!![]}];}_0xd1136f=_['merge']({},_0xd1136f,_0x263544[_0xb39c('0x44')]);return db['FreshsalesField']['find'](_0xd1136f)[_0xb39c('0x23')](handleEntityNotFound(_0x38359d,null))[_0xb39c('0x23')](respondWithResult(_0x38359d,null))[_0xb39c('0x40')](handleError(_0x38359d,null));};exports[_0xb39c('0x45')]=function(_0x3dff16,_0x2af6ec){return db[_0xb39c('0x2a')][_0xb39c('0x45')](_0x3dff16[_0xb39c('0x46')],{})[_0xb39c('0x23')](respondWithResult(_0x2af6ec,0xc9))['catch'](handleError(_0x2af6ec,null));};exports[_0xb39c('0x22')]=function(_0x7e9750,_0xe329bf){if(_0x7e9750[_0xb39c('0x46')]['id']){delete _0x7e9750[_0xb39c('0x46')]['id'];}return db[_0xb39c('0x2a')][_0xb39c('0x47')]({'where':{'id':_0x7e9750[_0xb39c('0x42')]['id']}})[_0xb39c('0x23')](handleEntityNotFound(_0xe329bf,null))[_0xb39c('0x23')](saveUpdates(_0x7e9750[_0xb39c('0x46')],null))[_0xb39c('0x23')](respondWithResult(_0xe329bf,null))[_0xb39c('0x40')](handleError(_0xe329bf,null));};exports[_0xb39c('0x24')]=function(_0x17ad13,_0x44b825){return db['FreshsalesField'][_0xb39c('0x47')]({'where':{'id':_0x17ad13[_0xb39c('0x42')]['id']}})[_0xb39c('0x23')](handleEntityNotFound(_0x44b825,null))[_0xb39c('0x23')](removeEntity(_0x44b825,null))[_0xb39c('0x40')](handleError(_0x44b825,null));};