feat: refs #7187 new method available pda
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Pablo Natek 2024-05-16 10:23:33 +02:00
parent a797fca2dd
commit bcb3ea4837
9 changed files with 67 additions and 9 deletions

View File

@ -15,3 +15,7 @@ ALTER TABLE vn.deviceProductionUser ADD IF NOT EXISTS simSerialNumber TEXT NULL;
ALTER TABLE vn.deviceProductionConfig ADD IF NOT EXISTS maxDevicesPerUser INT UNSIGNED NULL; ALTER TABLE vn.deviceProductionConfig ADD IF NOT EXISTS maxDevicesPerUser INT UNSIGNED NULL;
UPDATE vn.deviceProductionConfig SET maxDevicesPerUser=1 WHERE id=1; UPDATE vn.deviceProductionConfig SET maxDevicesPerUser=1 WHERE id=1;
INSERT IGNORE INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('Worker','getAvailablePda','READ','ALLOW','ROLE','hr');

View File

@ -223,7 +223,8 @@
"printerNotExists": "The printer does not exist", "printerNotExists": "The printer does not exist",
"There are not picking tickets": "There are not picking tickets", "There are not picking tickets": "There are not picking tickets",
"ticketCommercial": "The ticket {{ ticket }} for the salesperson {{ salesMan }} is in preparation. (automatically generated message)", "ticketCommercial": "The ticket {{ ticket }} for the salesperson {{ salesMan }} is in preparation. (automatically generated message)",
"This password can only be changed by the user themselves": "This password can only be changed by the user themselves", "This password can only be changed by the user themselves": "This password can only be changed by the user themselves",
"They're not your subordinate": "They're not your subordinate", "They're not your subordinate": "They're not your subordinate",
"InvoiceIn is already booked": "InvoiceIn is already booked" "InvoiceIn is already booked": "InvoiceIn is already booked",
} "This workCenter is already assigned to this agency": "This workCenter is already assigned to this agency"
}

View File

@ -355,6 +355,7 @@
"No results found": "No se han encontrado resultados", "No results found": "No se han encontrado resultados",
"InvoiceIn is already booked": "La factura recibida está contabilizada", "InvoiceIn is already booked": "La factura recibida está contabilizada",
"This workCenter is already assigned to this agency": "Este centro de trabajo ya está asignado a esta agencia", "This workCenter is already assigned to this agency": "Este centro de trabajo ya está asignado a esta agencia",
"Select ticket or client": "Elija un ticket o un client", "Select ticket or client": "Elija un ticket o un client",
"It was not able to create the invoice": "No se pudo crear la factura" "It was not able to create the invoice": "No se pudo crear la factura",
} "This PDA is already assigned to another user": "This PDA is already assigned to another user"
}

View File

@ -0,0 +1,25 @@
module.exports = Self => {
Self.remoteMethod('getAvailablePda', {
description: 'returns devices without user',
accessType: 'READ',
accepts: [],
returns: {
type: 'array',
root: true
},
http: {
path: `/getAvailablePda`,
verb: 'GET'
}
});
Self.getAvailablePda = async() => {
const models = Self.app.models;
return models.DeviceProduction.rawSql(
`SELECT d.*
FROM deviceProduction d
LEFT JOIN deviceProductionUser du ON du.deviceProductionFk = d.id
WHERE du.deviceProductionFk IS NULL`
);
};
};

View File

@ -0,0 +1,13 @@
const models = require('vn-loopback/server/server').models;
describe('worker getAvailablePda()', () => {
fit('should return a Pda that has no user assigned', async() => {
const [{id}] = await models.Worker.getAvailablePda();
const deviceProductionUser = await models.DeviceProductionUser.findOne({
where: {deviceProductionFk: id}
});
expect(!deviceProductionUser).toBeTruthy();
});
});

View File

@ -0,0 +1,8 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.rewriteDbError(function(err) {
if (err.code === 'ER_DUP_ENTRY')
return new UserError(`This PDA is already assigned to another user`);
return err;
});
};

View File

@ -34,9 +34,9 @@
}, },
"relations": { "relations": {
"deviceProduction": { "deviceProduction": {
"type": "belongsTo", "type": "hasOne",
"model": "DeviceProduction", "model": "DeviceProduction",
"foreignKey": "deviceProductionFk" "foreignKey": "id"
}, },
"user": { "user": {
"type": "belongsTo", "type": "belongsTo",

View File

@ -55,6 +55,11 @@
"type": "belongsTo", "type": "belongsTo",
"model": "DeviceProductionState", "model": "DeviceProductionState",
"foreignKey": "stateFk" "foreignKey": "stateFk"
},
"deviceProductionUser": {
"type": "hasMany",
"model": "DeviceProductionUser",
"foreignKey": "deviceProductionFk"
} }
} }
} }

View File

@ -20,6 +20,7 @@ module.exports = Self => {
require('../methods/worker/search')(Self); require('../methods/worker/search')(Self);
require('../methods/worker/isAuthorized')(Self); require('../methods/worker/isAuthorized')(Self);
require('../methods/worker/setPassword')(Self); require('../methods/worker/setPassword')(Self);
require('../methods/worker/getAvailablePda')(Self);
Self.validatesUniquenessOf('locker', { Self.validatesUniquenessOf('locker', {
message: 'This locker has already been assigned' message: 'This locker has already been assigned'