Built motion from commit (unavailable).|2.5.6
[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 _0x43f0=['options','count','findAll','rows','params','keys','length','include','catch','create','body','find','rimraf','zip-dir','fast-json-patch','moment','bluebird','util','path','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','Content-Range','reject','save','update','then','destroy','error','name','send','map','FreshsalesField','rawAttributes','fieldName','key','model','query','filters','intersection','attributes','fields','hasOwnProperty','limit','order','sort','where','pick','filter','merge'];(function(_0x572ce1,_0xa27ca4){var _0x57e794=function(_0x101ff4){while(--_0x101ff4){_0x572ce1['push'](_0x572ce1['shift']());}};_0x57e794(++_0xa27ca4);}(_0x43f0,0x92));var _0x043f=function(_0x385212,_0x19b410){_0x385212=_0x385212-0x0;var _0x27174f=_0x43f0[_0x385212];return _0x27174f;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x043f('0x0'));var zipdir=require(_0x043f('0x1'));var jsonpatch=require(_0x043f('0x2'));var rp=require('request-promise');var moment=require(_0x043f('0x3'));var BPromise=require(_0x043f('0x4'));var Mustache=require('mustache');var util=require(_0x043f('0x5'));var path=require(_0x043f('0x6'));var sox=require('sox');var csv=require(_0x043f('0x7'));var ejs=require(_0x043f('0x8'));var fs=require('fs');var _=require(_0x043f('0x9'));var squel=require(_0x043f('0xa'));var crypto=require(_0x043f('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x043f('0xc'));var toCsv=require(_0x043f('0x7'));var querystring=require(_0x043f('0xd'));var Papa=require('papaparse');var Redis=require(_0x043f('0xe'));var authService=require(_0x043f('0xf'));var qs=require(_0x043f('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x043f('0x11'))(_0x043f('0x12'));var utils=require('../../config/utils');var config=require(_0x043f('0x13'));var licenseUtil=require(_0x043f('0x14'));var db=require(_0x043f('0x15'))['db'];function respondWithStatusCode(_0x5dbf5b,_0x2ebc37){_0x2ebc37=_0x2ebc37||0xcc;return function(_0x36a369){if(_0x36a369){return _0x5dbf5b[_0x043f('0x16')](_0x2ebc37);}return _0x5dbf5b[_0x043f('0x17')](_0x2ebc37)[_0x043f('0x18')]();};}function respondWithResult(_0x1642b3,_0x2ca1a3){_0x2ca1a3=_0x2ca1a3||0xc8;return function(_0x1cd40d){if(_0x1cd40d){return _0x1642b3[_0x043f('0x17')](_0x2ca1a3)[_0x043f('0x19')](_0x1cd40d);}};}function respondWithFilteredResult(_0x5286d1,_0x1e7b73){return function(_0xba2989){if(_0xba2989){var _0x1a4d38=_0xba2989['count'],_0x569dd9=_0x1e7b73[_0x043f('0x1a')],_0x3210b0=_0x1e7b73[_0x043f('0x1a')]+_0x1e7b73['limit'],_0x2bf02f;if(_0x3210b0>=_0x1a4d38){_0x3210b0=_0x1a4d38;_0x2bf02f=0xc8;}else{_0x2bf02f=0xce;}_0x5286d1['status'](_0x2bf02f);return _0x5286d1['set'](_0x043f('0x1b'),_0x569dd9+'-'+_0x3210b0+'/'+_0x1a4d38)[_0x043f('0x19')](_0xba2989);}return null;};}function patchUpdates(_0x2f67f5){return function(_0x2f72ae){try{jsonpatch['apply'](_0x2f72ae,_0x2f67f5,!![]);}catch(_0x48c4dd){return BPromise[_0x043f('0x1c')](_0x48c4dd);}return _0x2f72ae[_0x043f('0x1d')]();};}function saveUpdates(_0x14c046,_0x31a614){return function(_0x5b4521){if(_0x5b4521){return _0x5b4521[_0x043f('0x1e')](_0x14c046)[_0x043f('0x1f')](function(_0x9af1ca){return _0x9af1ca;});}return null;};}function removeEntity(_0x3f8f3a,_0x2ebcdb){return function(_0xc7986d){if(_0xc7986d){return _0xc7986d[_0x043f('0x20')]()[_0x043f('0x1f')](function(){_0x3f8f3a['status'](0xcc)[_0x043f('0x18')]();});}};}function handleEntityNotFound(_0x2ccfcb,_0x8e2812){return function(_0x29460c){if(!_0x29460c){_0x2ccfcb[_0x043f('0x16')](0x194);}return _0x29460c;};}function handleError(_0x164e08,_0x31e3c8){_0x31e3c8=_0x31e3c8||0x1f4;return function(_0x50c5f6){logger[_0x043f('0x21')](_0x50c5f6['stack']);if(_0x50c5f6[_0x043f('0x22')]){delete _0x50c5f6[_0x043f('0x22')];}_0x164e08['status'](_0x31e3c8)[_0x043f('0x23')](_0x50c5f6);};}exports['index']=function(_0x4bf954,_0x47d920){var _0x23a48b={},_0x31f866={},_0x15a74e={'count':0x0,'rows':[]};var _0x1b6490=_[_0x043f('0x24')](db[_0x043f('0x25')][_0x043f('0x26')],function(_0x1d4477){return{'name':_0x1d4477[_0x043f('0x27')],'type':_0x1d4477['type'][_0x043f('0x28')]};});_0x31f866[_0x043f('0x29')]=_[_0x043f('0x24')](_0x1b6490,_0x043f('0x22'));_0x31f866[_0x043f('0x2a')]=_['keys'](_0x4bf954['query']);_0x31f866[_0x043f('0x2b')]=_[_0x043f('0x2c')](_0x31f866[_0x043f('0x29')],_0x31f866[_0x043f('0x2a')]);_0x23a48b[_0x043f('0x2d')]=_[_0x043f('0x2c')](_0x31f866[_0x043f('0x29')],qs['fields'](_0x4bf954[_0x043f('0x2a')][_0x043f('0x2e')]));_0x23a48b[_0x043f('0x2d')]=_0x23a48b[_0x043f('0x2d')]['length']?_0x23a48b[_0x043f('0x2d')]:_0x31f866[_0x043f('0x29')];if(!_0x4bf954[_0x043f('0x2a')][_0x043f('0x2f')]('nolimit')){_0x23a48b[_0x043f('0x30')]=qs[_0x043f('0x30')](_0x4bf954[_0x043f('0x2a')]['limit']);_0x23a48b['offset']=qs[_0x043f('0x1a')](_0x4bf954[_0x043f('0x2a')][_0x043f('0x1a')]);}_0x23a48b[_0x043f('0x31')]=qs[_0x043f('0x32')](_0x4bf954['query'][_0x043f('0x32')]);_0x23a48b[_0x043f('0x33')]=qs['filters'](_[_0x043f('0x34')](_0x4bf954[_0x043f('0x2a')],_0x31f866[_0x043f('0x2b')]),_0x1b6490);if(_0x4bf954[_0x043f('0x2a')][_0x043f('0x35')]){_0x23a48b[_0x043f('0x33')]=_[_0x043f('0x36')](_0x23a48b[_0x043f('0x33')],{'$or':_[_0x043f('0x24')](_0x1b6490,function(_0x4f6fd9){if(_0x4f6fd9['type']!=='VIRTUAL'){var _0x45fd9a={};_0x45fd9a[_0x4f6fd9[_0x043f('0x22')]]={'$like':'%'+_0x4bf954[_0x043f('0x2a')][_0x043f('0x35')]+'%'};return _0x45fd9a;}})});}_0x23a48b=_[_0x043f('0x36')]({},_0x23a48b,_0x4bf954[_0x043f('0x37')]);var _0x11ca12={'where':_0x23a48b['where']};return db[_0x043f('0x25')][_0x043f('0x38')](_0x11ca12)[_0x043f('0x1f')](function(_0x3c787d){_0x15a74e[_0x043f('0x38')]=_0x3c787d;if(_0x4bf954[_0x043f('0x2a')]['includeAll']){_0x23a48b['include']=[{'all':!![]}];}return db[_0x043f('0x25')][_0x043f('0x39')](_0x23a48b);})[_0x043f('0x1f')](function(_0x31d3b4){_0x15a74e[_0x043f('0x3a')]=_0x31d3b4;return _0x15a74e;})[_0x043f('0x1f')](respondWithFilteredResult(_0x47d920,_0x23a48b))['catch'](handleError(_0x47d920,null));};exports['show']=function(_0x29a469,_0x22ec46){var _0x479b69={'raw':!![],'where':{'id':_0x29a469[_0x043f('0x3b')]['id']}},_0x28fefb={};_0x28fefb[_0x043f('0x29')]=_[_0x043f('0x3c')](db[_0x043f('0x25')][_0x043f('0x26')]);_0x28fefb[_0x043f('0x2a')]=_[_0x043f('0x3c')](_0x29a469[_0x043f('0x2a')]);_0x28fefb[_0x043f('0x2b')]=_[_0x043f('0x2c')](_0x28fefb['model'],_0x28fefb[_0x043f('0x2a')]);_0x479b69[_0x043f('0x2d')]=_['intersection'](_0x28fefb['model'],qs['fields'](_0x29a469[_0x043f('0x2a')]['fields']));_0x479b69[_0x043f('0x2d')]=_0x479b69[_0x043f('0x2d')][_0x043f('0x3d')]?_0x479b69['attributes']:_0x28fefb['model'];if(_0x29a469['query']['includeAll']){_0x479b69[_0x043f('0x3e')]=[{'all':!![]}];}_0x479b69=_[_0x043f('0x36')]({},_0x479b69,_0x29a469[_0x043f('0x37')]);return db[_0x043f('0x25')]['find'](_0x479b69)[_0x043f('0x1f')](handleEntityNotFound(_0x22ec46,null))['then'](respondWithResult(_0x22ec46,null))[_0x043f('0x3f')](handleError(_0x22ec46,null));};exports[_0x043f('0x40')]=function(_0x1c3676,_0xac0f1c){return db[_0x043f('0x25')][_0x043f('0x40')](_0x1c3676[_0x043f('0x41')],{})[_0x043f('0x1f')](respondWithResult(_0xac0f1c,0xc9))[_0x043f('0x3f')](handleError(_0xac0f1c,null));};exports[_0x043f('0x1e')]=function(_0x4f76c3,_0x308a32){if(_0x4f76c3[_0x043f('0x41')]['id']){delete _0x4f76c3['body']['id'];}return db[_0x043f('0x25')]['find']({'where':{'id':_0x4f76c3[_0x043f('0x3b')]['id']}})['then'](handleEntityNotFound(_0x308a32,null))[_0x043f('0x1f')](saveUpdates(_0x4f76c3[_0x043f('0x41')],null))[_0x043f('0x1f')](respondWithResult(_0x308a32,null))[_0x043f('0x3f')](handleError(_0x308a32,null));};exports[_0x043f('0x20')]=function(_0x1dd77b,_0x514bc0){return db[_0x043f('0x25')][_0x043f('0x42')]({'where':{'id':_0x1dd77b['params']['id']}})[_0x043f('0x1f')](handleEntityNotFound(_0x514bc0,null))['then'](removeEntity(_0x514bc0,null))[_0x043f('0x3f')](handleError(_0x514bc0,null));};