76349f2b60a80267d2b2baa120133bc6bf922895
[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 _0xf631=['stack','name','send','map','FreshsalesField','key','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','limit','offset','order','sort','where','pick','filter','type','VIRTUAL','includeAll','rows','catch','show','params','keys','rawAttributes','include','merge','create','body','find','eml-format','rimraf','request-promise','bluebird','mustache','util','to-csv','ejs','lodash','squel','jsforce','desk.js','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','sendStatus','end','status','json','undefined','count','Content-Range','apply','reject','then','destroy','error'];(function(_0x47d6dc,_0xc036cc){var _0x1a1c93=function(_0x18ec96){while(--_0x18ec96){_0x47d6dc['push'](_0x47d6dc['shift']());}};_0x1a1c93(++_0xc036cc);}(_0xf631,0xaa));var _0x1f63=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xf631[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0x1f63('0x0'));var rimraf=require(_0x1f63('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x1f63('0x2'));var moment=require('moment');var BPromise=require(_0x1f63('0x3'));var Mustache=require(_0x1f63('0x4'));var util=require(_0x1f63('0x5'));var path=require('path');var sox=require('sox');var csv=require(_0x1f63('0x6'));var ejs=require(_0x1f63('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x1f63('0x8'));var squel=require(_0x1f63('0x9'));var crypto=require('crypto');var jsforce=require(_0x1f63('0xa'));var deskjs=require(_0x1f63('0xb'));var toCsv=require(_0x1f63('0x6'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x1f63('0xc'));var qs=require('../../components/parsers/qs');var as=require(_0x1f63('0xd'));var hardwareService=require(_0x1f63('0xe'));var logger=require(_0x1f63('0xf'))(_0x1f63('0x10'));var utils=require(_0x1f63('0x11'));var config=require(_0x1f63('0x12'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x263014,_0x6a520d){_0x6a520d=_0x6a520d||0xcc;return function(_0x4ee397){if(_0x4ee397){return _0x263014[_0x1f63('0x13')](_0x6a520d);}return _0x263014['status'](_0x6a520d)[_0x1f63('0x14')]();};}function respondWithResult(_0x48d81d,_0x2eca7a){_0x2eca7a=_0x2eca7a||0xc8;return function(_0x72470){if(_0x72470){return _0x48d81d[_0x1f63('0x15')](_0x2eca7a)[_0x1f63('0x16')](_0x72470);}};}function respondWithFilteredResult(_0x599302,_0x510fdf){return function(_0x4f97ae){if(_0x4f97ae){var _0x336a6b=typeof _0x510fdf['offset']===_0x1f63('0x17')&&typeof _0x510fdf['limit']===_0x1f63('0x17');var _0x2bb874=_0x4f97ae[_0x1f63('0x18')];var _0x5ca636=_0x336a6b?0x0:_0x510fdf['offset'];var _0x128a29=_0x336a6b?_0x4f97ae[_0x1f63('0x18')]:_0x510fdf['offset']+_0x510fdf['limit'];var _0x62d115;if(_0x128a29>=_0x2bb874){_0x128a29=_0x2bb874;_0x62d115=0xc8;}else{_0x62d115=0xce;}_0x599302['status'](_0x62d115);return _0x599302['set'](_0x1f63('0x19'),_0x5ca636+'-'+_0x128a29+'/'+_0x2bb874)[_0x1f63('0x16')](_0x4f97ae);}return null;};}function patchUpdates(_0x89177a){return function(_0x41dd85){try{jsonpatch[_0x1f63('0x1a')](_0x41dd85,_0x89177a,!![]);}catch(_0x1acdbe){return BPromise[_0x1f63('0x1b')](_0x1acdbe);}return _0x41dd85['save']();};}function saveUpdates(_0x33cdba,_0x2aef7a){return function(_0x314b59){if(_0x314b59){return _0x314b59['update'](_0x33cdba)[_0x1f63('0x1c')](function(_0x3a12f5){return _0x3a12f5;});}return null;};}function removeEntity(_0x5639a4,_0x4eb692){return function(_0xb28f6f){if(_0xb28f6f){return _0xb28f6f[_0x1f63('0x1d')]()[_0x1f63('0x1c')](function(){_0x5639a4[_0x1f63('0x15')](0xcc)[_0x1f63('0x14')]();});}};}function handleEntityNotFound(_0x5bca0e,_0x2a02d0){return function(_0x202fdd){if(!_0x202fdd){_0x5bca0e['sendStatus'](0x194);}return _0x202fdd;};}function handleError(_0xb6abfc,_0xe305ef){_0xe305ef=_0xe305ef||0x1f4;return function(_0x1d8d22){logger[_0x1f63('0x1e')](_0x1d8d22[_0x1f63('0x1f')]);if(_0x1d8d22[_0x1f63('0x20')]){delete _0x1d8d22[_0x1f63('0x20')];}_0xb6abfc[_0x1f63('0x15')](_0xe305ef)[_0x1f63('0x21')](_0x1d8d22);};}exports['index']=function(_0x186b4b,_0x20f800){var _0x56eada={},_0xc594b7={},_0x1df173={'count':0x0,'rows':[]};var _0x3ffc4b=_[_0x1f63('0x22')](db[_0x1f63('0x23')]['rawAttributes'],function(_0x5f1528){return{'name':_0x5f1528['fieldName'],'type':_0x5f1528['type'][_0x1f63('0x24')]};});_0xc594b7[_0x1f63('0x25')]=_[_0x1f63('0x22')](_0x3ffc4b,_0x1f63('0x20'));_0xc594b7[_0x1f63('0x26')]=_['keys'](_0x186b4b['query']);_0xc594b7[_0x1f63('0x27')]=_['intersection'](_0xc594b7[_0x1f63('0x25')],_0xc594b7[_0x1f63('0x26')]);_0x56eada['attributes']=_[_0x1f63('0x28')](_0xc594b7[_0x1f63('0x25')],qs[_0x1f63('0x29')](_0x186b4b[_0x1f63('0x26')][_0x1f63('0x29')]));_0x56eada[_0x1f63('0x2a')]=_0x56eada[_0x1f63('0x2a')][_0x1f63('0x2b')]?_0x56eada[_0x1f63('0x2a')]:_0xc594b7[_0x1f63('0x25')];if(!_0x186b4b[_0x1f63('0x26')][_0x1f63('0x2c')](_0x1f63('0x2d'))){_0x56eada[_0x1f63('0x2e')]=qs['limit'](_0x186b4b[_0x1f63('0x26')]['limit']);_0x56eada[_0x1f63('0x2f')]=qs[_0x1f63('0x2f')](_0x186b4b[_0x1f63('0x26')]['offset']);}_0x56eada[_0x1f63('0x30')]=qs[_0x1f63('0x31')](_0x186b4b[_0x1f63('0x26')][_0x1f63('0x31')]);_0x56eada[_0x1f63('0x32')]=qs[_0x1f63('0x27')](_[_0x1f63('0x33')](_0x186b4b[_0x1f63('0x26')],_0xc594b7[_0x1f63('0x27')]),_0x3ffc4b);if(_0x186b4b[_0x1f63('0x26')][_0x1f63('0x34')]){_0x56eada[_0x1f63('0x32')]=_['merge'](_0x56eada[_0x1f63('0x32')],{'$or':_[_0x1f63('0x22')](_0x3ffc4b,function(_0x1ea8be){if(_0x1ea8be[_0x1f63('0x35')]!==_0x1f63('0x36')){var _0x7b89a5={};_0x7b89a5[_0x1ea8be[_0x1f63('0x20')]]={'$like':'%'+_0x186b4b[_0x1f63('0x26')][_0x1f63('0x34')]+'%'};return _0x7b89a5;}})});}_0x56eada=_['merge']({},_0x56eada,_0x186b4b['options']);var _0x128368={'where':_0x56eada[_0x1f63('0x32')]};return db[_0x1f63('0x23')][_0x1f63('0x18')](_0x128368)[_0x1f63('0x1c')](function(_0x205511){_0x1df173[_0x1f63('0x18')]=_0x205511;if(_0x186b4b[_0x1f63('0x26')][_0x1f63('0x37')]){_0x56eada['include']=[{'all':!![]}];}return db[_0x1f63('0x23')]['findAll'](_0x56eada);})[_0x1f63('0x1c')](function(_0x4e7314){_0x1df173[_0x1f63('0x38')]=_0x4e7314;return _0x1df173;})['then'](respondWithFilteredResult(_0x20f800,_0x56eada))[_0x1f63('0x39')](handleError(_0x20f800,null));};exports[_0x1f63('0x3a')]=function(_0x98df3a,_0x3d926e){var _0x3f24d6={'raw':!![],'where':{'id':_0x98df3a[_0x1f63('0x3b')]['id']}},_0x5eeae8={};_0x5eeae8[_0x1f63('0x25')]=_[_0x1f63('0x3c')](db[_0x1f63('0x23')][_0x1f63('0x3d')]);_0x5eeae8[_0x1f63('0x26')]=_['keys'](_0x98df3a[_0x1f63('0x26')]);_0x5eeae8[_0x1f63('0x27')]=_[_0x1f63('0x28')](_0x5eeae8['model'],_0x5eeae8[_0x1f63('0x26')]);_0x3f24d6[_0x1f63('0x2a')]=_[_0x1f63('0x28')](_0x5eeae8[_0x1f63('0x25')],qs[_0x1f63('0x29')](_0x98df3a['query'][_0x1f63('0x29')]));_0x3f24d6['attributes']=_0x3f24d6[_0x1f63('0x2a')][_0x1f63('0x2b')]?_0x3f24d6[_0x1f63('0x2a')]:_0x5eeae8[_0x1f63('0x25')];if(_0x98df3a[_0x1f63('0x26')]['includeAll']){_0x3f24d6[_0x1f63('0x3e')]=[{'all':!![]}];}_0x3f24d6=_[_0x1f63('0x3f')]({},_0x3f24d6,_0x98df3a['options']);return db['FreshsalesField']['find'](_0x3f24d6)[_0x1f63('0x1c')](handleEntityNotFound(_0x3d926e,null))[_0x1f63('0x1c')](respondWithResult(_0x3d926e,null))[_0x1f63('0x39')](handleError(_0x3d926e,null));};exports[_0x1f63('0x40')]=function(_0x22f0bc,_0xa15679){return db[_0x1f63('0x23')][_0x1f63('0x40')](_0x22f0bc['body'],{})[_0x1f63('0x1c')](respondWithResult(_0xa15679,0xc9))['catch'](handleError(_0xa15679,null));};exports['update']=function(_0x4e3d4d,_0x14fdf0){if(_0x4e3d4d['body']['id']){delete _0x4e3d4d[_0x1f63('0x41')]['id'];}return db['FreshsalesField'][_0x1f63('0x42')]({'where':{'id':_0x4e3d4d[_0x1f63('0x3b')]['id']}})[_0x1f63('0x1c')](handleEntityNotFound(_0x14fdf0,null))[_0x1f63('0x1c')](saveUpdates(_0x4e3d4d[_0x1f63('0x41')],null))[_0x1f63('0x1c')](respondWithResult(_0x14fdf0,null))[_0x1f63('0x39')](handleError(_0x14fdf0,null));};exports[_0x1f63('0x1d')]=function(_0x41e4bd,_0x3dd843){return db['FreshsalesField'][_0x1f63('0x42')]({'where':{'id':_0x41e4bd[_0x1f63('0x3b')]['id']}})[_0x1f63('0x1c')](handleEntityNotFound(_0x3dd843,null))[_0x1f63('0x1c')](removeEntity(_0x3dd843,null))[_0x1f63('0x39')](handleError(_0x3dd843,null));};