Built motion from commit 85328c08.|2.5.50
[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 _0x8383=['catch','keys','find','create','body','params','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','jsforce','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','status','offset','limit','undefined','count','set','Content-Range','json','reject','update','then','destroy','error','name','send','index','map','rawAttributes','fieldName','key','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','options','ZohoField','includeAll','include','findAll','rows'];(function(_0x1cd8d9,_0x4928b4){var _0x4a81e7=function(_0x146a81){while(--_0x146a81){_0x1cd8d9['push'](_0x1cd8d9['shift']());}};_0x4a81e7(++_0x4928b4);}(_0x8383,0x98));var _0x3838=function(_0x328700,_0x3e953f){_0x328700=_0x328700-0x0;var _0x54c15a=_0x8383[_0x328700];return _0x54c15a;};'use strict';var emlformat=require(_0x3838('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x3838('0x1'));var rp=require(_0x3838('0x2'));var moment=require(_0x3838('0x3'));var BPromise=require(_0x3838('0x4'));var Mustache=require(_0x3838('0x5'));var util=require(_0x3838('0x6'));var path=require(_0x3838('0x7'));var sox=require(_0x3838('0x8'));var csv=require(_0x3838('0x9'));var ejs=require(_0x3838('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x3838('0xb'));var squel=require(_0x3838('0xc'));var crypto=require('crypto');var jsforce=require(_0x3838('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x3838('0x9'));var querystring=require(_0x3838('0xe'));var Papa=require(_0x3838('0xf'));var Redis=require('ioredis');var authService=require(_0x3838('0x10'));var qs=require(_0x3838('0x11'));var as=require(_0x3838('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x3838('0x13'))(_0x3838('0x14'));var utils=require(_0x3838('0x15'));var config=require(_0x3838('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0x3838('0x17'))['db'];function respondWithStatusCode(_0x276d98,_0x21f2c0){_0x21f2c0=_0x21f2c0||0xcc;return function(_0x56e009){if(_0x56e009){return _0x276d98[_0x3838('0x18')](_0x21f2c0);}return _0x276d98['status'](_0x21f2c0)[_0x3838('0x19')]();};}function respondWithResult(_0x2cfc06,_0x104adf){_0x104adf=_0x104adf||0xc8;return function(_0x17e0c4){if(_0x17e0c4){return _0x2cfc06[_0x3838('0x1a')](_0x104adf)['json'](_0x17e0c4);}};}function respondWithFilteredResult(_0x284ec1,_0xb4bf82){return function(_0x396b2d){if(_0x396b2d){var _0x2d81b2=typeof _0xb4bf82[_0x3838('0x1b')]==='undefined'&&typeof _0xb4bf82[_0x3838('0x1c')]===_0x3838('0x1d');var _0x29e617=_0x396b2d['count'];var _0x45aa66=_0x2d81b2?0x0:_0xb4bf82[_0x3838('0x1b')];var _0x4a9a7a=_0x2d81b2?_0x396b2d[_0x3838('0x1e')]:_0xb4bf82[_0x3838('0x1b')]+_0xb4bf82['limit'];var _0x313a90;if(_0x4a9a7a>=_0x29e617){_0x4a9a7a=_0x29e617;_0x313a90=0xc8;}else{_0x313a90=0xce;}_0x284ec1['status'](_0x313a90);return _0x284ec1[_0x3838('0x1f')](_0x3838('0x20'),_0x45aa66+'-'+_0x4a9a7a+'/'+_0x29e617)[_0x3838('0x21')](_0x396b2d);}return null;};}function patchUpdates(_0x2f9965){return function(_0x31a4b8){try{jsonpatch['apply'](_0x31a4b8,_0x2f9965,!![]);}catch(_0x5d7dd0){return BPromise[_0x3838('0x22')](_0x5d7dd0);}return _0x31a4b8['save']();};}function saveUpdates(_0x211fa7,_0x220fdd){return function(_0x200e51){if(_0x200e51){return _0x200e51[_0x3838('0x23')](_0x211fa7)[_0x3838('0x24')](function(_0x30e98f){return _0x30e98f;});}return null;};}function removeEntity(_0xbd0fd1,_0x1e8d61){return function(_0x525b21){if(_0x525b21){return _0x525b21[_0x3838('0x25')]()['then'](function(){_0xbd0fd1[_0x3838('0x1a')](0xcc)[_0x3838('0x19')]();});}};}function handleEntityNotFound(_0x55eaa5,_0x45c723){return function(_0x265099){if(!_0x265099){_0x55eaa5['sendStatus'](0x194);}return _0x265099;};}function handleError(_0x12cf42,_0x30af15){_0x30af15=_0x30af15||0x1f4;return function(_0x537f85){logger[_0x3838('0x26')](_0x537f85['stack']);if(_0x537f85[_0x3838('0x27')]){delete _0x537f85['name'];}_0x12cf42['status'](_0x30af15)[_0x3838('0x28')](_0x537f85);};}exports[_0x3838('0x29')]=function(_0x41bb45,_0x21b3e5){var _0x22ee47={},_0x4b6519={},_0x1baf56={'count':0x0,'rows':[]};var _0x429da4=_[_0x3838('0x2a')](db['ZohoField'][_0x3838('0x2b')],function(_0x5ee2d8){return{'name':_0x5ee2d8[_0x3838('0x2c')],'type':_0x5ee2d8['type'][_0x3838('0x2d')]};});_0x4b6519[_0x3838('0x2e')]=_['map'](_0x429da4,_0x3838('0x27'));_0x4b6519['query']=_['keys'](_0x41bb45[_0x3838('0x2f')]);_0x4b6519[_0x3838('0x30')]=_['intersection'](_0x4b6519['model'],_0x4b6519[_0x3838('0x2f')]);_0x22ee47['attributes']=_[_0x3838('0x31')](_0x4b6519[_0x3838('0x2e')],qs[_0x3838('0x32')](_0x41bb45[_0x3838('0x2f')][_0x3838('0x32')]));_0x22ee47[_0x3838('0x33')]=_0x22ee47['attributes'][_0x3838('0x34')]?_0x22ee47[_0x3838('0x33')]:_0x4b6519[_0x3838('0x2e')];if(!_0x41bb45[_0x3838('0x2f')][_0x3838('0x35')](_0x3838('0x36'))){_0x22ee47[_0x3838('0x1c')]=qs[_0x3838('0x1c')](_0x41bb45[_0x3838('0x2f')][_0x3838('0x1c')]);_0x22ee47[_0x3838('0x1b')]=qs['offset'](_0x41bb45[_0x3838('0x2f')][_0x3838('0x1b')]);}_0x22ee47[_0x3838('0x37')]=qs[_0x3838('0x38')](_0x41bb45['query'][_0x3838('0x38')]);_0x22ee47[_0x3838('0x39')]=qs[_0x3838('0x30')](_[_0x3838('0x3a')](_0x41bb45['query'],_0x4b6519[_0x3838('0x30')]),_0x429da4);if(_0x41bb45[_0x3838('0x2f')][_0x3838('0x3b')]){_0x22ee47[_0x3838('0x39')]=_['merge'](_0x22ee47[_0x3838('0x39')],{'$or':_[_0x3838('0x2a')](_0x429da4,function(_0x28c0ba){if(_0x28c0ba['type']!=='VIRTUAL'){var _0x403078={};_0x403078[_0x28c0ba[_0x3838('0x27')]]={'$like':'%'+_0x41bb45[_0x3838('0x2f')][_0x3838('0x3b')]+'%'};return _0x403078;}})});}_0x22ee47=_[_0x3838('0x3c')]({},_0x22ee47,_0x41bb45[_0x3838('0x3d')]);var _0x29c159={'where':_0x22ee47[_0x3838('0x39')]};return db[_0x3838('0x3e')]['count'](_0x29c159)[_0x3838('0x24')](function(_0x303d26){_0x1baf56[_0x3838('0x1e')]=_0x303d26;if(_0x41bb45[_0x3838('0x2f')][_0x3838('0x3f')]){_0x22ee47[_0x3838('0x40')]=[{'all':!![]}];}return db[_0x3838('0x3e')][_0x3838('0x41')](_0x22ee47);})['then'](function(_0x2bbd18){_0x1baf56[_0x3838('0x42')]=_0x2bbd18;return _0x1baf56;})['then'](respondWithFilteredResult(_0x21b3e5,_0x22ee47))[_0x3838('0x43')](handleError(_0x21b3e5,null));};exports['show']=function(_0x27e830,_0x4e8e9b){var _0x5595f9={'raw':!![],'where':{'id':_0x27e830['params']['id']}},_0x55af4f={};_0x55af4f[_0x3838('0x2e')]=_[_0x3838('0x44')](db[_0x3838('0x3e')][_0x3838('0x2b')]);_0x55af4f['query']=_[_0x3838('0x44')](_0x27e830[_0x3838('0x2f')]);_0x55af4f[_0x3838('0x30')]=_[_0x3838('0x31')](_0x55af4f[_0x3838('0x2e')],_0x55af4f[_0x3838('0x2f')]);_0x5595f9[_0x3838('0x33')]=_[_0x3838('0x31')](_0x55af4f[_0x3838('0x2e')],qs[_0x3838('0x32')](_0x27e830['query'][_0x3838('0x32')]));_0x5595f9[_0x3838('0x33')]=_0x5595f9[_0x3838('0x33')][_0x3838('0x34')]?_0x5595f9[_0x3838('0x33')]:_0x55af4f[_0x3838('0x2e')];if(_0x27e830[_0x3838('0x2f')]['includeAll']){_0x5595f9[_0x3838('0x40')]=[{'all':!![]}];}_0x5595f9=_['merge']({},_0x5595f9,_0x27e830['options']);return db[_0x3838('0x3e')][_0x3838('0x45')](_0x5595f9)[_0x3838('0x24')](handleEntityNotFound(_0x4e8e9b,null))['then'](respondWithResult(_0x4e8e9b,null))[_0x3838('0x43')](handleError(_0x4e8e9b,null));};exports['create']=function(_0x1c4f00,_0x3f52fd){return db[_0x3838('0x3e')][_0x3838('0x46')](_0x1c4f00[_0x3838('0x47')],{})[_0x3838('0x24')](respondWithResult(_0x3f52fd,0xc9))[_0x3838('0x43')](handleError(_0x3f52fd,null));};exports[_0x3838('0x23')]=function(_0x415af0,_0x18b817){if(_0x415af0['body']['id']){delete _0x415af0['body']['id'];}return db['ZohoField'][_0x3838('0x45')]({'where':{'id':_0x415af0[_0x3838('0x48')]['id']}})[_0x3838('0x24')](handleEntityNotFound(_0x18b817,null))[_0x3838('0x24')](saveUpdates(_0x415af0[_0x3838('0x47')],null))[_0x3838('0x24')](respondWithResult(_0x18b817,null))[_0x3838('0x43')](handleError(_0x18b817,null));};exports[_0x3838('0x25')]=function(_0x1992a6,_0x359a68){return db[_0x3838('0x3e')][_0x3838('0x45')]({'where':{'id':_0x1992a6[_0x3838('0x48')]['id']}})[_0x3838('0x24')](handleEntityNotFound(_0x359a68,null))[_0x3838('0x24')](removeEntity(_0x359a68,null))[_0x3838('0x43')](handleError(_0x359a68,null));};