Compare commits
13 Commits
faecbbb373
...
0e2dcbce0c
Author | SHA1 | Date |
---|---|---|
Robert Ferrús | 0e2dcbce0c | |
Alex Moreno | 76415e507d | |
Alex Moreno | c355fcfece | |
Alex Moreno | ccaec1a2cf | |
Sergio De la torre | 15622a3e68 | |
Sergio De la torre | 12abca0a2d | |
Sergio De la torre | 2adc424ccb | |
Sergio De la torre | b592ccc162 | |
Alex Moreno | b1b36a33a0 | |
Alex Moreno | 3c881d5e48 | |
Alex Moreno | 394cf0d18b | |
Alex Moreno | 9695fea48f | |
Alex Moreno | 952f8f3dfc |
|
@ -62,7 +62,8 @@ module.exports = Self => {
|
||||||
p.code parkingCodePrevia,
|
p.code parkingCodePrevia,
|
||||||
p.pickingOrder pickingOrderPrevia,
|
p.pickingOrder pickingOrderPrevia,
|
||||||
iss.id itemShelvingSaleFk,
|
iss.id itemShelvingSaleFk,
|
||||||
iss.isPicked
|
iss.isPicked,
|
||||||
|
iss.itemShelvingFk
|
||||||
FROM ticketCollection tc
|
FROM ticketCollection tc
|
||||||
LEFT JOIN collection c ON c.id = tc.collectionFk
|
LEFT JOIN collection c ON c.id = tc.collectionFk
|
||||||
JOIN sale s ON s.ticketFk = tc.ticketFk
|
JOIN sale s ON s.ticketFk = tc.ticketFk
|
||||||
|
@ -102,7 +103,8 @@ module.exports = Self => {
|
||||||
p.code,
|
p.code,
|
||||||
p.pickingOrder,
|
p.pickingOrder,
|
||||||
iss.id itemShelvingSaleFk,
|
iss.id itemShelvingSaleFk,
|
||||||
iss.isPicked
|
iss.isPicked,
|
||||||
|
iss.itemShelvingFk
|
||||||
FROM sectorCollection sc
|
FROM sectorCollection sc
|
||||||
JOIN sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id
|
JOIN sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id
|
||||||
JOIN saleGroup sg ON sg.id = ss.saleGroupFk
|
JOIN saleGroup sg ON sg.id = ss.saleGroupFk
|
||||||
|
|
|
@ -4,21 +4,45 @@ module.exports = Self => {
|
||||||
/**
|
/**
|
||||||
* Returns basic headers
|
* Returns basic headers
|
||||||
*
|
*
|
||||||
* @param {string} cookie - The docuware cookie
|
|
||||||
* @return {object} - The headers
|
* @return {object} - The headers
|
||||||
*/
|
*/
|
||||||
Self.getOptions = async() => {
|
Self.getOptions = async() => {
|
||||||
const docuwareConfig = await Self.app.models.DocuwareConfig.findOne();
|
const docuwareConfig = await Self.app.models.DocuwareConfig.findOne();
|
||||||
|
const now = Date.vnNow();
|
||||||
|
let {url, username, password, token, expired} = docuwareConfig;
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV && (!expired || expired < now + 60)) {
|
||||||
|
const {data: {IdentityServiceUrl}} = await axios.get(`${url}/Home/IdentityServiceInfo`);
|
||||||
|
const {data: {token_endpoint}} = await axios.get(`${IdentityServiceUrl}/.well-known/openid-configuration`);
|
||||||
|
const {data} = await axios.post(token_endpoint, {
|
||||||
|
grant_type: 'password',
|
||||||
|
scope: 'docuware.platform',
|
||||||
|
client_id: 'docuware.platform.net.client',
|
||||||
|
username,
|
||||||
|
password
|
||||||
|
}, {headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
}});
|
||||||
|
|
||||||
|
const newToken = data.access_token;
|
||||||
|
token = data.token_type + ' ' + newToken;
|
||||||
|
await docuwareConfig.updateAttributes({
|
||||||
|
token,
|
||||||
|
expired: now + data.expires_in
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Cookie': docuwareConfig.cookie
|
'Authorization': token
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url: docuwareConfig.url,
|
url,
|
||||||
headers
|
headers
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,26 +2,21 @@ const axios = require('axios');
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('Docuware core', () => {
|
describe('Docuware core', () => {
|
||||||
beforeAll(() => {
|
const fileCabinetCode = 'deliveryNote';
|
||||||
|
beforeAll(async() => {
|
||||||
process.env.NODE_ENV = 'testing';
|
process.env.NODE_ENV = 'testing';
|
||||||
|
|
||||||
|
const docuwareInfo = await models.Docuware.findOne({
|
||||||
|
where: {
|
||||||
|
code: fileCabinetCode
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
spyOn(axios, 'get').and.callFake(url => {
|
||||||
delete process.env.NODE_ENV;
|
if (url.includes('IdentityServiceInfo')) return {data: {IdentityServiceUrl: 'IdentityServiceUrl'}};
|
||||||
});
|
if (url.includes('IdentityServiceUrl')) return {data: {token_endpoint: 'token_endpoint'}};
|
||||||
|
if (url.includes('dialogs')) {
|
||||||
describe('getOptions()', () => {
|
return {
|
||||||
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: {
|
data: {
|
||||||
Dialog: [
|
Dialog: [
|
||||||
{
|
{
|
||||||
|
@ -31,58 +26,30 @@ describe('Docuware core', () => {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
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 = {
|
if (url.includes('FileCabinets')) {
|
||||||
data: {
|
return {data: {
|
||||||
FileCabinet: [
|
FileCabinet: [
|
||||||
{
|
{
|
||||||
Name: docuwareInfo.fileCabinetName,
|
Name: docuwareInfo.fileCabinetName,
|
||||||
Id: 'getFileCabinetTest'
|
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()', () => {
|
spyOn(axios, 'post').and.callFake(url => {
|
||||||
it('should return data without parse', async() => {
|
if (url.includes('token_endpoint')) {
|
||||||
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
return {data: {
|
||||||
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
access_token: 'access_token',
|
||||||
const data = {
|
token_type: 'bearer',
|
||||||
data: {
|
expires_in: 10000
|
||||||
id: 1
|
}};
|
||||||
}
|
}
|
||||||
};
|
if (url.includes('DialogExpression')) {
|
||||||
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
|
return {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: [{
|
Items: [{
|
||||||
Fields: [
|
Fields: [
|
||||||
{
|
{
|
||||||
|
@ -104,11 +71,51 @@ describe('Docuware core', () => {
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
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('Dialog()', () => {
|
||||||
|
it('should return dialogId', async() => {
|
||||||
|
const result = await models.Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId');
|
||||||
|
|
||||||
|
expect(result).toEqual('getDialogTest');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getFileCabinet()', () => {
|
||||||
|
it('should return fileCabinetId', async() => {
|
||||||
|
const result = await models.Docuware.getFileCabinet(fileCabinetCode);
|
||||||
|
|
||||||
|
expect(result).toEqual('getFileCabinetTest');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('get()', () => {
|
||||||
|
it('should return data without parse', async() => {
|
||||||
|
const [result] = await models.Docuware.get('deliveryNote');
|
||||||
|
|
||||||
|
expect(result.firstRequiredField).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return data with parse', async() => {
|
||||||
const parse = {
|
const parse = {
|
||||||
'firstRequiredField': 'id',
|
'firstRequiredField': 'id',
|
||||||
'secondRequiredField': 'name',
|
'secondRequiredField': 'name',
|
||||||
};
|
};
|
||||||
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
|
|
||||||
const [result] = await models.Docuware.get('deliveryNote', null, parse);
|
const [result] = await models.Docuware.get('deliveryNote', null, parse);
|
||||||
|
|
||||||
expect(result.id).toEqual(1);
|
expect(result.id).toEqual(1);
|
||||||
|
@ -119,17 +126,14 @@ describe('Docuware core', () => {
|
||||||
|
|
||||||
describe('getById()', () => {
|
describe('getById()', () => {
|
||||||
it('should return data', async() => {
|
it('should return data', async() => {
|
||||||
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
spyOn(models.Docuware, 'get');
|
||||||
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
await models.Docuware.getById('deliveryNote', 1);
|
||||||
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);
|
expect(models.Docuware.get).toHaveBeenCalledWith(
|
||||||
|
'deliveryNote',
|
||||||
|
{condition: [Object({DBName: 'N__ALBAR_N', Value: [1]})]},
|
||||||
|
undefined
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -143,7 +143,7 @@ module.exports = Self => {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'multipart/form-data',
|
'Content-Type': 'multipart/form-data',
|
||||||
'X-File-ModifiedDate': Date.vnNew(),
|
'X-File-ModifiedDate': Date.vnNew(),
|
||||||
'Cookie': docuwareOptions.headers.headers.Cookie,
|
'Authorization': docuwareOptions.headers.headers.Authorization,
|
||||||
...data.getHeaders()
|
...data.getHeaders()
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,17 +16,17 @@
|
||||||
"url": {
|
"url": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"cookie": {
|
"token": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"acls": [
|
"username": {
|
||||||
{
|
"type": "string"
|
||||||
"property": "*",
|
},
|
||||||
"accessType": "*",
|
"password": {
|
||||||
"principalType": "ROLE",
|
"type": "string"
|
||||||
"principalId": "$everyone",
|
},
|
||||||
"permission": "ALLOW"
|
"expired":{
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,10 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`itemShelvingSale_afterI
|
||||||
AFTER INSERT ON `itemShelvingSale`
|
AFTER INSERT ON `itemShelvingSale`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
UPDATE sale s
|
UPDATE sale s
|
||||||
JOIN operator o ON o.workerFk = account.myUser_getId()
|
JOIN operator o ON o.workerFk = account.myUser_getId()
|
||||||
SET s.isPicked = IF(o.isOnReservationMode, s.isPicked, TRUE)
|
JOIN sector se ON se.id = o.sectorFk
|
||||||
WHERE id = NEW.saleFk;
|
SET s.isPicked = IF(IFNULL(se.isOnReservationMode, o.isOnReservationMode), s.isPicked, TRUE)
|
||||||
|
WHERE s.id = NEW.saleFk;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
|
@ -0,0 +1,4 @@
|
||||||
|
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS username varchar(100) NULL;
|
||||||
|
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS password varchar(100) NULL;
|
||||||
|
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS token text NULL;
|
||||||
|
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS expired int(11) NULL;
|
Loading…
Reference in New Issue