8062-testToMaster_2 #3059
|
@ -2488,7 +2488,7 @@ INSERT INTO `vn`.`clientDms`(`clientFk`, `dmsFk`)
|
||||||
(1104, 2),
|
(1104, 2),
|
||||||
(1104, 3);
|
(1104, 3);
|
||||||
|
|
||||||
INSERT INTO `vn`.`workerDocument`(`id`, `worker`, `document`,`isReadableByWorker`)
|
INSERT INTO `vn`.`workerDms`(`id`, `workerFk`, `dmsFk`,`isReadableByWorker`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 1106, 4, TRUE),
|
(1, 1106, 4, TRUE),
|
||||||
(2, 1107, 3, FALSE);
|
(2, 1107, 3, FALSE);
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDocument_afterDelete`
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDms_afterDelete`
|
||||||
AFTER DELETE ON `workerDocument`
|
AFTER DELETE ON `workerDms`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO workerLog
|
INSERT INTO workerLog
|
||||||
SET `action` = 'delete',
|
SET `action` = 'delete',
|
||||||
`changedModel` = 'WorkerDocument',
|
`changedModel` = 'WorkerDms',
|
||||||
`changedModelId` = OLD.id,
|
`changedModelId` = OLD.id,
|
||||||
`userFk` = account.myUser_getId();
|
`userFk` = account.myUser_getId();
|
||||||
END$$
|
END$$
|
|
@ -1,6 +1,6 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDocument_beforeInsert`
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDms_beforeInsert`
|
||||||
BEFORE INSERT ON `workerDocument`
|
BEFORE INSERT ON `workerDms`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NEW.editorFk = account.myUser_getId();
|
SET NEW.editorFk = account.myUser_getId();
|
|
@ -1,6 +1,6 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDocument_beforeUpdate`
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDms_beforeUpdate`
|
||||||
BEFORE UPDATE ON `workerDocument`
|
BEFORE UPDATE ON `workerDms`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NEW.editorFk = account.myUser_getId();
|
SET NEW.editorFk = account.myUser_getId();
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE vn.workerDocument CHANGE worker workerFk int(10) unsigned DEFAULT NULL NULL;
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE vn.workerDocument CHANGE document dmsFk int(11) DEFAULT NULL NULL;
|
|
@ -0,0 +1 @@
|
||||||
|
RENAME TABLE vn.workerDocument TO vn.workerDms;
|
|
@ -8,19 +8,19 @@ module.exports = Self => {
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
type: 'Number',
|
type: 'number',
|
||||||
description: 'The worker id',
|
description: 'The worker id',
|
||||||
http: {source: 'path'}
|
http: {source: 'path'}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'filter',
|
arg: 'filter',
|
||||||
type: 'Object',
|
type: 'object',
|
||||||
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
||||||
http: {source: 'query'}
|
http: {source: 'query'}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
type: ['Object'],
|
type: ['object'],
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
|
@ -36,38 +36,50 @@ module.exports = Self => {
|
||||||
|
|
||||||
// Get ids alloweds
|
// Get ids alloweds
|
||||||
const account = await models.VnUser.findById(userId);
|
const account = await models.VnUser.findById(userId);
|
||||||
|
|
||||||
const stmt = new ParameterizedSQL(
|
const stmt = new ParameterizedSQL(
|
||||||
`SELECT d.id, d.id dmsFk
|
`SELECT d.id, d.id dmsFk
|
||||||
FROM workerDocument wd
|
FROM workerDms wd
|
||||||
JOIN dms d ON d.id = wd.document
|
JOIN dms d ON d.id = wd.dmsFk
|
||||||
JOIN dmsType dt ON dt.id = d.dmsTypeFk
|
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]
|
`, [account.roleFk]
|
||||||
);
|
);
|
||||||
const yourOwnDms = {and: [{isReadableByWorker: true}, {worker: userId}]};
|
const yourOwnDms = {
|
||||||
const where = {
|
or: [
|
||||||
or: [yourOwnDms, {
|
{and: [
|
||||||
role: {
|
{isReadableByWorker: true},
|
||||||
neq: null
|
{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 dmsIds = await conn.executeStmt(stmt);
|
||||||
|
|
||||||
const allowedIds = dmsIds.map(dms => dms.id);
|
const allowedIds = dmsIds.map(dms => dms.id);
|
||||||
const allowedFilter = mergeFilters(filter, {where: {dmsFk: {inq: allowedIds}, workerFk: id}});
|
const allowedFilter = mergeFilters(filter, {where: {dmsFk: {inq: allowedIds}, workerFk: id}});
|
||||||
let workerDms = await models.WorkerDms.find(allowedFilter);
|
|
||||||
|
|
||||||
// Get docuware info
|
const workerDms = await models.WorkerDms.find(allowedFilter);
|
||||||
const docuware = await models.Docuware.findOne({
|
|
||||||
fields: ['dmsTypeFk'],
|
const workerDocuware = filter.skip ? [] : await getDocuware(ctx, id);
|
||||||
where: {code: 'hr', action: 'find'}
|
return workerDms.concat(workerDocuware);
|
||||||
});
|
|
||||||
const docuwareDmsType = docuware.dmsTypeFk;
|
async function getDocuware(ctx, id) {
|
||||||
let workerDocuware = [];
|
const {dmsTypeFk} = await models.Docuware.findOne({
|
||||||
if (!filter.skip && (!docuwareDmsType || (docuwareDmsType && await models.DmsType.hasReadRole(ctx, docuwareDmsType)))) {
|
fields: ['dmsTypeFk'],
|
||||||
|
where: {code: 'hr', action: 'find'}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!await models.DmsType.hasReadRole(ctx, dmsTypeFk)) return [];
|
||||||
|
|
||||||
|
let workerDocuware = [];
|
||||||
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',
|
||||||
|
@ -80,7 +92,7 @@ module.exports = Self => {
|
||||||
};
|
};
|
||||||
|
|
||||||
workerDocuware =
|
workerDocuware =
|
||||||
await models.Docuware.getById('hr', worker.lastName + ' ' + worker.firstName, docuwareParse) ?? [];
|
await models.Docuware.getById('hr', worker.lastName + ' ' + worker.firstName, docuwareParse) ?? [];
|
||||||
const url = (await Self.app.models.Url.getUrl('docuware')) + 'WebClient';
|
const url = (await Self.app.models.Url.getUrl('docuware')) + 'WebClient';
|
||||||
for (document of workerDocuware) {
|
for (document of workerDocuware) {
|
||||||
const docuwareId = document.id;
|
const docuwareId = document.id;
|
||||||
|
@ -105,7 +117,7 @@ module.exports = Self => {
|
||||||
};
|
};
|
||||||
Object.assign(document, defaultData);
|
Object.assign(document, defaultData);
|
||||||
}
|
}
|
||||||
|
return workerDocuware;
|
||||||
}
|
}
|
||||||
return workerDms.concat(workerDocuware);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "workerDocument"
|
"table": "workerDms"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -16,17 +16,11 @@
|
||||||
},
|
},
|
||||||
"dmsFk": {
|
"dmsFk": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"required": true,
|
"required": true
|
||||||
"mysql": {
|
|
||||||
"columnName": "document"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"workerFk": {
|
"workerFk": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"required": true,
|
"required": true
|
||||||
"mysql": {
|
|
||||||
"columnName": "worker"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"isReadableByWorker": {
|
"isReadableByWorker": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
|
|
@ -375,7 +375,7 @@ localFixtures:
|
||||||
- workerBosses
|
- workerBosses
|
||||||
- workerBusinessType
|
- workerBusinessType
|
||||||
- workerConfig
|
- workerConfig
|
||||||
- workerDocument
|
- workerDms
|
||||||
- workerLog
|
- workerLog
|
||||||
- workerMana
|
- workerMana
|
||||||
- workerManaExcluded
|
- workerManaExcluded
|
||||||
|
|
Loading…
Reference in New Issue