5712-workerDms_integrateDocuware #1577
|
@ -1,5 +1,3 @@
|
||||||
const axios = require('axios');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('checkFile', {
|
Self.remoteMethod('checkFile', {
|
||||||
description: 'Check if exist docuware file',
|
description: 'Check if exist docuware file',
|
||||||
|
@ -73,17 +71,8 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = await Self.getOptions();
|
const response = await Self.get(fileCabinet, filter);
|
||||||
|
const [documents] = response.Items;
|
||||||
const fileCabinetId = await Self.getFileCabinet(fileCabinet);
|
|
||||||
const dialogId = await Self.getDialog(fileCabinet, action, fileCabinetId);
|
|
||||||
|
|
||||||
const response = await axios.post(
|
|
||||||
`${options.url}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`,
|
|
||||||
filter,
|
|
||||||
options.headers
|
|
||||||
);
|
|
||||||
const [documents] = response.data.Items;
|
|
||||||
if (!documents) return false;
|
if (!documents) return false;
|
||||||
|
|
||||||
return {id: documents.Id};
|
return {id: documents.Id};
|
||||||
|
|
|
@ -32,10 +32,13 @@ module.exports = Self => {
|
||||||
* @return {number} - The fileCabinet id
|
* @return {number} - The fileCabinet id
|
||||||
*/
|
*/
|
||||||
Self.getDialog = async(code, action, fileCabinetId) => {
|
Self.getDialog = async(code, action, fileCabinetId) => {
|
||||||
|
if (!process.env.NODE_ENV)
|
||||||
|
return Math.floor(Math.random() + 100);
|
||||||
|
|
||||||
const docuwareInfo = await Self.app.models.Docuware.findOne({
|
const docuwareInfo = await Self.app.models.Docuware.findOne({
|
||||||
where: {
|
where: {
|
||||||
code: code,
|
code,
|
||||||
action: action
|
action
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!fileCabinetId) fileCabinetId = await Self.getFileCabinet(code);
|
if (!fileCabinetId) fileCabinetId = await Self.getFileCabinet(code);
|
||||||
|
@ -56,10 +59,13 @@ module.exports = Self => {
|
||||||
* @return {number} - The fileCabinet id
|
* @return {number} - The fileCabinet id
|
||||||
*/
|
*/
|
||||||
Self.getFileCabinet = async code => {
|
Self.getFileCabinet = async code => {
|
||||||
|
if (!process.env.NODE_ENV)
|
||||||
|
return Math.floor(Math.random() + 100);
|
||||||
|
|
||||||
const options = await Self.getOptions();
|
const options = await Self.getOptions();
|
||||||
const docuwareInfo = await Self.app.models.Docuware.findOne({
|
const docuwareInfo = await Self.app.models.Docuware.findOne({
|
||||||
where: {
|
where: {
|
||||||
code: code
|
code
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -79,6 +85,8 @@ module.exports = Self => {
|
||||||
* @return {object} - The data
|
* @return {object} - The data
|
||||||
*/
|
*/
|
||||||
Self.get = async(code, filter, parse) => {
|
Self.get = async(code, filter, parse) => {
|
||||||
|
if (!process.env.NODE_ENV) return;
|
||||||
|
|
||||||
const options = await Self.getOptions();
|
const options = await Self.getOptions();
|
||||||
const fileCabinetId = await Self.getFileCabinet(code);
|
const fileCabinetId = await Self.getFileCabinet(code);
|
||||||
const dialogId = await Self.getDialog(code, 'find', fileCabinetId);
|
const dialogId = await Self.getDialog(code, 'find', fileCabinetId);
|
||||||
|
@ -100,10 +108,12 @@ module.exports = Self => {
|
||||||
* @return {object} - The data
|
* @return {object} - The data
|
||||||
*/
|
*/
|
||||||
Self.getById = async(code, id, parse) => {
|
Self.getById = async(code, id, parse) => {
|
||||||
|
if (!process.env.NODE_ENV) return;
|
||||||
|
|
||||||
const docuwareInfo = await Self.app.models.Docuware.findOne({
|
const docuwareInfo = await Self.app.models.Docuware.findOne({
|
||||||
fields: ['findById'],
|
fields: ['findById'],
|
||||||
where: {
|
where: {
|
||||||
code: code,
|
code,
|
||||||
action: 'find'
|
action: 'find'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,57 +1,15 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
const axios = require('axios');
|
|
||||||
|
|
||||||
describe('docuware download()', () => {
|
describe('docuware download()', () => {
|
||||||
const ticketId = 1;
|
const ticketId = 1;
|
||||||
const userId = 9;
|
|
||||||
const ctx = {
|
|
||||||
req: {
|
|
||||||
|
|
||||||
accessToken: {userId: userId},
|
|
||||||
headers: {origin: 'http://localhost:5000'},
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const docuwareModel = models.Docuware;
|
const docuwareModel = models.Docuware;
|
||||||
const fileCabinetName = 'deliveryNote';
|
const fileCabinetName = 'deliveryNote';
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
spyOn(docuwareModel, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
|
||||||
spyOn(docuwareModel, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false if there are no documents', async() => {
|
it('should return false if there are no documents', async() => {
|
||||||
const response = {
|
spyOn(docuwareModel, 'get').and.returnValue((new Promise(resolve => resolve({Items: []}))));
|
||||||
data: {
|
|
||||||
Items: []
|
|
||||||
}
|
|
||||||
};
|
|
||||||
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(response)));
|
|
||||||
|
|
||||||
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, true);
|
const result = await models.Docuware.checkFile(ticketId, fileCabinetName, null, true);
|
||||||
|
|
||||||
expect(result).toEqual(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false if the document is unsigned', async() => {
|
|
||||||
const response = {
|
|
||||||
data: {
|
|
||||||
Items: [
|
|
||||||
{
|
|
||||||
Id: 1,
|
|
||||||
Fields: [
|
|
||||||
{
|
|
||||||
FieldName: 'ESTADO',
|
|
||||||
Item: 'Unsigned'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
};
|
|
||||||
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(response)));
|
|
||||||
|
|
||||||
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, true);
|
|
||||||
|
|
||||||
expect(result).toEqual(false);
|
expect(result).toEqual(false);
|
||||||
});
|
});
|
||||||
|
@ -59,7 +17,6 @@ describe('docuware download()', () => {
|
||||||
it('should return the document data', async() => {
|
it('should return the document data', async() => {
|
||||||
const docuwareId = 1;
|
const docuwareId = 1;
|
||||||
const response = {
|
const response = {
|
||||||
data: {
|
|
||||||
Items: [
|
Items: [
|
||||||
{
|
{
|
||||||
Id: docuwareId,
|
Id: docuwareId,
|
||||||
|
@ -71,11 +28,10 @@ describe('docuware download()', () => {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
|
||||||
};
|
};
|
||||||
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(response)));
|
spyOn(docuwareModel, 'get').and.returnValue((new Promise(resolve => resolve(response))));
|
||||||
|
|
||||||
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, true);
|
const result = await models.Docuware.checkFile(ticketId, fileCabinetName, null, true);
|
||||||
|
|
||||||
expect(result.id).toEqual(docuwareId);
|
expect(result.id).toEqual(docuwareId);
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,135 @@
|
||||||
|
const axios = require('axios');
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('Docuware core', () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
process.env.NODE_ENV = 'testing';
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
delete process.env.NODE_ENV;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getOptions()', () => {
|
||||||
|
it('should return url and headers', async() => {
|
||||||
|
const result = await models.Docuware.getOptions();
|
||||||
|
|
||||||
|
expect(result.url).toBeDefined();
|
||||||
|
expect(result.headers).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getDialog()', () => {
|
||||||
|
it('should return dialogId', async() => {
|
||||||
|
const dialogs = {
|
||||||
|
data: {
|
||||||
|
Dialog: [
|
||||||
|
{
|
||||||
|
DisplayName: 'find',
|
||||||
|
Id: 'getDialogTest'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs)));
|
||||||
|
const result = await models.Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId');
|
||||||
|
|
||||||
|
expect(result).toEqual('getDialogTest');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getFileCabinet()', () => {
|
||||||
|
it('should return fileCabinetId', async() => {
|
||||||
|
const code = 'deliveryNote';
|
||||||
|
const docuwareInfo = await models.Docuware.findOne({
|
||||||
|
where: {
|
||||||
|
code
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const dialogs = {
|
||||||
|
data: {
|
||||||
|
FileCabinet: [
|
||||||
|
{
|
||||||
|
Name: docuwareInfo.fileCabinetName,
|
||||||
|
Id: 'getFileCabinetTest'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs)));
|
||||||
|
const result = await models.Docuware.getFileCabinet(code);
|
||||||
|
|
||||||
|
expect(result).toEqual('getFileCabinetTest');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('get()', () => {
|
||||||
|
it('should return data without parse', async() => {
|
||||||
|
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||||
|
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||||
|
const data = {
|
||||||
|
data: {
|
||||||
|
id: 1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
|
||||||
|
const result = await models.Docuware.get('deliveryNote');
|
||||||
|
|
||||||
|
expect(result.id).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return data with parse', async() => {
|
||||||
|
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||||
|
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||||
|
const data = {
|
||||||
|
data: {
|
||||||
|
Items: [{
|
||||||
|
Fields: [
|
||||||
|
{
|
||||||
|
ItemElementName: 'integer',
|
||||||
|
FieldLabel: 'firstRequiredField',
|
||||||
|
Item: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ItemElementName: 'string',
|
||||||
|
FieldLabel: 'secondRequiredField',
|
||||||
|
Item: 'myName'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ItemElementName: 'integer',
|
||||||
|
FieldLabel: 'notRequiredField',
|
||||||
|
Item: 2
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const parse = {
|
||||||
|
'firstRequiredField': 'id',
|
||||||
|
'secondRequiredField': 'name',
|
||||||
|
};
|
||||||
|
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
|
||||||
|
const [result] = await models.Docuware.get('deliveryNote', null, parse);
|
||||||
|
|
||||||
|
expect(result.id).toEqual(1);
|
||||||
|
expect(result.name).toEqual('myName');
|
||||||
|
expect(result.notRequiredField).not.toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getById()', () => {
|
||||||
|
it('should return data', async() => {
|
||||||
|
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||||
|
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||||
|
const data = {
|
||||||
|
data: {
|
||||||
|
id: 1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
|
||||||
|
const result = await models.Docuware.getById('deliveryNote', 1);
|
||||||
|
|
||||||
|
expect(result.id).toEqual(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -39,7 +39,7 @@ describe('docuware download()', () => {
|
||||||
spyOn(docuwareModel, 'checkFile').and.returnValue({});
|
spyOn(docuwareModel, 'checkFile').and.returnValue({});
|
||||||
spyOn(axios, 'get').and.returnValue(new stream.PassThrough({objectMode: true}));
|
spyOn(axios, 'get').and.returnValue(new stream.PassThrough({objectMode: true}));
|
||||||
|
|
||||||
const result = await models.Docuware.download(ctx, ticketId, fileCabinetName);
|
const result = await models.Docuware.download(ticketId, fileCabinetName);
|
||||||
|
|
||||||
expect(result[1]).toEqual('application/pdf');
|
expect(result[1]).toEqual('application/pdf');
|
||||||
expect(result[2]).toEqual(`filename="${ticketId}.pdf"`);
|
expect(result[2]).toEqual(`filename="${ticketId}.pdf"`);
|
||||||
|
|
|
@ -2,7 +2,7 @@ ALTER TABLE `vn`.`docuware` ADD dmsTypeFk INT(11) DEFAULT NULL NULL;
|
||||||
ALTER TABLE `vn`.`docuware` ADD CONSTRAINT docuware_FK FOREIGN KEY (dmsTypeFk) REFERENCES `vn`.`dmsType`(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
ALTER TABLE `vn`.`docuware` ADD CONSTRAINT docuware_FK FOREIGN KEY (dmsTypeFk) REFERENCES `vn`.`dmsType`(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
INSERT INTO `vn`.`docuware` (code, fileCabinetName, `action`, dialogName, findById, dmsTypeFk)
|
INSERT INTO `vn`.`docuware` (code, fileCabinetName, `action`, dialogName, findById, dmsTypeFk)
|
||||||
VALUES
|
VALUES
|
||||||
('hr', 'RRHH', 'find', 'Búsqueda', 'N__DOCUMENTO', NULL);
|
('hr', 'RRHH', 'find', 'Búsqueda', 'N__DOCUMENTO', NULL); -- set dmsTypeFk 3 when deploy in production
|
||||||
|
|
||||||
INSERT INTO `salix`.`url` (appName, environment, url)
|
INSERT INTO `salix`.`url` (appName, environment, url)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('docuwareDownload', {
|
Self.remoteMethod('docuwareDownload', {
|
||||||
description: 'Download a ticket delivery note document',
|
description: 'Download a ticket delivery note document',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [
|
accepts: [
|
||||||
|
@ -31,7 +31,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.docuwareDownload = async function(ctx, id) {
|
Self.docuwareDownload = async id => {
|
||||||
const filter = {
|
const filter = {
|
||||||
condition: [
|
condition: [
|
||||||
{
|
{
|
||||||
|
@ -50,6 +50,6 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
return await Self.app.models.Docuware.download(id, 'deliveryNote', filter);
|
return Self.app.models.Docuware.download(id, 'deliveryNote', filter);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('docuwareDownload', {
|
Self.remoteMethod('docuwareDownload', {
|
||||||
description: 'Download a worker document',
|
description: 'Download a worker document',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [
|
accepts: [
|
||||||
|
@ -31,7 +31,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.docuwareDownload = async function(ctx, id) {
|
Self.docuwareDownload = async id => {
|
||||||
const filter = {
|
const filter = {
|
||||||
condition: [
|
condition: [
|
||||||
{
|
{
|
||||||
|
@ -40,6 +40,6 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
return await Self.app.models.Docuware.download(id, 'hr', filter);
|
return Self.app.models.Docuware.download(id, 'hr', filter);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,8 +62,8 @@ module.exports = Self => {
|
||||||
where: {code: 'hr', action: 'find'}
|
where: {code: 'hr', action: 'find'}
|
||||||
});
|
});
|
||||||
const docuwareDmsType = docuware.dmsTypeFk;
|
const docuwareDmsType = docuware.dmsTypeFk;
|
||||||
let workerDocuware;
|
let workerDocuware = [];
|
||||||
if (!(docuwareDmsType && !await models.DmsType.hasReadRole(ctx, docuwareDmsType))) {
|
if (!docuwareDmsType || (docuwareDmsType && await models.DmsType.hasReadRole(ctx, docuwareDmsType))) {
|
||||||
const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']});
|
const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']});
|
||||||
const docuwareParse = {
|
const docuwareParse = {
|
||||||
'Filename': 'dmsFk',
|
'Filename': 'dmsFk',
|
||||||
|
@ -86,7 +86,6 @@ module.exports = Self => {
|
||||||
document = Object.assign(document, defaultData);
|
document = Object.assign(document, defaultData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return workerDms.concat(workerDocuware);
|
return workerDms.concat(workerDocuware);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue