932c807060a630fde35961cb91779ba063d57b2e
[motion2.git] / server / api / license / license.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 _0xf483=['getLicense','catch','body','License','params','demo','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','end','error','stack','name','send','index','model','keys','rawAttributes','query','filters','intersection','attributes','fields','length','merge','options'];(function(_0x13b194,_0x332de0){var _0xa2d34d=function(_0x52d89b){while(--_0x52d89b){_0x13b194['push'](_0x13b194['shift']());}};_0xa2d34d(++_0x332de0);}(_0xf483,0xf2));var _0x3f48=function(_0xad30ba,_0x3f7e67){_0xad30ba=_0xad30ba-0x0;var _0x233532=_0xf483[_0xad30ba];return _0x233532;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x3f48('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x3f48('0x1'));var jsonpatch=require(_0x3f48('0x2'));var rp=require(_0x3f48('0x3'));var moment=require(_0x3f48('0x4'));var BPromise=require(_0x3f48('0x5'));var Mustache=require(_0x3f48('0x6'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require(_0x3f48('0x7'));var ejs=require(_0x3f48('0x8'));var fs=require('fs');var _=require('lodash');var squel=require(_0x3f48('0x9'));var crypto=require(_0x3f48('0xa'));var jsforce=require(_0x3f48('0xb'));var deskjs=require(_0x3f48('0xc'));var toCsv=require(_0x3f48('0x7'));var querystring=require(_0x3f48('0xd'));var Papa=require(_0x3f48('0xe'));var Redis=require('ioredis');var authService=require(_0x3f48('0xf'));var qs=require(_0x3f48('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x3f48('0x11'));var logger=require('../../config/logger')(_0x3f48('0x12'));var utils=require(_0x3f48('0x13'));var config=require(_0x3f48('0x14'));var licenseUtil=require(_0x3f48('0x15'));var db=require(_0x3f48('0x16'))['db'];function respondWithStatusCode(_0x1e9563,_0x38502b){_0x38502b=_0x38502b||0xcc;return function(_0x5867db){if(_0x5867db){return _0x1e9563[_0x3f48('0x17')](_0x38502b);}return _0x1e9563[_0x3f48('0x18')](_0x38502b)['end']();};}function respondWithResult(_0x27ca72,_0x4e1f66){_0x4e1f66=_0x4e1f66||0xc8;return function(_0x101139){if(_0x101139){return _0x27ca72['status'](_0x4e1f66)[_0x3f48('0x19')](_0x101139);}};}function respondWithFilteredResult(_0x57c489,_0x2a2083){return function(_0x2013b9){if(_0x2013b9){var _0x364032=_0x2013b9[_0x3f48('0x1a')],_0x572ba5=_0x2a2083[_0x3f48('0x1b')],_0xd42f1e=_0x2a2083['offset']+_0x2a2083[_0x3f48('0x1c')],_0x319aa5;if(_0xd42f1e>=_0x364032){_0xd42f1e=_0x364032;_0x319aa5=0xc8;}else{_0x319aa5=0xce;}_0x57c489[_0x3f48('0x18')](_0x319aa5);return _0x57c489[_0x3f48('0x1d')](_0x3f48('0x1e'),_0x572ba5+'-'+_0xd42f1e+'/'+_0x364032)[_0x3f48('0x19')](_0x2013b9);}return null;};}function patchUpdates(_0x3d6cf3){return function(_0x7a962f){try{jsonpatch[_0x3f48('0x1f')](_0x7a962f,_0x3d6cf3,!![]);}catch(_0x349caf){return BPromise[_0x3f48('0x20')](_0x349caf);}return _0x7a962f[_0x3f48('0x21')]();};}function saveUpdates(_0x353a23,_0x108c6e){return function(_0x9be106){if(_0x9be106){return _0x9be106[_0x3f48('0x22')](_0x353a23)[_0x3f48('0x23')](function(_0x3e4946){return _0x3e4946;});}return null;};}function removeEntity(_0x285462,_0x12fcde){return function(_0x12ef86){if(_0x12ef86){return _0x12ef86['destroy']()['then'](function(){_0x285462[_0x3f48('0x18')](0xcc)[_0x3f48('0x24')]();});}};}function handleEntityNotFound(_0x2e569d,_0x56ad7b){return function(_0x48c473){if(!_0x48c473){_0x2e569d[_0x3f48('0x17')](0x194);}return _0x48c473;};}function handleError(_0x1f0191,_0x494b0f){_0x494b0f=_0x494b0f||0x1f4;return function(_0x30a5f1){logger[_0x3f48('0x25')](_0x30a5f1[_0x3f48('0x26')]);if(_0x30a5f1[_0x3f48('0x27')]){delete _0x30a5f1[_0x3f48('0x27')];}_0x1f0191[_0x3f48('0x18')](_0x494b0f)[_0x3f48('0x28')](_0x30a5f1);};}var utilLicense=require('../../config/license/util');exports[_0x3f48('0x29')]=function(_0x3340d5,_0x320f91){var _0x1d9420={'raw':!![],'where':{'id':0x1}},_0x568701={};_0x568701[_0x3f48('0x2a')]=_[_0x3f48('0x2b')](db['License'][_0x3f48('0x2c')]);_0x568701[_0x3f48('0x2d')]=_[_0x3f48('0x2b')](_0x3340d5['query']);_0x568701[_0x3f48('0x2e')]=_[_0x3f48('0x2f')](_0x568701['model'],_0x568701[_0x3f48('0x2d')]);_0x1d9420[_0x3f48('0x30')]=_[_0x3f48('0x2f')](_0x568701['model'],qs['fields'](_0x3340d5['query'][_0x3f48('0x31')]));_0x1d9420[_0x3f48('0x30')]=_0x1d9420[_0x3f48('0x30')][_0x3f48('0x32')]?_0x1d9420[_0x3f48('0x30')]:_0x568701[_0x3f48('0x2a')];_0x1d9420=_[_0x3f48('0x33')]({},_0x1d9420,_0x3340d5[_0x3f48('0x34')]);return utilLicense[_0x3f48('0x35')](_0x1d9420)[_0x3f48('0x23')](respondWithResult(_0x320f91,null))[_0x3f48('0x36')](handleError(_0x320f91,null));};exports[_0x3f48('0x22')]=function(_0x25a6b4,_0x2aa9ed){if(_0x25a6b4['body']['id']){delete _0x25a6b4[_0x3f48('0x37')]['id'];}return db[_0x3f48('0x38')]['find']({'where':{'id':_0x25a6b4[_0x3f48('0x39')]['id']}})['then'](handleEntityNotFound(_0x2aa9ed,null))['then'](function(_0x530f1b){var _0x50c1fc=_0x530f1b['get']({'plain':!![]});return utilLicense['checkLicense'](_0x50c1fc,_0x25a6b4[_0x3f48('0x37')]['key']);})['then'](function(_0x7f9d37){if(!_0x7f9d37[_0x3f48('0x3a')]){return saveUpdates(_0x25a6b4[_0x3f48('0x37')],null);}return _0x7f9d37;})[_0x3f48('0x23')](respondWithResult(_0x2aa9ed,null))['catch'](handleError(_0x2aa9ed,null));};