diff --git a/db/changes/10480-june/00-packingSiteConfig.sql b/db/changes/10480-june/00-packingSiteConfig.sql new file mode 100644 index 000000000..b32bc115e --- /dev/null +++ b/db/changes/10480-june/00-packingSiteConfig.sql @@ -0,0 +1,16 @@ +CREATE TABLE `vn`.`packingSiteConfig` ( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `shinobiUrl` varchar(255) NOT NULL, + `shinobiGroupKey` varchar(255) NOT NULL, + `avgBoxingTime` INT(3) NULL, + PRIMARY KEY (`id`) + ); + +INSERT INTO `vn`.`packingSiteConfig` SET + shinobiUrl = 'https://shinobi.verdnatura.es/', + shinobiGroupKey = 'xVqft9LFXg', + avgBoxingTime = 30; + +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('Boxing', '*', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/front/core/lib/lilium.js b/front/core/lib/lilium.js new file mode 100644 index 000000000..ca10d3511 --- /dev/null +++ b/front/core/lib/lilium.js @@ -0,0 +1,12 @@ + +export default function lilium(route) { + const env = process.env.NODE_ENV; + let newRoute = 'https://localhost:8080/#/' + route; + + if (env == 'test') + newRoute = 'https://test-lilium.verdnatura.es/#/' + route; + if (env == 'producction') + newRoute = 'https://lilium.verdnatura.es/#/' + route; + + return newRoute; +} diff --git a/modules/ticket/back/methods/boxing/getVideo.js b/modules/ticket/back/methods/boxing/getVideo.js new file mode 100644 index 000000000..851e4cfac --- /dev/null +++ b/modules/ticket/back/methods/boxing/getVideo.js @@ -0,0 +1,65 @@ +const axios = require('axios'); + +module.exports = Self => { + Self.remoteMethod('getVideo', { + description: 'Get packing video of ticketId', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'Ticket id' + }, + { + arg: 'time', + type: 'number', + required: true, + description: 'Time to add' + } + ], + returns: { + type: ['object'], + root: true, + }, + http: { + path: `/getVideo`, + verb: 'GET', + }, + }); + + Self.getVideo = async(id, time, options) => { + const models = Self.app.models; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const expedition = await models.Expedition.findById(id, null, myOptions); + const packingSiteConfig = await models.PackingSiteConfig.findOne({}, myOptions); + const token = await Self.getToken(packingSiteConfig); + const monitorId = 'xVqft9LFXg'; + + const start = new Date(expedition.created); + const end = start.setTime(start.getTime() + (time ? time : packingSiteConfig.avgBoxingTime)); + + const videoUrl = `${token}/videos/${packingSiteConfig}/${monitorId}?start=${start}&end=${end}`; + const videos = await axios.post(`${packingSiteConfig.shinobiUrl}${videoUrl}`, { + mail: packingSiteConfig.mail, + pass: packingSiteConfig.pass + }); + + console.log(videos); + return videos.data; + }; + + Self.getToken = async function getToken(packingSiteConfig) { + const response = await axios.post(`${packingSiteConfig.shinobiUrl}?json=true`, { + machineID: 1, + ke: 'hola', + }); + + console.log(response); + return response.data; + }; +}; diff --git a/modules/ticket/back/methods/boxing/specs/getVideo.js b/modules/ticket/back/methods/boxing/specs/getVideo.js new file mode 100644 index 000000000..ad5295f0c --- /dev/null +++ b/modules/ticket/back/methods/boxing/specs/getVideo.js @@ -0,0 +1,69 @@ +const models = require('vn-loopback/server/server').models; + +xdescribe('sale canEdit()', () => { + it('should return true if the role is production regardless of the saleTrackings', async() => { + const tx = await models.Sale.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const productionUserID = 49; + const ctx = {req: {accessToken: {userId: productionUserID}}}; + + const sales = [{id: 3}]; + + const result = await models.Sale.canEdit(ctx, sales, options); + + expect(result).toEqual(true); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return true if the role is not production and none of the sales has saleTracking', async() => { + const tx = await models.Sale.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const salesPersonUserID = 18; + const ctx = {req: {accessToken: {userId: salesPersonUserID}}}; + + const sales = [{id: 10}]; + + const result = await models.Sale.canEdit(ctx, sales, options); + + expect(result).toEqual(true); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return false if any of the sales has a saleTracking record', async() => { + const tx = await models.Sale.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const salesPersonUserID = 18; + const ctx = {req: {accessToken: {userId: salesPersonUserID}}}; + + const sales = [{id: 3}]; + + const result = await models.Sale.canEdit(ctx, sales, options); + + expect(result).toEqual(false); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/ticket/back/model-config.json b/modules/ticket/back/model-config.json index 8a6ac0c00..21e800b36 100644 --- a/modules/ticket/back/model-config.json +++ b/modules/ticket/back/model-config.json @@ -5,6 +5,9 @@ "AnnualAverageInvoiced": { "dataSource": "vn" }, + "Boxing": { + "dataSource": "vn" + }, "Component": { "dataSource": "vn" }, @@ -20,6 +23,9 @@ "Packaging": { "dataSource": "vn" }, + "PackingSiteConfig": { + "dataSource": "vn" + }, "PrintServerQueue": { "dataSource": "vn" }, diff --git a/modules/ticket/back/models/boxing.js b/modules/ticket/back/models/boxing.js new file mode 100644 index 000000000..81732d17a --- /dev/null +++ b/modules/ticket/back/models/boxing.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/boxing/getVideo')(Self); +}; diff --git a/modules/ticket/back/models/boxing.json b/modules/ticket/back/models/boxing.json new file mode 100644 index 000000000..5aecbcabe --- /dev/null +++ b/modules/ticket/back/models/boxing.json @@ -0,0 +1,12 @@ +{ + "name": "Boxing", + "base": "PersistedModel", + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} diff --git a/modules/ticket/back/models/packingSiteConfig.json b/modules/ticket/back/models/packingSiteConfig.json new file mode 100644 index 000000000..7e4699c71 --- /dev/null +++ b/modules/ticket/back/models/packingSiteConfig.json @@ -0,0 +1,25 @@ +{ + "name": "PackingSiteConfig", + "base": "VnModel", + "options": { + "mysql": { + "table": "packingSiteConfig" + } + }, + "properties": { + "id": { + "id": true, + "type": "number", + "description": "Identifier" + }, + "shinobiUrl": { + "type": "string" + }, + "shinobiGroupKey":{ + "type":"string" + }, + "avgBoxingTime":{ + "type":"number" + } + } +} diff --git a/modules/ticket/front/boxing/index.html b/modules/ticket/front/boxing/index.html new file mode 100644 index 000000000..7fb3b870e --- /dev/null +++ b/modules/ticket/front/boxing/index.html @@ -0,0 +1,2 @@ + + diff --git a/modules/ticket/front/boxing/index.js b/modules/ticket/front/boxing/index.js new file mode 100644 index 000000000..6a1d4b4d3 --- /dev/null +++ b/modules/ticket/front/boxing/index.js @@ -0,0 +1,32 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +class Controller extends Section { + constructor($element, $) { + super($element, $); + } + + $onInit() { + window.location.href = this.lilium('dashboard'); + } + + 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; + } +} + +ngModule.vnComponent('vnTicketBoxing', { + template: require('./index.html'), + controller: Controller, + bindings: { + ticket: '<' + } +}); diff --git a/modules/ticket/front/index.js b/modules/ticket/front/index.js index 85a03ffb6..0558d251d 100644 --- a/modules/ticket/front/index.js +++ b/modules/ticket/front/index.js @@ -33,3 +33,4 @@ import './dms/index'; import './dms/create'; import './dms/edit'; import './sms'; +import './boxing'; diff --git a/modules/ticket/front/routes.json b/modules/ticket/front/routes.json index ba7cfa887..4be8e2183 100644 --- a/modules/ticket/front/routes.json +++ b/modules/ticket/front/routes.json @@ -24,7 +24,8 @@ {"state": "ticket.card.saleChecked", "icon": "assignment"}, {"state": "ticket.card.components", "icon": "icon-components"}, {"state": "ticket.card.saleTracking", "icon": "assignment"}, - {"state": "ticket.card.dms.index", "icon": "cloud_download"} + {"state": "ticket.card.dms.index", "icon": "cloud_download"}, + {"state": "ticket.card.boxing", "icon": "science"} ] }, "keybindings": [ @@ -66,7 +67,7 @@ "abstract": true, "params": { "ticket": "$ctrl.ticket" - } + } }, { "url" : "/step-one", @@ -273,6 +274,15 @@ "params": { "ticket": "$ctrl.ticket" } + }, + { + "url": "/boxing", + "state": "ticket.card.boxing", + "component": "vn-ticket-boxing", + "description": "Boxing", + "params": { + "ticket": "$ctrl.ticket" + } } ] -} \ No newline at end of file +}