feat(ticket): getVideo from shinobi
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-08-01 07:59:04 +02:00
parent 468da0c5a9
commit d040ecb743
12 changed files with 256 additions and 3 deletions

View File

@ -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');

12
front/core/lib/lilium.js Normal file
View File

@ -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;
}

View File

@ -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;
};
};

View File

@ -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;
}
});
});

View File

@ -5,6 +5,9 @@
"AnnualAverageInvoiced": { "AnnualAverageInvoiced": {
"dataSource": "vn" "dataSource": "vn"
}, },
"Boxing": {
"dataSource": "vn"
},
"Component": { "Component": {
"dataSource": "vn" "dataSource": "vn"
}, },
@ -20,6 +23,9 @@
"Packaging": { "Packaging": {
"dataSource": "vn" "dataSource": "vn"
}, },
"PackingSiteConfig": {
"dataSource": "vn"
},
"PrintServerQueue": { "PrintServerQueue": {
"dataSource": "vn" "dataSource": "vn"
}, },

View File

@ -0,0 +1,3 @@
module.exports = Self => {
require('../methods/boxing/getVideo')(Self);
};

View File

@ -0,0 +1,12 @@
{
"name": "Boxing",
"base": "PersistedModel",
"acls": [
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
]
}

View File

@ -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"
}
}
}

View File

@ -0,0 +1,2 @@
<vn-card>
</vn-card>

View File

@ -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: '<'
}
});

View File

@ -33,3 +33,4 @@ import './dms/index';
import './dms/create'; import './dms/create';
import './dms/edit'; import './dms/edit';
import './sms'; import './sms';
import './boxing';

View File

@ -24,7 +24,8 @@
{"state": "ticket.card.saleChecked", "icon": "assignment"}, {"state": "ticket.card.saleChecked", "icon": "assignment"},
{"state": "ticket.card.components", "icon": "icon-components"}, {"state": "ticket.card.components", "icon": "icon-components"},
{"state": "ticket.card.saleTracking", "icon": "assignment"}, {"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": [ "keybindings": [
@ -66,7 +67,7 @@
"abstract": true, "abstract": true,
"params": { "params": {
"ticket": "$ctrl.ticket" "ticket": "$ctrl.ticket"
} }
}, },
{ {
"url" : "/step-one", "url" : "/step-one",
@ -273,6 +274,15 @@
"params": { "params": {
"ticket": "$ctrl.ticket" "ticket": "$ctrl.ticket"
} }
},
{
"url": "/boxing",
"state": "ticket.card.boxing",
"component": "vn-ticket-boxing",
"description": "Boxing",
"params": {
"ticket": "$ctrl.ticket"
}
} }
] ]
} }