60027cbbd5cc287c0a93e702960e8d55925d37ba
[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 _0xf580=['querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','reject','save','update','destroy','then','error','stack','name','map','FreshsalesField','fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','filter','include','findAll','rows','catch','show','params','includeAll','create','body','html-pdf','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js'];(function(_0x2369ce,_0x5e14c8){var _0x3a442f=function(_0x3127ee){while(--_0x3127ee){_0x2369ce['push'](_0x2369ce['shift']());}};_0x3a442f(++_0x5e14c8);}(_0xf580,0x7f));var _0x0f58=function(_0x3ae71c,_0x1e4157){_0x3ae71c=_0x3ae71c-0x0;var _0x2d97e5=_0xf580[_0x3ae71c];return _0x2d97e5;};'use strict';var pdf=require(_0x0f58('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x0f58('0x1'));var zipdir=require(_0x0f58('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x0f58('0x3'));var moment=require(_0x0f58('0x4'));var BPromise=require(_0x0f58('0x5'));var Mustache=require(_0x0f58('0x6'));var util=require(_0x0f58('0x7'));var path=require('path');var sox=require('sox');var csv=require(_0x0f58('0x8'));var ejs=require(_0x0f58('0x9'));var fs=require('fs');var _=require(_0x0f58('0xa'));var squel=require(_0x0f58('0xb'));var crypto=require(_0x0f58('0xc'));var jsforce=require(_0x0f58('0xd'));var deskjs=require(_0x0f58('0xe'));var toCsv=require(_0x0f58('0x8'));var querystring=require(_0x0f58('0xf'));var Papa=require(_0x0f58('0x10'));var Redis=require(_0x0f58('0x11'));var authService=require('../../components/auth/service');var qs=require(_0x0f58('0x12'));var as=require(_0x0f58('0x13'));var hardwareService=require(_0x0f58('0x14'));var logger=require('../../config/logger')(_0x0f58('0x15'));var utils=require('../../config/utils');var config=require(_0x0f58('0x16'));var licenseUtil=require(_0x0f58('0x17'));var db=require(_0x0f58('0x18'))['db'];function respondWithStatusCode(_0x5a9aa6,_0x430f34){_0x430f34=_0x430f34||0xcc;return function(_0x134f24){if(_0x134f24){return _0x5a9aa6[_0x0f58('0x19')](_0x430f34);}return _0x5a9aa6[_0x0f58('0x1a')](_0x430f34)[_0x0f58('0x1b')]();};}function respondWithResult(_0x3f7727,_0x16c36a){_0x16c36a=_0x16c36a||0xc8;return function(_0x532a0b){if(_0x532a0b){return _0x3f7727[_0x0f58('0x1a')](_0x16c36a)[_0x0f58('0x1c')](_0x532a0b);}};}function respondWithFilteredResult(_0x20aedf,_0x4bcf86){return function(_0x5e4611){if(_0x5e4611){var _0x187e3e=_0x5e4611[_0x0f58('0x1d')],_0x59d5ae=_0x4bcf86[_0x0f58('0x1e')],_0x4039b5=_0x4bcf86[_0x0f58('0x1e')]+_0x4bcf86[_0x0f58('0x1f')],_0x4a040a;if(_0x4039b5>=_0x187e3e){_0x4039b5=_0x187e3e;_0x4a040a=0xc8;}else{_0x4a040a=0xce;}_0x20aedf[_0x0f58('0x1a')](_0x4a040a);return _0x20aedf[_0x0f58('0x20')](_0x0f58('0x21'),_0x59d5ae+'-'+_0x4039b5+'/'+_0x187e3e)[_0x0f58('0x1c')](_0x5e4611);}return null;};}function patchUpdates(_0x4676bc){return function(_0x5e2b1b){try{jsonpatch['apply'](_0x5e2b1b,_0x4676bc,!![]);}catch(_0x3790be){return BPromise[_0x0f58('0x22')](_0x3790be);}return _0x5e2b1b[_0x0f58('0x23')]();};}function saveUpdates(_0x418f7f,_0x52cd1c){return function(_0x151a4b){if(_0x151a4b){return _0x151a4b[_0x0f58('0x24')](_0x418f7f)['then'](function(_0x35d07){return _0x35d07;});}return null;};}function removeEntity(_0xfe0f96,_0x21b043){return function(_0x58ed9e){if(_0x58ed9e){return _0x58ed9e[_0x0f58('0x25')]()[_0x0f58('0x26')](function(){_0xfe0f96[_0x0f58('0x1a')](0xcc)[_0x0f58('0x1b')]();});}};}function handleEntityNotFound(_0x17d999,_0x36458c){return function(_0x380f4d){if(!_0x380f4d){_0x17d999[_0x0f58('0x19')](0x194);}return _0x380f4d;};}function handleError(_0x32bae4,_0x2540a3){_0x2540a3=_0x2540a3||0x1f4;return function(_0x3aa592){logger[_0x0f58('0x27')](_0x3aa592[_0x0f58('0x28')]);if(_0x3aa592[_0x0f58('0x29')]){delete _0x3aa592['name'];}_0x32bae4[_0x0f58('0x1a')](_0x2540a3)['send'](_0x3aa592);};}exports['index']=function(_0x575ffa,_0x24085c){var _0x272d73={},_0x5069db={},_0x33d370={'count':0x0,'rows':[]};var _0x1e0f06=_[_0x0f58('0x2a')](db[_0x0f58('0x2b')]['rawAttributes'],function(_0x373f75){return{'name':_0x373f75[_0x0f58('0x2c')],'type':_0x373f75[_0x0f58('0x2d')]['key']};});_0x5069db[_0x0f58('0x2e')]=_[_0x0f58('0x2a')](_0x1e0f06,_0x0f58('0x29'));_0x5069db[_0x0f58('0x2f')]=_[_0x0f58('0x30')](_0x575ffa[_0x0f58('0x2f')]);_0x5069db[_0x0f58('0x31')]=_[_0x0f58('0x32')](_0x5069db['model'],_0x5069db[_0x0f58('0x2f')]);_0x272d73[_0x0f58('0x33')]=_[_0x0f58('0x32')](_0x5069db[_0x0f58('0x2e')],qs[_0x0f58('0x34')](_0x575ffa[_0x0f58('0x2f')]['fields']));_0x272d73[_0x0f58('0x33')]=_0x272d73['attributes'][_0x0f58('0x35')]?_0x272d73[_0x0f58('0x33')]:_0x5069db[_0x0f58('0x2e')];if(!_0x575ffa[_0x0f58('0x2f')][_0x0f58('0x36')](_0x0f58('0x37'))){_0x272d73[_0x0f58('0x1f')]=qs['limit'](_0x575ffa[_0x0f58('0x2f')][_0x0f58('0x1f')]);_0x272d73[_0x0f58('0x1e')]=qs[_0x0f58('0x1e')](_0x575ffa[_0x0f58('0x2f')][_0x0f58('0x1e')]);}_0x272d73[_0x0f58('0x38')]=qs[_0x0f58('0x39')](_0x575ffa[_0x0f58('0x2f')]['sort']);_0x272d73[_0x0f58('0x3a')]=qs[_0x0f58('0x31')](_[_0x0f58('0x3b')](_0x575ffa[_0x0f58('0x2f')],_0x5069db[_0x0f58('0x31')]),_0x1e0f06);if(_0x575ffa[_0x0f58('0x2f')]['filter']){_0x272d73['where']=_[_0x0f58('0x3c')](_0x272d73[_0x0f58('0x3a')],{'$or':_[_0x0f58('0x2a')](_0x1e0f06,function(_0x59e1f8){if(_0x59e1f8[_0x0f58('0x2d')]!=='VIRTUAL'){var _0x4897ba={};_0x4897ba[_0x59e1f8[_0x0f58('0x29')]]={'$like':'%'+_0x575ffa[_0x0f58('0x2f')][_0x0f58('0x3d')]+'%'};return _0x4897ba;}})});}_0x272d73=_['merge']({},_0x272d73,_0x575ffa['options']);var _0x389c68={'where':_0x272d73['where']};return db['FreshsalesField'][_0x0f58('0x1d')](_0x389c68)[_0x0f58('0x26')](function(_0x517ce4){_0x33d370[_0x0f58('0x1d')]=_0x517ce4;if(_0x575ffa[_0x0f58('0x2f')]['includeAll']){_0x272d73[_0x0f58('0x3e')]=[{'all':!![]}];}return db['FreshsalesField'][_0x0f58('0x3f')](_0x272d73);})[_0x0f58('0x26')](function(_0x208e83){_0x33d370[_0x0f58('0x40')]=_0x208e83;return _0x33d370;})[_0x0f58('0x26')](respondWithFilteredResult(_0x24085c,_0x272d73))[_0x0f58('0x41')](handleError(_0x24085c,null));};exports[_0x0f58('0x42')]=function(_0x4c0e9e,_0x21005f){var _0x5f39ee={'raw':!![],'where':{'id':_0x4c0e9e[_0x0f58('0x43')]['id']}},_0x379080={};_0x379080[_0x0f58('0x2e')]=_[_0x0f58('0x30')](db[_0x0f58('0x2b')]['rawAttributes']);_0x379080[_0x0f58('0x2f')]=_['keys'](_0x4c0e9e[_0x0f58('0x2f')]);_0x379080[_0x0f58('0x31')]=_[_0x0f58('0x32')](_0x379080['model'],_0x379080[_0x0f58('0x2f')]);_0x5f39ee[_0x0f58('0x33')]=_[_0x0f58('0x32')](_0x379080[_0x0f58('0x2e')],qs[_0x0f58('0x34')](_0x4c0e9e[_0x0f58('0x2f')][_0x0f58('0x34')]));_0x5f39ee[_0x0f58('0x33')]=_0x5f39ee[_0x0f58('0x33')][_0x0f58('0x35')]?_0x5f39ee[_0x0f58('0x33')]:_0x379080['model'];if(_0x4c0e9e[_0x0f58('0x2f')][_0x0f58('0x44')]){_0x5f39ee[_0x0f58('0x3e')]=[{'all':!![]}];}_0x5f39ee=_[_0x0f58('0x3c')]({},_0x5f39ee,_0x4c0e9e['options']);return db[_0x0f58('0x2b')]['find'](_0x5f39ee)[_0x0f58('0x26')](handleEntityNotFound(_0x21005f,null))['then'](respondWithResult(_0x21005f,null))['catch'](handleError(_0x21005f,null));};exports[_0x0f58('0x45')]=function(_0x3535f5,_0x5c2be5){return db['FreshsalesField'][_0x0f58('0x45')](_0x3535f5['body'],{})[_0x0f58('0x26')](respondWithResult(_0x5c2be5,0xc9))[_0x0f58('0x41')](handleError(_0x5c2be5,null));};exports[_0x0f58('0x24')]=function(_0x3245d4,_0x20f8a3){if(_0x3245d4['body']['id']){delete _0x3245d4[_0x0f58('0x46')]['id'];}return db[_0x0f58('0x2b')]['find']({'where':{'id':_0x3245d4['params']['id']}})[_0x0f58('0x26')](handleEntityNotFound(_0x20f8a3,null))[_0x0f58('0x26')](saveUpdates(_0x3245d4['body'],null))['then'](respondWithResult(_0x20f8a3,null))['catch'](handleError(_0x20f8a3,null));};exports[_0x0f58('0x25')]=function(_0x31eecb,_0x6909d){return db[_0x0f58('0x2b')]['find']({'where':{'id':_0x31eecb['params']['id']}})[_0x0f58('0x26')](handleEntityNotFound(_0x6909d,null))['then'](removeEntity(_0x6909d,null))[_0x0f58('0x41')](handleError(_0x6909d,null));};