diff --git a/back/model-config.json b/back/model-config.json index f4adc954b..5f1c0bbe2 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -101,6 +101,9 @@ "Town": { "dataSource": "vn" }, + "Url": { + "dataSource": "vn" + }, "UserConfig": { "dataSource": "vn" }, diff --git a/back/models/url.json b/back/models/url.json new file mode 100644 index 000000000..8610ff28b --- /dev/null +++ b/back/models/url.json @@ -0,0 +1,25 @@ +{ + "name": "Url", + "base": "VnModel", + "options": { + "mysql": { + "table": "salix.url" + } + }, + "properties": { + "appName": { + "type": "string", + "required": true, + "id": 1 + }, + "environment": { + "type": "string", + "required": true, + "id": 2 + }, + "url": { + "type": "string", + "required": true + } + } +} diff --git a/db/changes/10490-august/00-packingSiteConfig.sql b/db/changes/10490-august/00-packingSiteConfig.sql index bbd0b32de..dc5e4c5cf 100644 --- a/db/changes/10490-august/00-packingSiteConfig.sql +++ b/db/changes/10490-august/00-packingSiteConfig.sql @@ -11,7 +11,7 @@ INSERT INTO `vn`.`packingSiteConfig` SET shinobiUrl = 'https://shinobi.verdnatura.es', shinobiToken = 'BW4o7FZyJ85she1hlRDe6QnwW3jwEP', shinobiGroupKey = 'xVqft9LFXg', - avgBoxingTime = 30; + avgBoxingTime = 6000; INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES diff --git a/db/changes/10490-august/00-salix_url.sql b/db/changes/10490-august/00-salix_url.sql new file mode 100644 index 000000000..ea5c3b606 --- /dev/null +++ b/db/changes/10490-august/00-salix_url.sql @@ -0,0 +1,33 @@ +CREATE TABLE `salix`.`url` ( + `appName` varchar(100) NOT NULL, + `environment` varchar(100) NOT NULL, + `url` varchar(255) NOT NULL, + PRIMARY KEY (`appName`,`environment`) +); + +INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) + VALUES + ('salix', 'production', 'https://salix.verdnatura.es/#!/'); +INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) + VALUES + ('salix', 'test', 'https://test-salix.verdnatura.es/#!/'); +INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) + VALUES + ('salix', 'dev', 'http://localhost:5000/#!/'); +INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) + VALUES + ('lilium', 'production', 'https://lilium.verdnatura.es/#/'); +INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) + VALUES + ('lilium', 'test', 'https://test-lilium.verdnatura.es/#/'); +INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) + VALUES + ('lilium', 'dev', 'http://localhost:8080/#/'); + +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('Url', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); + +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('Url', '*', 'WRITE', 'ALLOW', 'ROLE', 'it'); diff --git a/front/core/services/app.js b/front/core/services/app.js index 889b24d01..37bddeca0 100644 --- a/front/core/services/app.js +++ b/front/core/services/app.js @@ -54,6 +54,23 @@ export default class App { localStorage.setItem('salix-version', newVersion); } } + + getUrl(route, appName) { + if (!appName) appName = 'lilium'; + + const env = process.env.NODE_ENV; + const filter = { + where: {and: [ + {appName: appName}, + {environment: env} + ]} + }; + + return this.logger.$http.get('Urls/findOne', {filter}) + .then(res => { + return res.data.url + route; + }); + } } ngModule.service('vnApp', App); diff --git a/modules/ticket/back/methods/boxing/specs/getVideo.spec.js b/modules/ticket/back/methods/boxing/specs/getVideo.spec.js new file mode 100644 index 000000000..8e8cdc5b9 --- /dev/null +++ b/modules/ticket/back/methods/boxing/specs/getVideo.spec.js @@ -0,0 +1,40 @@ +const models = require('vn-loopback/server/server').models; +const https = require('https'); + +xdescribe('boxing getVideo()', () => { + it('should return data', async() => { + const tx = await models.PackingSiteConfig.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const id = 1; + const video = 'video.mp4'; + + const response = { + pipe: () => {}, + on: () => {}, + end: () => {}, + }; + + const req = { + headers: 'apiHeader', + data: { + pipe: () => {}, + on: () => {}, + } + }; + + spyOn(https, 'request').and.returnValue(response); + + const result = await models.Boxing.getVideo(id, video, req, null, options); + + expect(result[0]).toEqual(response.data.videos[0].filename); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/ticket/back/methods/boxing/specs/getVideoList.js b/modules/ticket/back/methods/boxing/specs/getVideoList.spec.js similarity index 58% rename from modules/ticket/back/methods/boxing/specs/getVideoList.js rename to modules/ticket/back/methods/boxing/specs/getVideoList.spec.js index e703f4c03..c6d1a3e07 100644 --- a/modules/ticket/back/methods/boxing/specs/getVideoList.js +++ b/modules/ticket/back/methods/boxing/specs/getVideoList.spec.js @@ -2,29 +2,30 @@ const models = require('vn-loopback/server/server').models; const axios = require('axios'); describe('boxing getVideoList()', () => { - it('should return data', async() => { + it('should return video list', async() => { const tx = await models.PackingSiteConfig.beginTransaction({}); try { const options = {transaction: tx}; - const params = { - id: 1, - from: 1, - to: 2 - }; + const id = 1; + const from = 1; + const to = 2; const response = { data: { - pipe: () => {}, - on: () => {}, + videos: [{ + id: 1, + filename: 'video1.mp4' + }] } }; + spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(response))); - const result = await models.Sale.canEdit(params, options); + const result = await models.Boxing.getVideoList(id, from, to, options); - expect(result).toEqual([]); + expect(result[0]).toEqual(response.data.videos[0].filename); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/front/boxing/index.js b/modules/ticket/front/boxing/index.js index 686bf7d01..4e6b398f2 100644 --- a/modules/ticket/front/boxing/index.js +++ b/modules/ticket/front/boxing/index.js @@ -6,20 +6,9 @@ class Controller extends Section { super($element, $); } - $onInit() { - window.location.href = this.lilium(`ticket/${this.ticket.id}/boxing`); - } - - lilium(route) { - const env = process.env.NODE_ENV; - let newRoute = 'http://localhost:8080/#/' + route; - - if (env == 'test') - newRoute = 'https://test-lilium.verdnatura.es/#/' + route; - if (env == 'producction') - newRoute = 'https://lilium.verdnatura.es/#/' + route; - - return newRoute; + async $onInit() { + const url = await this.vnApp.getUrl(`ticket/${this.$params.id}/boxing`); + window.open(url).focus(); } }