e2ba26e8a52aa0c6318cb815b92e9cd3160313f7
[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 _0x5f06=['status','end','json','offset','undefined','limit','count','set','apply','update','then','destroy','error','stack','name','send','index','map','FreshsalesField','fieldName','type','key','model','query','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','filter','merge','options','include','rows','catch','show','keys','rawAttributes','includeAll','find','create','body','params','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','path','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb'];(function(_0x2828b3,_0x2bb499){var _0x3ddbce=function(_0x424ced){while(--_0x424ced){_0x2828b3['push'](_0x2828b3['shift']());}};_0x3ddbce(++_0x2bb499);}(_0x5f06,0x193));var _0x65f0=function(_0x231421,_0x576cd2){_0x231421=_0x231421-0x0;var _0x5b4a53=_0x5f06[_0x231421];return _0x5b4a53;};'use strict';var emlformat=require(_0x65f0('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x65f0('0x1'));var rp=require(_0x65f0('0x2'));var moment=require(_0x65f0('0x3'));var BPromise=require(_0x65f0('0x4'));var Mustache=require(_0x65f0('0x5'));var util=require('util');var path=require(_0x65f0('0x6'));var sox=require('sox');var csv=require(_0x65f0('0x7'));var ejs=require(_0x65f0('0x8'));var fs=require('fs');var fs_extra=require(_0x65f0('0x9'));var _=require(_0x65f0('0xa'));var squel=require(_0x65f0('0xb'));var crypto=require(_0x65f0('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x65f0('0xd'));var toCsv=require('to-csv');var querystring=require(_0x65f0('0xe'));var Papa=require(_0x65f0('0xf'));var Redis=require('ioredis');var authService=require(_0x65f0('0x10'));var qs=require(_0x65f0('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x65f0('0x12'));var logger=require('../../config/logger')('api');var utils=require(_0x65f0('0x13'));var config=require(_0x65f0('0x14'));var licenseUtil=require(_0x65f0('0x15'));var db=require(_0x65f0('0x16'))['db'];function respondWithStatusCode(_0x275b8b,_0x17e5a3){_0x17e5a3=_0x17e5a3||0xcc;return function(_0x444ef0){if(_0x444ef0){return _0x275b8b['sendStatus'](_0x17e5a3);}return _0x275b8b[_0x65f0('0x17')](_0x17e5a3)[_0x65f0('0x18')]();};}function respondWithResult(_0x131608,_0xd02844){_0xd02844=_0xd02844||0xc8;return function(_0x3f0e2e){if(_0x3f0e2e){return _0x131608['status'](_0xd02844)[_0x65f0('0x19')](_0x3f0e2e);}};}function respondWithFilteredResult(_0x44dd1c,_0x7d52bd){return function(_0x25c9fd){if(_0x25c9fd){var _0x5ccf6e=typeof _0x7d52bd[_0x65f0('0x1a')]===_0x65f0('0x1b')&&typeof _0x7d52bd[_0x65f0('0x1c')]===_0x65f0('0x1b');var _0x77b1b9=_0x25c9fd[_0x65f0('0x1d')];var _0x1caab8=_0x5ccf6e?0x0:_0x7d52bd[_0x65f0('0x1a')];var _0x25f64c=_0x5ccf6e?_0x25c9fd['count']:_0x7d52bd[_0x65f0('0x1a')]+_0x7d52bd['limit'];var _0x18c747;if(_0x25f64c>=_0x77b1b9){_0x25f64c=_0x77b1b9;_0x18c747=0xc8;}else{_0x18c747=0xce;}_0x44dd1c[_0x65f0('0x17')](_0x18c747);return _0x44dd1c[_0x65f0('0x1e')]('Content-Range',_0x1caab8+'-'+_0x25f64c+'/'+_0x77b1b9)[_0x65f0('0x19')](_0x25c9fd);}return null;};}function patchUpdates(_0x7094e4){return function(_0x1c2f94){try{jsonpatch[_0x65f0('0x1f')](_0x1c2f94,_0x7094e4,!![]);}catch(_0x709d82){return BPromise['reject'](_0x709d82);}return _0x1c2f94['save']();};}function saveUpdates(_0x43eab6,_0x1cfd5c){return function(_0x433534){if(_0x433534){return _0x433534[_0x65f0('0x20')](_0x43eab6)[_0x65f0('0x21')](function(_0x225268){return _0x225268;});}return null;};}function removeEntity(_0x831773,_0x1821d6){return function(_0x3f7a25){if(_0x3f7a25){return _0x3f7a25[_0x65f0('0x22')]()[_0x65f0('0x21')](function(){_0x831773['status'](0xcc)[_0x65f0('0x18')]();});}};}function handleEntityNotFound(_0x294223,_0xf5f9f6){return function(_0x319629){if(!_0x319629){_0x294223['sendStatus'](0x194);}return _0x319629;};}function handleError(_0x225d39,_0x3fc491){_0x3fc491=_0x3fc491||0x1f4;return function(_0x7d4b31){logger[_0x65f0('0x23')](_0x7d4b31[_0x65f0('0x24')]);if(_0x7d4b31[_0x65f0('0x25')]){delete _0x7d4b31[_0x65f0('0x25')];}_0x225d39[_0x65f0('0x17')](_0x3fc491)[_0x65f0('0x26')](_0x7d4b31);};}exports[_0x65f0('0x27')]=function(_0xd2e3a9,_0x181143){var _0x3c5c01={},_0x35d48c={},_0x37d287={'count':0x0,'rows':[]};var _0x279a9d=_[_0x65f0('0x28')](db[_0x65f0('0x29')]['rawAttributes'],function(_0x40587d){return{'name':_0x40587d[_0x65f0('0x2a')],'type':_0x40587d[_0x65f0('0x2b')][_0x65f0('0x2c')]};});_0x35d48c[_0x65f0('0x2d')]=_[_0x65f0('0x28')](_0x279a9d,_0x65f0('0x25'));_0x35d48c[_0x65f0('0x2e')]=_['keys'](_0xd2e3a9['query']);_0x35d48c['filters']=_[_0x65f0('0x2f')](_0x35d48c[_0x65f0('0x2d')],_0x35d48c['query']);_0x3c5c01[_0x65f0('0x30')]=_[_0x65f0('0x2f')](_0x35d48c[_0x65f0('0x2d')],qs['fields'](_0xd2e3a9[_0x65f0('0x2e')][_0x65f0('0x31')]));_0x3c5c01[_0x65f0('0x30')]=_0x3c5c01[_0x65f0('0x30')][_0x65f0('0x32')]?_0x3c5c01[_0x65f0('0x30')]:_0x35d48c[_0x65f0('0x2d')];if(!_0xd2e3a9['query'][_0x65f0('0x33')](_0x65f0('0x34'))){_0x3c5c01['limit']=qs[_0x65f0('0x1c')](_0xd2e3a9[_0x65f0('0x2e')][_0x65f0('0x1c')]);_0x3c5c01[_0x65f0('0x1a')]=qs[_0x65f0('0x1a')](_0xd2e3a9[_0x65f0('0x2e')][_0x65f0('0x1a')]);}_0x3c5c01[_0x65f0('0x35')]=qs[_0x65f0('0x36')](_0xd2e3a9[_0x65f0('0x2e')][_0x65f0('0x36')]);_0x3c5c01[_0x65f0('0x37')]=qs[_0x65f0('0x38')](_['pick'](_0xd2e3a9['query'],_0x35d48c[_0x65f0('0x38')]),_0x279a9d);if(_0xd2e3a9[_0x65f0('0x2e')][_0x65f0('0x39')]){_0x3c5c01[_0x65f0('0x37')]=_[_0x65f0('0x3a')](_0x3c5c01[_0x65f0('0x37')],{'$or':_[_0x65f0('0x28')](_0x279a9d,function(_0x8e699){if(_0x8e699[_0x65f0('0x2b')]!=='VIRTUAL'){var _0x370ded={};_0x370ded[_0x8e699[_0x65f0('0x25')]]={'$like':'%'+_0xd2e3a9[_0x65f0('0x2e')][_0x65f0('0x39')]+'%'};return _0x370ded;}})});}_0x3c5c01=_['merge']({},_0x3c5c01,_0xd2e3a9[_0x65f0('0x3b')]);var _0x3e8f3f={'where':_0x3c5c01[_0x65f0('0x37')]};return db[_0x65f0('0x29')][_0x65f0('0x1d')](_0x3e8f3f)[_0x65f0('0x21')](function(_0x3f682b){_0x37d287['count']=_0x3f682b;if(_0xd2e3a9[_0x65f0('0x2e')]['includeAll']){_0x3c5c01[_0x65f0('0x3c')]=[{'all':!![]}];}return db[_0x65f0('0x29')]['findAll'](_0x3c5c01);})[_0x65f0('0x21')](function(_0x3575b7){_0x37d287[_0x65f0('0x3d')]=_0x3575b7;return _0x37d287;})['then'](respondWithFilteredResult(_0x181143,_0x3c5c01))[_0x65f0('0x3e')](handleError(_0x181143,null));};exports[_0x65f0('0x3f')]=function(_0x14de05,_0x304a86){var _0x2f9e0b={'raw':!![],'where':{'id':_0x14de05['params']['id']}},_0x41ca50={};_0x41ca50[_0x65f0('0x2d')]=_[_0x65f0('0x40')](db[_0x65f0('0x29')][_0x65f0('0x41')]);_0x41ca50[_0x65f0('0x2e')]=_[_0x65f0('0x40')](_0x14de05['query']);_0x41ca50['filters']=_[_0x65f0('0x2f')](_0x41ca50[_0x65f0('0x2d')],_0x41ca50[_0x65f0('0x2e')]);_0x2f9e0b['attributes']=_[_0x65f0('0x2f')](_0x41ca50[_0x65f0('0x2d')],qs[_0x65f0('0x31')](_0x14de05['query'][_0x65f0('0x31')]));_0x2f9e0b['attributes']=_0x2f9e0b[_0x65f0('0x30')][_0x65f0('0x32')]?_0x2f9e0b[_0x65f0('0x30')]:_0x41ca50[_0x65f0('0x2d')];if(_0x14de05[_0x65f0('0x2e')][_0x65f0('0x42')]){_0x2f9e0b[_0x65f0('0x3c')]=[{'all':!![]}];}_0x2f9e0b=_[_0x65f0('0x3a')]({},_0x2f9e0b,_0x14de05['options']);return db[_0x65f0('0x29')][_0x65f0('0x43')](_0x2f9e0b)[_0x65f0('0x21')](handleEntityNotFound(_0x304a86,null))[_0x65f0('0x21')](respondWithResult(_0x304a86,null))['catch'](handleError(_0x304a86,null));};exports[_0x65f0('0x44')]=function(_0x3ebb62,_0x3c84b7){return db['FreshsalesField']['create'](_0x3ebb62[_0x65f0('0x45')],{})['then'](respondWithResult(_0x3c84b7,0xc9))['catch'](handleError(_0x3c84b7,null));};exports[_0x65f0('0x20')]=function(_0x4cbd52,_0x59d246){if(_0x4cbd52[_0x65f0('0x45')]['id']){delete _0x4cbd52[_0x65f0('0x45')]['id'];}return db[_0x65f0('0x29')]['find']({'where':{'id':_0x4cbd52['params']['id']}})[_0x65f0('0x21')](handleEntityNotFound(_0x59d246,null))[_0x65f0('0x21')](saveUpdates(_0x4cbd52[_0x65f0('0x45')],null))[_0x65f0('0x21')](respondWithResult(_0x59d246,null))[_0x65f0('0x3e')](handleError(_0x59d246,null));};exports['destroy']=function(_0x30b8b3,_0x353d5d){return db[_0x65f0('0x29')][_0x65f0('0x43')]({'where':{'id':_0x30b8b3[_0x65f0('0x46')]['id']}})[_0x65f0('0x21')](handleEntityNotFound(_0x353d5d,null))[_0x65f0('0x21')](removeEntity(_0x353d5d,null))[_0x65f0('0x3e')](handleError(_0x353d5d,null));};