89612d87d069ad46acd4e7ebf4980c7485d46699
[motion2.git] / server / api / intZohoField / intZohoField.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 _0x16f0=['rows','catch','show','params','rawAttributes','fields','options','create','update','body','find','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','path','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','Content-Range','apply','save','then','destroy','error','stack','name','send','index','ZohoField','type','key','model','map','query','keys','filters','intersection','attributes','length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','findAll'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0x16f0,0xa3));var _0x016f=function(_0x3d85be,_0x382b11){_0x3d85be=_0x3d85be-0x0;var _0x3fa27c=_0x16f0[_0x3d85be];return _0x3fa27c;};'use strict';var emlformat=require(_0x016f('0x0'));var rimraf=require(_0x016f('0x1'));var zipdir=require(_0x016f('0x2'));var jsonpatch=require(_0x016f('0x3'));var rp=require(_0x016f('0x4'));var moment=require(_0x016f('0x5'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require('util');var path=require(_0x016f('0x6'));var sox=require(_0x016f('0x7'));var csv=require(_0x016f('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x016f('0x9'));var _=require(_0x016f('0xa'));var squel=require(_0x016f('0xb'));var crypto=require(_0x016f('0xc'));var jsforce=require(_0x016f('0xd'));var deskjs=require(_0x016f('0xe'));var toCsv=require(_0x016f('0x8'));var querystring=require(_0x016f('0xf'));var Papa=require(_0x016f('0x10'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x016f('0x11'));var as=require(_0x016f('0x12'));var hardwareService=require(_0x016f('0x13'));var logger=require(_0x016f('0x14'))(_0x016f('0x15'));var utils=require(_0x016f('0x16'));var config=require(_0x016f('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x016f('0x18'))['db'];function respondWithStatusCode(_0x1833cd,_0xe11ac1){_0xe11ac1=_0xe11ac1||0xcc;return function(_0x5ca254){if(_0x5ca254){return _0x1833cd[_0x016f('0x19')](_0xe11ac1);}return _0x1833cd[_0x016f('0x1a')](_0xe11ac1)[_0x016f('0x1b')]();};}function respondWithResult(_0x42eb54,_0x5ae182){_0x5ae182=_0x5ae182||0xc8;return function(_0x3e08fe){if(_0x3e08fe){return _0x42eb54[_0x016f('0x1a')](_0x5ae182)[_0x016f('0x1c')](_0x3e08fe);}};}function respondWithFilteredResult(_0x153ec2,_0x1ff9eb){return function(_0x5a668d){if(_0x5a668d){var _0x1656b9=typeof _0x1ff9eb[_0x016f('0x1d')]===_0x016f('0x1e')&&typeof _0x1ff9eb[_0x016f('0x1f')]===_0x016f('0x1e');var _0x42ef2b=_0x5a668d[_0x016f('0x20')];var _0x4de5f9=_0x1656b9?0x0:_0x1ff9eb[_0x016f('0x1d')];var _0x16497f=_0x1656b9?_0x5a668d['count']:_0x1ff9eb[_0x016f('0x1d')]+_0x1ff9eb[_0x016f('0x1f')];var _0x84d4f1;if(_0x16497f>=_0x42ef2b){_0x16497f=_0x42ef2b;_0x84d4f1=0xc8;}else{_0x84d4f1=0xce;}_0x153ec2[_0x016f('0x1a')](_0x84d4f1);return _0x153ec2['set'](_0x016f('0x21'),_0x4de5f9+'-'+_0x16497f+'/'+_0x42ef2b)[_0x016f('0x1c')](_0x5a668d);}return null;};}function patchUpdates(_0x2b4707){return function(_0x391ce7){try{jsonpatch[_0x016f('0x22')](_0x391ce7,_0x2b4707,!![]);}catch(_0x113c31){return BPromise['reject'](_0x113c31);}return _0x391ce7[_0x016f('0x23')]();};}function saveUpdates(_0x4196b7,_0x42f5b4){return function(_0x1352dd){if(_0x1352dd){return _0x1352dd['update'](_0x4196b7)[_0x016f('0x24')](function(_0x14b69c){return _0x14b69c;});}return null;};}function removeEntity(_0x4da27b,_0x1ec2a6){return function(_0x167a09){if(_0x167a09){return _0x167a09[_0x016f('0x25')]()[_0x016f('0x24')](function(){_0x4da27b['status'](0xcc)[_0x016f('0x1b')]();});}};}function handleEntityNotFound(_0xf0636,_0x534aa3){return function(_0x19aff2){if(!_0x19aff2){_0xf0636[_0x016f('0x19')](0x194);}return _0x19aff2;};}function handleError(_0x368c62,_0x2b654f){_0x2b654f=_0x2b654f||0x1f4;return function(_0x33a53a){logger[_0x016f('0x26')](_0x33a53a[_0x016f('0x27')]);if(_0x33a53a[_0x016f('0x28')]){delete _0x33a53a[_0x016f('0x28')];}_0x368c62[_0x016f('0x1a')](_0x2b654f)[_0x016f('0x29')](_0x33a53a);};}exports[_0x016f('0x2a')]=function(_0x407125,_0x23109c){var _0x454c85={},_0x24434d={},_0x2f04fd={'count':0x0,'rows':[]};var _0x44f2c3=_['map'](db[_0x016f('0x2b')]['rawAttributes'],function(_0x363dac){return{'name':_0x363dac['fieldName'],'type':_0x363dac[_0x016f('0x2c')][_0x016f('0x2d')]};});_0x24434d[_0x016f('0x2e')]=_[_0x016f('0x2f')](_0x44f2c3,_0x016f('0x28'));_0x24434d[_0x016f('0x30')]=_[_0x016f('0x31')](_0x407125[_0x016f('0x30')]);_0x24434d[_0x016f('0x32')]=_[_0x016f('0x33')](_0x24434d[_0x016f('0x2e')],_0x24434d[_0x016f('0x30')]);_0x454c85['attributes']=_['intersection'](_0x24434d[_0x016f('0x2e')],qs['fields'](_0x407125[_0x016f('0x30')]['fields']));_0x454c85[_0x016f('0x34')]=_0x454c85[_0x016f('0x34')][_0x016f('0x35')]?_0x454c85[_0x016f('0x34')]:_0x24434d[_0x016f('0x2e')];if(!_0x407125[_0x016f('0x30')]['hasOwnProperty'](_0x016f('0x36'))){_0x454c85[_0x016f('0x1f')]=qs[_0x016f('0x1f')](_0x407125[_0x016f('0x30')][_0x016f('0x1f')]);_0x454c85[_0x016f('0x1d')]=qs[_0x016f('0x1d')](_0x407125[_0x016f('0x30')][_0x016f('0x1d')]);}_0x454c85[_0x016f('0x37')]=qs['sort'](_0x407125[_0x016f('0x30')][_0x016f('0x38')]);_0x454c85[_0x016f('0x39')]=qs[_0x016f('0x32')](_[_0x016f('0x3a')](_0x407125['query'],_0x24434d[_0x016f('0x32')]),_0x44f2c3);if(_0x407125[_0x016f('0x30')][_0x016f('0x3b')]){_0x454c85[_0x016f('0x39')]=_[_0x016f('0x3c')](_0x454c85[_0x016f('0x39')],{'$or':_[_0x016f('0x2f')](_0x44f2c3,function(_0x2701ab){if(_0x2701ab[_0x016f('0x2c')]!==_0x016f('0x3d')){var _0x2833e0={};_0x2833e0[_0x2701ab[_0x016f('0x28')]]={'$like':'%'+_0x407125[_0x016f('0x30')][_0x016f('0x3b')]+'%'};return _0x2833e0;}})});}_0x454c85=_['merge']({},_0x454c85,_0x407125['options']);var _0x31b42c={'where':_0x454c85[_0x016f('0x39')]};return db[_0x016f('0x2b')]['count'](_0x31b42c)['then'](function(_0x4bd180){_0x2f04fd[_0x016f('0x20')]=_0x4bd180;if(_0x407125[_0x016f('0x30')][_0x016f('0x3e')]){_0x454c85[_0x016f('0x3f')]=[{'all':!![]}];}return db[_0x016f('0x2b')][_0x016f('0x40')](_0x454c85);})[_0x016f('0x24')](function(_0x41ce27){_0x2f04fd[_0x016f('0x41')]=_0x41ce27;return _0x2f04fd;})[_0x016f('0x24')](respondWithFilteredResult(_0x23109c,_0x454c85))[_0x016f('0x42')](handleError(_0x23109c,null));};exports[_0x016f('0x43')]=function(_0x128fe1,_0x246e00){var _0x5eec75={'raw':!![],'where':{'id':_0x128fe1[_0x016f('0x44')]['id']}},_0x180a48={};_0x180a48['model']=_[_0x016f('0x31')](db[_0x016f('0x2b')][_0x016f('0x45')]);_0x180a48[_0x016f('0x30')]=_['keys'](_0x128fe1['query']);_0x180a48[_0x016f('0x32')]=_['intersection'](_0x180a48[_0x016f('0x2e')],_0x180a48[_0x016f('0x30')]);_0x5eec75['attributes']=_['intersection'](_0x180a48[_0x016f('0x2e')],qs[_0x016f('0x46')](_0x128fe1[_0x016f('0x30')]['fields']));_0x5eec75[_0x016f('0x34')]=_0x5eec75[_0x016f('0x34')][_0x016f('0x35')]?_0x5eec75[_0x016f('0x34')]:_0x180a48[_0x016f('0x2e')];if(_0x128fe1[_0x016f('0x30')][_0x016f('0x3e')]){_0x5eec75[_0x016f('0x3f')]=[{'all':!![]}];}_0x5eec75=_[_0x016f('0x3c')]({},_0x5eec75,_0x128fe1[_0x016f('0x47')]);return db[_0x016f('0x2b')]['find'](_0x5eec75)[_0x016f('0x24')](handleEntityNotFound(_0x246e00,null))['then'](respondWithResult(_0x246e00,null))[_0x016f('0x42')](handleError(_0x246e00,null));};exports[_0x016f('0x48')]=function(_0x4f6f73,_0x33fac3){return db['ZohoField']['create'](_0x4f6f73['body'],{})[_0x016f('0x24')](respondWithResult(_0x33fac3,0xc9))[_0x016f('0x42')](handleError(_0x33fac3,null));};exports[_0x016f('0x49')]=function(_0x41b785,_0x71b31b){if(_0x41b785[_0x016f('0x4a')]['id']){delete _0x41b785[_0x016f('0x4a')]['id'];}return db['ZohoField'][_0x016f('0x4b')]({'where':{'id':_0x41b785[_0x016f('0x44')]['id']}})[_0x016f('0x24')](handleEntityNotFound(_0x71b31b,null))['then'](saveUpdates(_0x41b785[_0x016f('0x4a')],null))['then'](respondWithResult(_0x71b31b,null))[_0x016f('0x42')](handleError(_0x71b31b,null));};exports['destroy']=function(_0x2c99df,_0x40e636){return db[_0x016f('0x2b')]['find']({'where':{'id':_0x2c99df[_0x016f('0x44')]['id']}})[_0x016f('0x24')](handleEntityNotFound(_0x40e636,null))[_0x016f('0x24')](removeEntity(_0x40e636,null))['catch'](handleError(_0x40e636,null));};