#5926 - Worker/PDA docuware #2482

Open
jsegarra wants to merge 40 commits from 5926_pda_worker_docuware into dev
4 changed files with 3 additions and 91 deletions
Showing only changes of commit 2072a3f404 - Show all commits

View File

@ -11,6 +11,7 @@ module.exports = Self => {
id, id,
type: 'deliveryNote' type: 'deliveryNote'
}, myOptions); }, myOptions);
// get ticket data // get ticket data
const ticket = await models.Ticket.findById(id, { const ticket = await models.Ticket.findById(id, {
include: [{ include: [{
@ -23,7 +24,6 @@ module.exports = Self => {
// upload file // upload file
const configTemplate = { const configTemplate = {
'N__ALBAR_N': { 'N__ALBAR_N': {
type: 'string', type: 'string',
value: id, value: id,
@ -69,32 +69,9 @@ module.exports = Self => {
// delete old // delete old
await models.Docuware.deleteOld(id, fileCabinet, uri); await models.Docuware.deleteOld(id, fileCabinet, uri);
// const docuwareFile = await models.Docuware.checkFile(id, fileCabinet, false);
// if (docuwareFile) {
// const deleteJson = {
// 'Field': [{'FieldName': 'ESTADO', 'Item': 'Pendiente eliminar', 'ItemElementName': 'String'}]
// };
// const deleteUri = `${uri}/${docuwareFile.id}/Fields`;
// await axios.put(deleteUri, deleteJson, docuwareOptions.headers);
// }
const uploadUri = `${uri}?StoreDialogId=${dialogId}`; const uploadUri = `${uri}?StoreDialogId=${dialogId}`;
const uploadOptions = models.Docuware.uploadOptions(deliveryNote[0], configTemplate); const uploadOptions = models.Docuware.uploadOptions(deliveryNote[0], configTemplate);
// const FormData = require('form-data');
// const data = new FormData();
// data.append('document', JSON.stringify(templateJson), 'schema.json');
// data.append('file[]', deliveryNote[0], 'file.pdf');
// const uploadOptions = {
// headers: {
// 'Content-Type': 'multipart/form-data',
// 'X-File-ModifiedDate': Date.vnNew(),
// 'Cookie': docuwareOptions.headers.headers.Cookie,
// ...data.getHeaders()
// },
// };
try { try {
await axios.post(uploadUri, data, uploadOptions); await axios.post(uploadUri, data, uploadOptions);
} catch (err) { } catch (err) {

View File

@ -4,18 +4,16 @@ const UserError = require('vn-loopback/util/user-error');
const isProduction = require('vn-loopback/server/boot/isProduction'); const isProduction = require('vn-loopback/server/boot/isProduction');
module.exports = Self => { module.exports = Self => {
Self.docuwareUpload = async({ctx, tabletFk, ids: id, myOptions, uri, fileCabinet, dialogId}) => { Self.docuwareUpload = async({ctx, tabletFk, ids: id, myOptions, uri, fileCabinet, dialogId}) => {
// get delivery note
const pdaId = id[0]; const pdaId = id[0];
ctx.args.id = pdaId; ctx.args.id = pdaId;
delete ctx.args.ids; delete ctx.args.ids;
// // get ticket data
// const pda = await models.DeviceProduction.findById(pdaId, myOptions);
// const user = await models.UserConfig.find({where: {tabletFk}, fields: ['userFk']}, myOptions);
// upload file // upload file
const signPda = await models.Worker.signPdaPdf(ctx, const signPda = await models.Worker.signPdaPdf(ctx,
pdaId pdaId
, myOptions); , myOptions);
const configTemplate = { const configTemplate = {
'N__DOCUMENTO': { 'N__DOCUMENTO': {
type: 'String', type: 'String',
@ -40,14 +38,6 @@ module.exports = Self => {
// delete old // delete old
await models.Docuware.deleteOld(id, fileCabinet, uri); await models.Docuware.deleteOld(id, fileCabinet, uri);
// const docuwareFile = await models.Docuware.checkFile(id, fileCabinet, false);
// if (docuwareFile) {
// const deleteJson = {
// 'Field': [{'FieldName': 'ESTADO', 'Item': 'Pendiente eliminar', 'ItemElementName': 'String'}]
// };
// const deleteUri = `${uri}/${docuwareFile.id}/Fields`;
// await axios.put(deleteUri, deleteJson, docuwareOptions.headers);
// }
const uploadUri = `${uri}?StoreDialogId=${dialogId}`; const uploadUri = `${uri}?StoreDialogId=${dialogId}`;
const uploadOptions = models.Docuware.uploadOptions(signPda[0], configTemplate); const uploadOptions = models.Docuware.uploadOptions(signPda[0], configTemplate);

View File

@ -1,54 +0,0 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('isPDASigned', {
description: 'Deallocate the PDA of the worker',
accepts: [{
arg: 'ctx',
type: 'Object',
http: {source: 'context'}
}, {
arg: 'id',
type: 'number',
required: true,
description: 'The worker id',
http: {source: 'path'}
}, {
arg: 'pda',
type: 'number',
required: true,
description: 'The pda id'
}],
returns: {
type: ['object'],
root: true
},
http: {
path: '/:id/:pda/isPDASigned',
verb: 'GET'
}
});
Self.isPDASigned = async(ctx, options) => {
const models = Self.app.models;
const args = ctx.args;
let tx;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const pda = await models.DeviceProduction.findById(args.pda, myOptions);
if (pda.stateFk != 'idle') throw new UserError(`The PDA state is not idle`);
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -18,7 +18,6 @@ module.exports = Self => {
require('../methods/worker/new')(Self); require('../methods/worker/new')(Self);
require('../methods/worker/deallocatePDA')(Self); require('../methods/worker/deallocatePDA')(Self);
require('../methods/worker/allocatePDA')(Self); require('../methods/worker/allocatePDA')(Self);
require('../methods/worker/signedPDA')(Self);
require('../methods/worker/signPdaPdf')(Self); require('../methods/worker/signPdaPdf')(Self);
require('../methods/worker/search')(Self); require('../methods/worker/search')(Self);
require('../methods/worker/isAuthorized')(Self); require('../methods/worker/isAuthorized')(Self);