Built motion from commit da617fac.|2.6.6
[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 _0x7cca=['map','ZohoField','fieldName','type','keys','filters','intersection','model','attributes','fields','query','length','hasOwnProperty','order','sort','where','pick','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','rawAttributes','find','create','body','zip-dir','fast-json-patch','mustache','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','destroy','then','end','error','stack','name','send','index'];(function(_0x1e03e4,_0x362f76){var _0x4a887e=function(_0x13f548){while(--_0x13f548){_0x1e03e4['push'](_0x1e03e4['shift']());}};_0x4a887e(++_0x362f76);}(_0x7cca,0x67));var _0xa7cc=function(_0x2f0e95,_0x3e946e){_0x2f0e95=_0x2f0e95-0x0;var _0x230c64=_0x7cca[_0x2f0e95];return _0x230c64;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xa7cc('0x0'));var jsonpatch=require(_0xa7cc('0x1'));var rp=require('request-promise');var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xa7cc('0x2'));var util=require('util');var path=require('path');var sox=require(_0xa7cc('0x3'));var csv=require(_0xa7cc('0x4'));var ejs=require(_0xa7cc('0x5'));var fs=require('fs');var fs_extra=require(_0xa7cc('0x6'));var _=require(_0xa7cc('0x7'));var squel=require(_0xa7cc('0x8'));var crypto=require(_0xa7cc('0x9'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xa7cc('0x4'));var querystring=require(_0xa7cc('0xa'));var Papa=require(_0xa7cc('0xb'));var Redis=require(_0xa7cc('0xc'));var authService=require(_0xa7cc('0xd'));var qs=require(_0xa7cc('0xe'));var as=require(_0xa7cc('0xf'));var hardwareService=require(_0xa7cc('0x10'));var logger=require(_0xa7cc('0x11'))(_0xa7cc('0x12'));var utils=require('../../config/utils');var config=require(_0xa7cc('0x13'));var licenseUtil=require('../../config/license/util');var db=require(_0xa7cc('0x14'))['db'];function respondWithStatusCode(_0x5e7d6f,_0x4bb91a){_0x4bb91a=_0x4bb91a||0xcc;return function(_0x27cfa5){if(_0x27cfa5){return _0x5e7d6f['sendStatus'](_0x4bb91a);}return _0x5e7d6f[_0xa7cc('0x15')](_0x4bb91a)['end']();};}function respondWithResult(_0x303d6d,_0xb49321){_0xb49321=_0xb49321||0xc8;return function(_0x258a7c){if(_0x258a7c){return _0x303d6d['status'](_0xb49321)[_0xa7cc('0x16')](_0x258a7c);}};}function respondWithFilteredResult(_0x1f965a,_0x28e3c8){return function(_0x5cc3fb){if(_0x5cc3fb){var _0x40ec57=typeof _0x28e3c8[_0xa7cc('0x17')]===_0xa7cc('0x18')&&typeof _0x28e3c8[_0xa7cc('0x19')]===_0xa7cc('0x18');var _0x22e689=_0x5cc3fb[_0xa7cc('0x1a')];var _0x1d1bd7=_0x40ec57?0x0:_0x28e3c8[_0xa7cc('0x17')];var _0xcc85f4=_0x40ec57?_0x5cc3fb[_0xa7cc('0x1a')]:_0x28e3c8[_0xa7cc('0x17')]+_0x28e3c8[_0xa7cc('0x19')];var _0x2de319;if(_0xcc85f4>=_0x22e689){_0xcc85f4=_0x22e689;_0x2de319=0xc8;}else{_0x2de319=0xce;}_0x1f965a[_0xa7cc('0x15')](_0x2de319);return _0x1f965a[_0xa7cc('0x1b')](_0xa7cc('0x1c'),_0x1d1bd7+'-'+_0xcc85f4+'/'+_0x22e689)['json'](_0x5cc3fb);}return null;};}function patchUpdates(_0x11b302){return function(_0x4d8f2c){try{jsonpatch[_0xa7cc('0x1d')](_0x4d8f2c,_0x11b302,!![]);}catch(_0x501be7){return BPromise[_0xa7cc('0x1e')](_0x501be7);}return _0x4d8f2c[_0xa7cc('0x1f')]();};}function saveUpdates(_0x4c9f30,_0x50dee2){return function(_0x1fb50f){if(_0x1fb50f){return _0x1fb50f[_0xa7cc('0x20')](_0x4c9f30)['then'](function(_0x27e311){return _0x27e311;});}return null;};}function removeEntity(_0x183c4e,_0x15b6df){return function(_0x206df2){if(_0x206df2){return _0x206df2[_0xa7cc('0x21')]()[_0xa7cc('0x22')](function(){_0x183c4e['status'](0xcc)[_0xa7cc('0x23')]();});}};}function handleEntityNotFound(_0x3c409b,_0x211bd4){return function(_0x2ca82b){if(!_0x2ca82b){_0x3c409b['sendStatus'](0x194);}return _0x2ca82b;};}function handleError(_0xb8c7c8,_0x9dad){_0x9dad=_0x9dad||0x1f4;return function(_0x541c4c){logger[_0xa7cc('0x24')](_0x541c4c[_0xa7cc('0x25')]);if(_0x541c4c[_0xa7cc('0x26')]){delete _0x541c4c[_0xa7cc('0x26')];}_0xb8c7c8['status'](_0x9dad)[_0xa7cc('0x27')](_0x541c4c);};}exports[_0xa7cc('0x28')]=function(_0x28e052,_0x134e51){var _0x40e76a={},_0x21f2ab={},_0x2cc61b={'count':0x0,'rows':[]};var _0x3d7eeb=_[_0xa7cc('0x29')](db[_0xa7cc('0x2a')]['rawAttributes'],function(_0x2beee1){return{'name':_0x2beee1[_0xa7cc('0x2b')],'type':_0x2beee1[_0xa7cc('0x2c')]['key']};});_0x21f2ab['model']=_[_0xa7cc('0x29')](_0x3d7eeb,_0xa7cc('0x26'));_0x21f2ab['query']=_[_0xa7cc('0x2d')](_0x28e052['query']);_0x21f2ab[_0xa7cc('0x2e')]=_[_0xa7cc('0x2f')](_0x21f2ab[_0xa7cc('0x30')],_0x21f2ab['query']);_0x40e76a[_0xa7cc('0x31')]=_[_0xa7cc('0x2f')](_0x21f2ab[_0xa7cc('0x30')],qs[_0xa7cc('0x32')](_0x28e052[_0xa7cc('0x33')][_0xa7cc('0x32')]));_0x40e76a[_0xa7cc('0x31')]=_0x40e76a['attributes'][_0xa7cc('0x34')]?_0x40e76a[_0xa7cc('0x31')]:_0x21f2ab[_0xa7cc('0x30')];if(!_0x28e052[_0xa7cc('0x33')][_0xa7cc('0x35')]('nolimit')){_0x40e76a[_0xa7cc('0x19')]=qs['limit'](_0x28e052['query'][_0xa7cc('0x19')]);_0x40e76a[_0xa7cc('0x17')]=qs['offset'](_0x28e052[_0xa7cc('0x33')][_0xa7cc('0x17')]);}_0x40e76a[_0xa7cc('0x36')]=qs['sort'](_0x28e052[_0xa7cc('0x33')][_0xa7cc('0x37')]);_0x40e76a[_0xa7cc('0x38')]=qs['filters'](_[_0xa7cc('0x39')](_0x28e052[_0xa7cc('0x33')],_0x21f2ab[_0xa7cc('0x2e')]),_0x3d7eeb);if(_0x28e052[_0xa7cc('0x33')]['filter']){_0x40e76a['where']=_[_0xa7cc('0x3a')](_0x40e76a[_0xa7cc('0x38')],{'$or':_['map'](_0x3d7eeb,function(_0x336e35){if(_0x336e35[_0xa7cc('0x2c')]!==_0xa7cc('0x3b')){var _0x116fbb={};_0x116fbb[_0x336e35[_0xa7cc('0x26')]]={'$like':'%'+_0x28e052['query']['filter']+'%'};return _0x116fbb;}})});}_0x40e76a=_[_0xa7cc('0x3a')]({},_0x40e76a,_0x28e052[_0xa7cc('0x3c')]);var _0x16119a={'where':_0x40e76a[_0xa7cc('0x38')]};return db['ZohoField']['count'](_0x16119a)['then'](function(_0x1a629f){_0x2cc61b[_0xa7cc('0x1a')]=_0x1a629f;if(_0x28e052['query'][_0xa7cc('0x3d')]){_0x40e76a[_0xa7cc('0x3e')]=[{'all':!![]}];}return db['ZohoField'][_0xa7cc('0x3f')](_0x40e76a);})[_0xa7cc('0x22')](function(_0x409b1a){_0x2cc61b[_0xa7cc('0x40')]=_0x409b1a;return _0x2cc61b;})[_0xa7cc('0x22')](respondWithFilteredResult(_0x134e51,_0x40e76a))[_0xa7cc('0x41')](handleError(_0x134e51,null));};exports[_0xa7cc('0x42')]=function(_0xdcb834,_0x329e03){var _0x55c5ac={'raw':!![],'where':{'id':_0xdcb834[_0xa7cc('0x43')]['id']}},_0xb07bf1={};_0xb07bf1[_0xa7cc('0x30')]=_[_0xa7cc('0x2d')](db[_0xa7cc('0x2a')][_0xa7cc('0x44')]);_0xb07bf1[_0xa7cc('0x33')]=_[_0xa7cc('0x2d')](_0xdcb834[_0xa7cc('0x33')]);_0xb07bf1[_0xa7cc('0x2e')]=_[_0xa7cc('0x2f')](_0xb07bf1[_0xa7cc('0x30')],_0xb07bf1[_0xa7cc('0x33')]);_0x55c5ac[_0xa7cc('0x31')]=_[_0xa7cc('0x2f')](_0xb07bf1['model'],qs[_0xa7cc('0x32')](_0xdcb834[_0xa7cc('0x33')][_0xa7cc('0x32')]));_0x55c5ac[_0xa7cc('0x31')]=_0x55c5ac[_0xa7cc('0x31')]['length']?_0x55c5ac[_0xa7cc('0x31')]:_0xb07bf1['model'];if(_0xdcb834[_0xa7cc('0x33')][_0xa7cc('0x3d')]){_0x55c5ac[_0xa7cc('0x3e')]=[{'all':!![]}];}_0x55c5ac=_['merge']({},_0x55c5ac,_0xdcb834[_0xa7cc('0x3c')]);return db[_0xa7cc('0x2a')][_0xa7cc('0x45')](_0x55c5ac)[_0xa7cc('0x22')](handleEntityNotFound(_0x329e03,null))[_0xa7cc('0x22')](respondWithResult(_0x329e03,null))[_0xa7cc('0x41')](handleError(_0x329e03,null));};exports[_0xa7cc('0x46')]=function(_0xf41dcf,_0x3dd183){return db[_0xa7cc('0x2a')][_0xa7cc('0x46')](_0xf41dcf['body'],{})[_0xa7cc('0x22')](respondWithResult(_0x3dd183,0xc9))['catch'](handleError(_0x3dd183,null));};exports['update']=function(_0x328f8d,_0x3aed84){if(_0x328f8d[_0xa7cc('0x47')]['id']){delete _0x328f8d[_0xa7cc('0x47')]['id'];}return db[_0xa7cc('0x2a')][_0xa7cc('0x45')]({'where':{'id':_0x328f8d['params']['id']}})['then'](handleEntityNotFound(_0x3aed84,null))[_0xa7cc('0x22')](saveUpdates(_0x328f8d[_0xa7cc('0x47')],null))[_0xa7cc('0x22')](respondWithResult(_0x3aed84,null))['catch'](handleError(_0x3aed84,null));};exports[_0xa7cc('0x21')]=function(_0xbfa4de,_0x3f4278){return db['ZohoField'][_0xa7cc('0x45')]({'where':{'id':_0xbfa4de[_0xa7cc('0x43')]['id']}})[_0xa7cc('0x22')](handleEntityNotFound(_0x3f4278,null))['then'](removeEntity(_0x3f4278,null))[_0xa7cc('0x41')](handleError(_0x3f4278,null));};