7525-devToTest #2542

Merged
alexm merged 231 commits from 7525-devToTest into test 2024-06-04 07:59:34 +00:00
15 changed files with 164 additions and 9 deletions
Showing only changes of commit 8b6844b9f0 - Show all commits

View File

@ -1,3 +1,4 @@
# Changelog
All notable changes to this project will be documented in this file.

View File

@ -54,6 +54,12 @@ For end-to-end tests run from project's root.
$ npm run test:e2e
```
## Generate changeLog test → master
```
$ bash changelog.sh
```
## Visual Studio Code extensions
Open Visual Studio Code, press Ctrl+P and paste the following commands.

34
changelog.sh Normal file
View File

@ -0,0 +1,34 @@
features_types=(chore feat style)
changes_types=(refactor perf)
fix_types=(fix revert)
file="CHANGELOG.md"
file_tmp="temp_log.txt"
file_current_tmp="temp_current_log.txt"
setType(){
echo "### $1" >> $file_tmp
arr=("$@")
echo "" > $file_current_tmp
for i in "${arr[@]}"
do
git log --grep="$i" --oneline --no-merges --format="- %s %d by:%an" master..test >> $file_current_tmp
done
# remove duplicates
sort -o $file_current_tmp -u $file_current_tmp
cat $file_current_tmp >> $file_tmp
echo "" >> $file_tmp
# remove tmp current file
[ -e $file_current_tmp ] && rm $file_current_tmp
}
echo "# Version XX.XX - XXXX-XX-XX" >> $file_tmp
echo "" >> $file_tmp
setType "Added 🆕" "${features_types[@]}"
setType "Changed 📦" "${changes_types[@]}"
setType "Fixed 🛠️" "${fix_types[@]}"
cat $file >> $file_tmp
mv $file_tmp $file

View File

@ -0,0 +1,24 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_checkMultipleDevice`(
vSelf INT
)
BEGIN
/**
* Verify if a worker has multiple assigned devices,
* except for freelancers.
*
* @param vUserFk worker id.
*/
DECLARE vHasPda BOOLEAN;
DECLARE vIsFreelance BOOLEAN;
DECLARE vMaxDevicesPerUser INT;
SELECT COUNT(*) INTO vHasPda FROM deviceProductionUser WHERE userFk = vSelf;
SELECT IFNULL(isFreelance, FALSE) INTO vIsFreelance FROM worker WHERE id = vSelf;
SELECT IFNULL(maxDevicesPerUser, FALSE) INTO vMaxDevicesPerUser FROM deviceProductionConfig LIMIT 1;
IF NOT vIsFreelance AND vHasPda > vMaxDevicesPerUser THEN
CALL util.throw('You can only have one PDA');
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,8 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`deviceProductionUser_afterInsert`
AFTER INSERT ON `deviceProductionUser`
FOR EACH ROW
BEGIN
CALL worker_checkMultipleDevice(NEW.userFk);
END$$
DELIMITER ;

View File

@ -3,6 +3,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`deviceProductionUser_
BEFORE UPDATE ON `deviceProductionUser`
FOR EACH ROW
BEGIN
CALL worker_checkMultipleDevice(NEW.userFk);
SET NEW.editorFk = account.myUser_getId();
END$$
DELIMITER ;

View File

@ -37,7 +37,7 @@ FROM (
)
JOIN `vn`.`volumeConfig` `vc`
)
JOIN `vn`.`itemCost` `ic` ON(
JOIN `vn`.`itemCost` `ic` FORCE INDEX (`PRIMARY`) ON(
`ic`.`itemFk` = `s`.`itemFk`
AND `ic`.`warehouseFk` = `t`.`warehouseFk`
)

View File

@ -0,0 +1,21 @@
ALTER TABLE vn.deviceProductionUser DROP INDEX IF EXISTS deviceProductionUser_UN;
ALTER TABLE vn.deviceProductionUser DROP FOREIGN KEY IF EXISTS deviceProductionUser_FK;
ALTER TABLE vn.deviceProductionUser DROP PRIMARY KEY;
ALTER TABLE vn.deviceProductionUser ADD IF NOT EXISTS id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY FIRST;
ALTER TABLE vn.deviceProductionUser ADD CONSTRAINT deviceProductionUser_deviceProduction_FK FOREIGN KEY IF NOT EXISTS (deviceProductionFk) REFERENCES vn.deviceProduction(id);
ALTER TABLE vn.deviceProductionUser ADD CONSTRAINT deviceProductionUser_unique UNIQUE KEY IF NOT EXISTS (deviceProductionFk);
ALTER TABLE vn.deviceProductionUser ADD IF NOT EXISTS simSerialNumber TEXT NULL;
ALTER TABLE vn.deviceProductionConfig ADD IF NOT EXISTS maxDevicesPerUser INT UNSIGNED NULL;
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",
"There are not picking tickets": "There are not picking tickets",
"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",
"They're not your subordinate": "They're not your subordinate",
"InvoiceIn is already booked": "InvoiceIn is already booked"
}
"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",
"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",
"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",
"Select ticket or client": "Elija un ticket o un client",
"It was not able to create the invoice": "No se pudo crear la factura"
}
"Select ticket or client": "Elija un ticket o un client",
"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,23 @@
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() => {
return Self.app.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()', () => {
it('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

@ -14,6 +14,10 @@
}
},
"properties": {
"id": {
"type": "number",
"id": true
},
"deviceProductionFk": {
"type": "number",
"id": true
@ -21,6 +25,9 @@
"userFk": {
"type": "number"
},
"simSerialNumber": {
"type": "string"
},
"created": {
"type": "date"
}
@ -28,7 +35,7 @@
"relations": {
"deviceProduction": {
"type": "belongsTo",
"model": "DeviceProduction",
"model": "DeviceProduction",
"foreignKey": "deviceProductionFk"
},
"user": {
@ -36,5 +43,10 @@
"model": "User",
"foreignKey": "userFk"
}
},
"scope": {
"include":{
"relation": "deviceProduction"
}
}
}

View File

@ -20,6 +20,7 @@ module.exports = Self => {
require('../methods/worker/search')(Self);
require('../methods/worker/isAuthorized')(Self);
require('../methods/worker/setPassword')(Self);
require('../methods/worker/getAvailablePda')(Self);
Self.validateAsync('fi', tinIsValid, {
message: 'Invalid TIN'