Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 7828-makeCorrectCalls
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-09-12 09:55:03 +02:00
commit 6f81ca08db
10 changed files with 53 additions and 44 deletions

View File

@ -2488,7 +2488,7 @@ INSERT INTO `vn`.`clientDms`(`clientFk`, `dmsFk`)
(1104, 2),
(1104, 3);
INSERT INTO `vn`.`workerDocument`(`id`, `worker`, `document`,`isReadableByWorker`)
INSERT INTO `vn`.`workerDms`(`id`, `workerFk`, `dmsFk`,`isReadableByWorker`)
VALUES
(1, 1106, 4, TRUE),
(2, 1107, 3, FALSE);

View File

@ -1,11 +1,11 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDocument_afterDelete`
AFTER DELETE ON `workerDocument`
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDms_afterDelete`
AFTER DELETE ON `workerDms`
FOR EACH ROW
BEGIN
INSERT INTO workerLog
SET `action` = 'delete',
`changedModel` = 'WorkerDocument',
`changedModel` = 'WorkerDms',
`changedModelId` = OLD.id,
`userFk` = account.myUser_getId();
END$$

View File

@ -1,6 +1,6 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDocument_beforeInsert`
BEFORE INSERT ON `workerDocument`
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDms_beforeInsert`
BEFORE INSERT ON `workerDms`
FOR EACH ROW
BEGIN
SET NEW.editorFk = account.myUser_getId();

View File

@ -1,6 +1,6 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDocument_beforeUpdate`
BEFORE UPDATE ON `workerDocument`
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDms_beforeUpdate`
BEFORE UPDATE ON `workerDms`
FOR EACH ROW
BEGIN
SET NEW.editorFk = account.myUser_getId();

View File

@ -0,0 +1 @@
ALTER TABLE vn.workerDocument CHANGE worker workerFk int(10) unsigned DEFAULT NULL NULL;

View File

@ -0,0 +1 @@
ALTER TABLE vn.workerDocument CHANGE document dmsFk int(11) DEFAULT NULL NULL;

View File

@ -0,0 +1 @@
RENAME TABLE vn.workerDocument TO vn.workerDms;

View File

@ -8,19 +8,19 @@ module.exports = Self => {
accepts: [
{
arg: 'id',
type: 'Number',
type: 'number',
description: 'The worker id',
http: {source: 'path'}
},
{
arg: 'filter',
type: 'Object',
type: 'object',
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
http: {source: 'query'}
}
],
returns: {
type: ['Object'],
type: ['object'],
root: true
},
http: {
@ -36,38 +36,50 @@ module.exports = Self => {
// Get ids alloweds
const account = await models.VnUser.findById(userId);
const stmt = new ParameterizedSQL(
`SELECT d.id, d.id dmsFk
FROM workerDocument wd
JOIN dms d ON d.id = wd.document
FROM workerDms wd
JOIN dms d ON d.id = wd.dmsFk
JOIN dmsType dt ON dt.id = d.dmsTypeFk
LEFT JOIN account.roleRole rr ON rr.inheritsFrom = dt.readRoleFk AND rr.role = ?
LEFT JOIN account.roleRole rr ON rr.inheritsFrom = dt.readRoleFk
AND rr.role = ?
`, [account.roleFk]
);
const yourOwnDms = {and: [{isReadableByWorker: true}, {worker: userId}]};
const where = {
or: [yourOwnDms, {
const yourOwnDms = {
or: [
{and: [
{isReadableByWorker: true},
{worker: userId}
]},
{
role: {
neq: null
}
}]
};
stmt.merge(conn.makeSuffix(mergeWhere(filter.where, where)));
// Get workerDms alloweds
const where = mergeWhere(filter.where, yourOwnDms);
stmt.merge(conn.makeSuffix({where}));
const dmsIds = await conn.executeStmt(stmt);
const allowedIds = dmsIds.map(dms => dms.id);
const allowedFilter = mergeFilters(filter, {where: {dmsFk: {inq: allowedIds}, workerFk: id}});
let workerDms = await models.WorkerDms.find(allowedFilter);
// Get docuware info
const docuware = await models.Docuware.findOne({
const workerDms = await models.WorkerDms.find(allowedFilter);
const workerDocuware = filter.skip ? [] : await getDocuware(ctx, id);
return workerDms.concat(workerDocuware);
async function getDocuware(ctx, id) {
const {dmsTypeFk} = await models.Docuware.findOne({
fields: ['dmsTypeFk'],
where: {code: 'hr', action: 'find'}
});
const docuwareDmsType = docuware.dmsTypeFk;
if (!await models.DmsType.hasReadRole(ctx, dmsTypeFk)) return [];
let workerDocuware = [];
if (!filter.skip && (!docuwareDmsType || (docuwareDmsType && await models.DmsType.hasReadRole(ctx, docuwareDmsType)))) {
const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']});
const docuwareParse = {
'Filename': 'dmsFk',
@ -105,7 +117,7 @@ module.exports = Self => {
};
Object.assign(document, defaultData);
}
return workerDocuware;
}
return workerDms.concat(workerDocuware);
};
};

View File

@ -6,7 +6,7 @@
},
"options": {
"mysql": {
"table": "workerDocument"
"table": "workerDms"
}
},
"properties": {
@ -16,17 +16,11 @@
},
"dmsFk": {
"type": "number",
"required": true,
"mysql": {
"columnName": "document"
}
"required": true
},
"workerFk": {
"type": "number",
"required": true,
"mysql": {
"columnName": "worker"
}
"required": true
},
"isReadableByWorker": {
"type": "boolean"

View File

@ -375,7 +375,7 @@ localFixtures:
- workerBosses
- workerBusinessType
- workerConfig
- workerDocument
- workerDms
- workerLog
- workerMana
- workerManaExcluded