1b5d9e6be4c2a8c16a36d84084a731c2d3e6161b
[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 _0x14f5=['options','getLicense','catch','body','checkLicense','demo','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','sox','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','set','Content-Range','apply','reject','update','then','destroy','error','stack','name','send','index','model','License','query','filters','intersection','fields','attributes','length'];(function(_0x38a54d,_0x132fde){var _0x2d1b0e=function(_0x11cac8){while(--_0x11cac8){_0x38a54d['push'](_0x38a54d['shift']());}};_0x2d1b0e(++_0x132fde);}(_0x14f5,0xae));var _0x514f=function(_0x5451cb,_0x4024d4){_0x5451cb=_0x5451cb-0x0;var _0x536727=_0x14f5[_0x5451cb];return _0x536727;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x514f('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x514f('0x1'));var jsonpatch=require(_0x514f('0x2'));var rp=require(_0x514f('0x3'));var moment=require('moment');var BPromise=require(_0x514f('0x4'));var Mustache=require(_0x514f('0x5'));var util=require('util');var path=require(_0x514f('0x6'));var sox=require(_0x514f('0x7'));var csv=require(_0x514f('0x8'));var ejs=require(_0x514f('0x9'));var fs=require('fs');var _=require(_0x514f('0xa'));var squel=require(_0x514f('0xb'));var crypto=require(_0x514f('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x514f('0xd'));var toCsv=require('to-csv');var querystring=require(_0x514f('0xe'));var Papa=require(_0x514f('0xf'));var Redis=require(_0x514f('0x10'));var authService=require(_0x514f('0x11'));var qs=require(_0x514f('0x12'));var as=require(_0x514f('0x13'));var hardwareService=require(_0x514f('0x14'));var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require(_0x514f('0x15'));var licenseUtil=require(_0x514f('0x16'));var db=require(_0x514f('0x17'))['db'];function respondWithStatusCode(_0x321914,_0x3eed49){_0x3eed49=_0x3eed49||0xcc;return function(_0x2ed1b7){if(_0x2ed1b7){return _0x321914[_0x514f('0x18')](_0x3eed49);}return _0x321914[_0x514f('0x19')](_0x3eed49)[_0x514f('0x1a')]();};}function respondWithResult(_0x4124bf,_0x46e552){_0x46e552=_0x46e552||0xc8;return function(_0x3fc905){if(_0x3fc905){return _0x4124bf[_0x514f('0x19')](_0x46e552)[_0x514f('0x1b')](_0x3fc905);}};}function respondWithFilteredResult(_0x1694b3,_0x5865d1){return function(_0x70d2b4){if(_0x70d2b4){var _0x1f0cbe=_0x70d2b4[_0x514f('0x1c')],_0x519b63=_0x5865d1[_0x514f('0x1d')],_0x255996=_0x5865d1[_0x514f('0x1d')]+_0x5865d1['limit'],_0x53851d;if(_0x255996>=_0x1f0cbe){_0x255996=_0x1f0cbe;_0x53851d=0xc8;}else{_0x53851d=0xce;}_0x1694b3[_0x514f('0x19')](_0x53851d);return _0x1694b3[_0x514f('0x1e')](_0x514f('0x1f'),_0x519b63+'-'+_0x255996+'/'+_0x1f0cbe)[_0x514f('0x1b')](_0x70d2b4);}return null;};}function patchUpdates(_0x4ba9b1){return function(_0x4f9193){try{jsonpatch[_0x514f('0x20')](_0x4f9193,_0x4ba9b1,!![]);}catch(_0x344433){return BPromise[_0x514f('0x21')](_0x344433);}return _0x4f9193['save']();};}function saveUpdates(_0x43fcf9,_0x7248e8){return function(_0x58eacc){if(_0x58eacc){return _0x58eacc[_0x514f('0x22')](_0x43fcf9)[_0x514f('0x23')](function(_0x560c23){return _0x560c23;});}return null;};}function removeEntity(_0xd093a1,_0x18a430){return function(_0xd89aa2){if(_0xd89aa2){return _0xd89aa2[_0x514f('0x24')]()['then'](function(){_0xd093a1['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x5d80cb,_0x1c16f9){return function(_0x22928c){if(!_0x22928c){_0x5d80cb[_0x514f('0x18')](0x194);}return _0x22928c;};}function handleError(_0xc36426,_0x2bf423){_0x2bf423=_0x2bf423||0x1f4;return function(_0x26df04){logger[_0x514f('0x25')](_0x26df04[_0x514f('0x26')]);if(_0x26df04[_0x514f('0x27')]){delete _0x26df04['name'];}_0xc36426[_0x514f('0x19')](_0x2bf423)[_0x514f('0x28')](_0x26df04);};}var utilLicense=require(_0x514f('0x16'));exports[_0x514f('0x29')]=function(_0x326809,_0x32f3e1){var _0x1a413e={'raw':!![],'where':{'id':0x1}},_0x2f61f7={};_0x2f61f7[_0x514f('0x2a')]=_['keys'](db[_0x514f('0x2b')]['rawAttributes']);_0x2f61f7[_0x514f('0x2c')]=_['keys'](_0x326809[_0x514f('0x2c')]);_0x2f61f7[_0x514f('0x2d')]=_[_0x514f('0x2e')](_0x2f61f7[_0x514f('0x2a')],_0x2f61f7[_0x514f('0x2c')]);_0x1a413e['attributes']=_['intersection'](_0x2f61f7[_0x514f('0x2a')],qs['fields'](_0x326809[_0x514f('0x2c')][_0x514f('0x2f')]));_0x1a413e[_0x514f('0x30')]=_0x1a413e[_0x514f('0x30')][_0x514f('0x31')]?_0x1a413e['attributes']:_0x2f61f7['model'];_0x1a413e=_['merge']({},_0x1a413e,_0x326809[_0x514f('0x32')]);return utilLicense[_0x514f('0x33')](_0x1a413e)[_0x514f('0x23')](respondWithResult(_0x32f3e1,null))[_0x514f('0x34')](handleError(_0x32f3e1,null));};exports[_0x514f('0x22')]=function(_0x3526c0,_0x1cd65a){if(_0x3526c0[_0x514f('0x35')]['id']){delete _0x3526c0[_0x514f('0x35')]['id'];}return db[_0x514f('0x2b')]['find']({'where':{'id':_0x3526c0['params']['id']}})['then'](handleEntityNotFound(_0x1cd65a,null))[_0x514f('0x23')](function(_0x4e028b){var _0x450d04=_0x4e028b['get']({'plain':!![]});return utilLicense[_0x514f('0x36')](_0x450d04,_0x3526c0['body']['key']);})[_0x514f('0x23')](function(_0x5c78be){if(!_0x5c78be[_0x514f('0x37')]){return saveUpdates(_0x3526c0[_0x514f('0x35')],null);}return _0x5c78be;})[_0x514f('0x23')](respondWithResult(_0x1cd65a,null))[_0x514f('0x34')](handleError(_0x1cd65a,null));};