d13829f54fc747f9f091eeb5d28fe79e05c32c97
[motion2.git] / server / api / squareReportDetail / squareReportDetail.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 _0xac5e=['bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','limit','count','offset','set','apply','reject','save','update','then','destroy','error','stack','name','send','SquareDetailsReport','rawAttributes','type','key','map','query','keys','intersection','model','attributes','fields','length','order','sort','where','filters','pick','merge','VIRTUAL','include','findAll','rows','catch','show','params','includeAll','options','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise'];(function(_0x5f059b,_0x1bbed5){var _0x2d3b11=function(_0x361a25){while(--_0x361a25){_0x5f059b['push'](_0x5f059b['shift']());}};_0x2d3b11(++_0x1bbed5);}(_0xac5e,0x172));var _0xeac5=function(_0x4189ad,_0x1da98a){_0x4189ad=_0x4189ad-0x0;var _0x1318de=_0xac5e[_0x4189ad];return _0x1318de;};'use strict';var emlformat=require(_0xeac5('0x0'));var rimraf=require(_0xeac5('0x1'));var zipdir=require(_0xeac5('0x2'));var jsonpatch=require(_0xeac5('0x3'));var rp=require(_0xeac5('0x4'));var moment=require('moment');var BPromise=require(_0xeac5('0x5'));var Mustache=require(_0xeac5('0x6'));var util=require(_0xeac5('0x7'));var path=require(_0xeac5('0x8'));var sox=require(_0xeac5('0x9'));var csv=require(_0xeac5('0xa'));var ejs=require(_0xeac5('0xb'));var fs=require('fs');var fs_extra=require(_0xeac5('0xc'));var _=require(_0xeac5('0xd'));var squel=require(_0xeac5('0xe'));var crypto=require(_0xeac5('0xf'));var jsforce=require(_0xeac5('0x10'));var deskjs=require('desk.js');var toCsv=require(_0xeac5('0xa'));var querystring=require(_0xeac5('0x11'));var Papa=require(_0xeac5('0x12'));var Redis=require('ioredis');var authService=require(_0xeac5('0x13'));var qs=require('../../components/parsers/qs');var as=require(_0xeac5('0x14'));var hardwareService=require(_0xeac5('0x15'));var logger=require(_0xeac5('0x16'))('api');var utils=require('../../config/utils');var config=require(_0xeac5('0x17'));var licenseUtil=require(_0xeac5('0x18'));var db=require(_0xeac5('0x19'))['db'];function respondWithStatusCode(_0xc4473e,_0x438adb){_0x438adb=_0x438adb||0xcc;return function(_0x1c3ea1){if(_0x1c3ea1){return _0xc4473e[_0xeac5('0x1a')](_0x438adb);}return _0xc4473e[_0xeac5('0x1b')](_0x438adb)[_0xeac5('0x1c')]();};}function respondWithResult(_0x175104,_0xe4a92c){_0xe4a92c=_0xe4a92c||0xc8;return function(_0x27ad21){if(_0x27ad21){return _0x175104[_0xeac5('0x1b')](_0xe4a92c)[_0xeac5('0x1d')](_0x27ad21);}};}function respondWithFilteredResult(_0xe3ebcb,_0x5a4dbf){return function(_0x2a83a4){if(_0x2a83a4){var _0x262933=typeof _0x5a4dbf['offset']==='undefined'&&typeof _0x5a4dbf[_0xeac5('0x1e')]==='undefined';var _0x55310f=_0x2a83a4[_0xeac5('0x1f')];var _0x174759=_0x262933?0x0:_0x5a4dbf[_0xeac5('0x20')];var _0xa0098e=_0x262933?_0x2a83a4[_0xeac5('0x1f')]:_0x5a4dbf[_0xeac5('0x20')]+_0x5a4dbf[_0xeac5('0x1e')];var _0x4e8ce1;if(_0xa0098e>=_0x55310f){_0xa0098e=_0x55310f;_0x4e8ce1=0xc8;}else{_0x4e8ce1=0xce;}_0xe3ebcb[_0xeac5('0x1b')](_0x4e8ce1);return _0xe3ebcb[_0xeac5('0x21')]('Content-Range',_0x174759+'-'+_0xa0098e+'/'+_0x55310f)[_0xeac5('0x1d')](_0x2a83a4);}return null;};}function patchUpdates(_0x5a3673){return function(_0xc104c1){try{jsonpatch[_0xeac5('0x22')](_0xc104c1,_0x5a3673,!![]);}catch(_0x5f51b4){return BPromise[_0xeac5('0x23')](_0x5f51b4);}return _0xc104c1[_0xeac5('0x24')]();};}function saveUpdates(_0x3fbe58,_0x34c003){return function(_0x63fc2f){if(_0x63fc2f){return _0x63fc2f[_0xeac5('0x25')](_0x3fbe58)[_0xeac5('0x26')](function(_0x983014){return _0x983014;});}return null;};}function removeEntity(_0x3c22cf,_0x57ed50){return function(_0xe8b059){if(_0xe8b059){return _0xe8b059[_0xeac5('0x27')]()[_0xeac5('0x26')](function(){_0x3c22cf[_0xeac5('0x1b')](0xcc)[_0xeac5('0x1c')]();});}};}function handleEntityNotFound(_0x2a639e,_0x4194c4){return function(_0x1e5f68){if(!_0x1e5f68){_0x2a639e[_0xeac5('0x1a')](0x194);}return _0x1e5f68;};}function handleError(_0x4349de,_0x5a77c7){_0x5a77c7=_0x5a77c7||0x1f4;return function(_0xc1c99f){logger[_0xeac5('0x28')](_0xc1c99f[_0xeac5('0x29')]);if(_0xc1c99f[_0xeac5('0x2a')]){delete _0xc1c99f['name'];}_0x4349de[_0xeac5('0x1b')](_0x5a77c7)[_0xeac5('0x2b')](_0xc1c99f);};}exports['index']=function(_0x1e3a3a,_0x10e26b){var _0x37540c={},_0x4d74d6={},_0x3db4ea={'count':0x0,'rows':[]};var _0x22cfd6=_['map'](db[_0xeac5('0x2c')][_0xeac5('0x2d')],function(_0x119e73){return{'name':_0x119e73['fieldName'],'type':_0x119e73[_0xeac5('0x2e')][_0xeac5('0x2f')]};});_0x4d74d6['model']=_[_0xeac5('0x30')](_0x22cfd6,_0xeac5('0x2a'));_0x4d74d6[_0xeac5('0x31')]=_[_0xeac5('0x32')](_0x1e3a3a[_0xeac5('0x31')]);_0x4d74d6['filters']=_[_0xeac5('0x33')](_0x4d74d6[_0xeac5('0x34')],_0x4d74d6[_0xeac5('0x31')]);_0x37540c[_0xeac5('0x35')]=_[_0xeac5('0x33')](_0x4d74d6[_0xeac5('0x34')],qs[_0xeac5('0x36')](_0x1e3a3a[_0xeac5('0x31')]['fields']));_0x37540c[_0xeac5('0x35')]=_0x37540c[_0xeac5('0x35')][_0xeac5('0x37')]?_0x37540c[_0xeac5('0x35')]:_0x4d74d6['model'];if(!_0x1e3a3a[_0xeac5('0x31')]['hasOwnProperty']('nolimit')){_0x37540c[_0xeac5('0x1e')]=qs['limit'](_0x1e3a3a[_0xeac5('0x31')]['limit']);_0x37540c[_0xeac5('0x20')]=qs[_0xeac5('0x20')](_0x1e3a3a[_0xeac5('0x31')]['offset']);}_0x37540c[_0xeac5('0x38')]=qs[_0xeac5('0x39')](_0x1e3a3a[_0xeac5('0x31')][_0xeac5('0x39')]);_0x37540c[_0xeac5('0x3a')]=qs[_0xeac5('0x3b')](_[_0xeac5('0x3c')](_0x1e3a3a['query'],_0x4d74d6['filters']),_0x22cfd6);if(_0x1e3a3a[_0xeac5('0x31')]['filter']){_0x37540c[_0xeac5('0x3a')]=_[_0xeac5('0x3d')](_0x37540c[_0xeac5('0x3a')],{'$or':_[_0xeac5('0x30')](_0x22cfd6,function(_0x138c06){if(_0x138c06[_0xeac5('0x2e')]!==_0xeac5('0x3e')){var _0x57d731={};_0x57d731[_0x138c06['name']]={'$like':'%'+_0x1e3a3a[_0xeac5('0x31')]['filter']+'%'};return _0x57d731;}})});}_0x37540c=_[_0xeac5('0x3d')]({},_0x37540c,_0x1e3a3a['options']);var _0x3ee020={'where':_0x37540c[_0xeac5('0x3a')]};return db[_0xeac5('0x2c')][_0xeac5('0x1f')](_0x3ee020)['then'](function(_0x3176ac){_0x3db4ea[_0xeac5('0x1f')]=_0x3176ac;if(_0x1e3a3a['query']['includeAll']){_0x37540c[_0xeac5('0x3f')]=[{'all':!![]}];}return db['SquareDetailsReport'][_0xeac5('0x40')](_0x37540c);})['then'](function(_0x26d6fd){_0x3db4ea[_0xeac5('0x41')]=_0x26d6fd;return _0x3db4ea;})['then'](respondWithFilteredResult(_0x10e26b,_0x37540c))[_0xeac5('0x42')](handleError(_0x10e26b,null));};exports[_0xeac5('0x43')]=function(_0xbc602b,_0x4cac2a){var _0x44fd81={'raw':!![],'where':{'id':_0xbc602b[_0xeac5('0x44')]['id']}},_0x27f662={};_0x27f662[_0xeac5('0x34')]=_[_0xeac5('0x32')](db[_0xeac5('0x2c')][_0xeac5('0x2d')]);_0x27f662[_0xeac5('0x31')]=_[_0xeac5('0x32')](_0xbc602b[_0xeac5('0x31')]);_0x27f662[_0xeac5('0x3b')]=_[_0xeac5('0x33')](_0x27f662[_0xeac5('0x34')],_0x27f662[_0xeac5('0x31')]);_0x44fd81['attributes']=_[_0xeac5('0x33')](_0x27f662['model'],qs[_0xeac5('0x36')](_0xbc602b[_0xeac5('0x31')][_0xeac5('0x36')]));_0x44fd81[_0xeac5('0x35')]=_0x44fd81['attributes'][_0xeac5('0x37')]?_0x44fd81['attributes']:_0x27f662[_0xeac5('0x34')];if(_0xbc602b['query'][_0xeac5('0x45')]){_0x44fd81[_0xeac5('0x3f')]=[{'all':!![]}];}_0x44fd81=_['merge']({},_0x44fd81,_0xbc602b[_0xeac5('0x46')]);return db[_0xeac5('0x2c')][_0xeac5('0x47')](_0x44fd81)[_0xeac5('0x26')](handleEntityNotFound(_0x4cac2a,null))['then'](respondWithResult(_0x4cac2a,null))['catch'](handleError(_0x4cac2a,null));};exports[_0xeac5('0x48')]=function(_0x501e85,_0x50d7b1){return db['SquareDetailsReport']['create'](_0x501e85[_0xeac5('0x49')],{})[_0xeac5('0x26')](respondWithResult(_0x50d7b1,0xc9))['catch'](handleError(_0x50d7b1,null));};exports[_0xeac5('0x25')]=function(_0x4c7170,_0x49d0e8){if(_0x4c7170['body']['id']){delete _0x4c7170['body']['id'];}return db[_0xeac5('0x2c')][_0xeac5('0x47')]({'where':{'id':_0x4c7170['params']['id']}})['then'](handleEntityNotFound(_0x49d0e8,null))['then'](saveUpdates(_0x4c7170[_0xeac5('0x49')],null))['then'](respondWithResult(_0x49d0e8,null))['catch'](handleError(_0x49d0e8,null));};exports[_0xeac5('0x27')]=function(_0x584c88,_0x397e26){return db[_0xeac5('0x2c')][_0xeac5('0x47')]({'where':{'id':_0x584c88[_0xeac5('0x44')]['id']}})[_0xeac5('0x26')](handleEntityNotFound(_0x397e26,null))[_0xeac5('0x26')](removeEntity(_0x397e26,null))[_0xeac5('0x42')](handleError(_0x397e26,null));};exports[_0xeac5('0x4a')]=function(_0x3ced1f,_0x4b3ec3){return db[_0xeac5('0x2c')][_0xeac5('0x4a')]()['then'](respondWithResult(_0x4b3ec3,null))[_0xeac5('0x42')](handleError(_0x4b3ec3,null));};