From d1214a998abd7636d862f0813634412f944ef184 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 6 Jun 2024 07:01:55 +0200 Subject: [PATCH 01/46] feat: login refs #6868 --- .../account/back/methods/account/login-app.js | 88 +++++++++++++++++++ modules/account/back/models/account.js | 1 + 2 files changed, 89 insertions(+) create mode 100644 modules/account/back/methods/account/login-app.js diff --git a/modules/account/back/methods/account/login-app.js b/modules/account/back/methods/account/login-app.js new file mode 100644 index 000000000..18543f90e --- /dev/null +++ b/modules/account/back/methods/account/login-app.js @@ -0,0 +1,88 @@ +const {setDefaultHighWaterMark} = require('form-data'); +const {setLocale} = require('i18n'); + +module.exports = Self => { + Self.remoteMethodCtx('loginApp', { + description: 'Login a user with username/email and password', + accepts: [ + { + arg: 'user', + type: 'String', + description: 'The user name or email', + required: true + }, { + arg: 'password', + type: 'String', + description: 'The password' + }, { + arg: 'deviceId', + type: 'String', + description: 'Device id' + }, { + arg: 'android_id', + type: 'String', + description: 'Android id' + }, { + arg: 'versionApp', + type: 'String', + description: 'Version app' + }, { + arg: 'nameApp', + type: 'String', + description: 'Version app' + }, { + arg: 'serialNumber', + type: 'String', + description: 'Serial number' + } + + ], + returns: { + type: 'object', + root: true + }, + http: { + path: `/loginApp`, + verb: 'POST' + } + }); + + Self.loginApp = async(ctx, user, password, deviceId, android_id, versionApp, nameApp, options) => { + const models = Self.app.models; + + const login = await Self.app.models.VnUser.signIn(ctx, user, password, options); + + const userId = login.user; + + const query = + `INSERT IGNORE INTO operator (workerFk) + VALUES (?);`; + + const insertOperator = await Self.rawSql(query, [userId], options); + + const [serialNumber] = await models.DeviceProductionUser.findOne({ + where: {id: '100'} + }); + + const insertDeviceLog = await models.DeviceLog.create( + { + 'android_id': android_id, + 'userFk': userId, + 'versionApp': versionApp, + 'nameApp': nameApp, + 'serialNumber': [serialNumber] + }, + options + ); + + const queryDeviceCheck = + `CALL device_checkLogin(?, ?)`; + + const [queryDeviceCheckLogin] = await Self.rawSql(queryDeviceCheck, [userId, android_id], options); + + if (!queryDeviceCheckLogin.vIsAuthorized) + throw new UserError('User not authorized'); + + return insertDeviceLog; + }; +}; diff --git a/modules/account/back/models/account.js b/modules/account/back/models/account.js index ceb26053c..f89d3079e 100644 --- a/modules/account/back/models/account.js +++ b/modules/account/back/models/account.js @@ -10,6 +10,7 @@ module.exports = Self => { require('../methods/account/logout')(Self); require('../methods/account/change-password')(Self); require('../methods/account/set-password')(Self); + require('../methods/account/login-app')(Self); Self.setUnverifiedPassword = async(id, pass, options) => { const {emailVerified} = await models.VnUser.findById(id, {fields: ['emailVerified']}, options); From 5c3ce40bbdfba57fa06f7b86f0cf4eebf23484bb Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 11 Jun 2024 07:12:47 +0200 Subject: [PATCH 02/46] feat login-app refs #6868 --- .../account/back/methods/account/login-app.js | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/modules/account/back/methods/account/login-app.js b/modules/account/back/methods/account/login-app.js index 18543f90e..3ade88fb8 100644 --- a/modules/account/back/methods/account/login-app.js +++ b/modules/account/back/methods/account/login-app.js @@ -49,40 +49,44 @@ module.exports = Self => { Self.loginApp = async(ctx, user, password, deviceId, android_id, versionApp, nameApp, options) => { const models = Self.app.models; + const myOptions = {}; + if (typeof options == 'object') + Object.assign(myOptions, options); - const login = await Self.app.models.VnUser.signIn(ctx, user, password, options); + await models.Account.login(ctx, user, password, myOptions); - const userId = login.user; + const userId = ctx.req.accessToken.userId; - const query = - `INSERT IGNORE INTO operator (workerFk) - VALUES (?);`; + const isUserInOperator = await models.Operator.findById(userId); + if (!isUserInOperator) + await models.Operator.create({'workerFk': userId}); - const insertOperator = await Self.rawSql(query, [userId], options); + const device = await models.DeviceProduction.findById(deviceId); - const [serialNumber] = await models.DeviceProductionUser.findOne({ - where: {id: '100'} - }); + // const [serialNumber] = await models.DeviceProductionUser.findOne({ + // where: {id: '100'} + // }); - const insertDeviceLog = await models.DeviceLog.create( - { - 'android_id': android_id, - 'userFk': userId, - 'versionApp': versionApp, - 'nameApp': nameApp, - 'serialNumber': [serialNumber] - }, - options - ); + // const insertDeviceLog = await models.DeviceLog.create( + // { + // 'android_id': android_id, + // 'userFk': userId, + // 'versionApp': versionApp, + // 'nameApp': nameApp, + // 'serialNumber': [serialNumber] + // }, + // options + // ); - const queryDeviceCheck = - `CALL device_checkLogin(?, ?)`; + // const queryDeviceCheck = + // `CALL device_checkLogin(?, ?)`; - const [queryDeviceCheckLogin] = await Self.rawSql(queryDeviceCheck, [userId, android_id], options); + // const [queryDeviceCheckLogin] = await Self.rawSql(queryDeviceCheck, [userId, android_id], options); - if (!queryDeviceCheckLogin.vIsAuthorized) - throw new UserError('User not authorized'); + // if (!queryDeviceCheckLogin.vIsAuthorized) + // throw new UserError('User not authorized'); - return insertDeviceLog; + // return insertDeviceLog; + return []; }; }; From 52b82603d22d4214282eaa216945423d6274ca86 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 13 Jun 2024 10:40:37 +0200 Subject: [PATCH 03/46] feat login-app refs #6868 --- .../account/back/methods/account/login-app.js | 54 +++++++++++++++---- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/modules/account/back/methods/account/login-app.js b/modules/account/back/methods/account/login-app.js index 3ade88fb8..5392f8eb2 100644 --- a/modules/account/back/methods/account/login-app.js +++ b/modules/account/back/methods/account/login-app.js @@ -1,5 +1,4 @@ -const {setDefaultHighWaterMark} = require('form-data'); -const {setLocale} = require('i18n'); +const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('loginApp', { @@ -53,20 +52,55 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - await models.Account.login(ctx, user, password, myOptions); + const login = await models.Account.login(ctx, user, password, myOptions); const userId = ctx.req.accessToken.userId; - const isUserInOperator = await models.Operator.findById(userId); - if (!isUserInOperator) - await models.Operator.create({'workerFk': userId}); + const resultCheckLogin = + await Self.rawSql('CALL vn.device_checkLogin(?, ?);', + [userId, android_id], myOptions); - const device = await models.DeviceProduction.findById(deviceId); + const [{vIsAuthorized, vMessage}] = resultCheckLogin[0]; - // const [serialNumber] = await models.DeviceProductionUser.findOne({ - // where: {id: '100'} - // }); + if (!vIsAuthorized) + throw new UserError('Not authorized'); + const isUserInOperator = await models.Operator.findOne({ + where: { + workerFk: userId + } + }); + + if (!isUserInOperator){ + await models.Operator.create({ 'workerFk': userId }); + + const getDataUser = await models.Operator.findOne({ + where: { + workerFk: userId + } + }); + + const resultDevice = await models.DeviceProduction.findOne({ + where: { + android_id: android_id + } + }); + + if (resultDevice) + serialNumber = resultDevice.serialNumber ?? ''; + + await models.DeviceLog.create({ + 'android_id': android_id, + 'userFk': userId, + 'nameApp': nameApp, + 'versionApp': versionApp, + 'serialNumber': serialNumber + }); + + + + console.log(vIsAuthorized); + console.log(vMessage); // const insertDeviceLog = await models.DeviceLog.create( // { // 'android_id': android_id, From 9d5d62afafd846b2f64989a24fb10f1d594964ed Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 17 Jun 2024 13:56:58 +0200 Subject: [PATCH 04/46] feat newLogin refs #6868 --- .../account/back/methods/account/login-app.js | 111 +++++++++--------- .../methods/account/specs/login-app.spec.js | 20 ++++ modules/account/back/models/account.json | 9 +- 3 files changed, 82 insertions(+), 58 deletions(-) create mode 100644 modules/account/back/methods/account/specs/login-app.spec.js diff --git a/modules/account/back/methods/account/login-app.js b/modules/account/back/methods/account/login-app.js index 5392f8eb2..b18226bd2 100644 --- a/modules/account/back/methods/account/login-app.js +++ b/modules/account/back/methods/account/login-app.js @@ -2,23 +2,20 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('loginApp', { - description: 'Login a user with username/email and password', + description: 'Login a user with username and password for app', accepts: [ { arg: 'user', type: 'String', - description: 'The user name or email', + description: 'The user name', required: true }, { arg: 'password', type: 'String', + required: true, description: 'The password' }, { - arg: 'deviceId', - type: 'String', - description: 'Device id' - }, { - arg: 'android_id', + arg: 'androidId', type: 'String', description: 'Android id' }, { @@ -29,11 +26,7 @@ module.exports = Self => { arg: 'nameApp', type: 'String', description: 'Version app' - }, { - arg: 'serialNumber', - type: 'String', - description: 'Serial number' - } + }, ], returns: { @@ -46,7 +39,7 @@ module.exports = Self => { } }); - Self.loginApp = async(ctx, user, password, deviceId, android_id, versionApp, nameApp, options) => { + Self.loginApp = async(ctx, user, password, android_id, versionApp, nameApp, options) => { const models = Self.app.models; const myOptions = {}; if (typeof options == 'object') @@ -54,14 +47,16 @@ module.exports = Self => { const login = await models.Account.login(ctx, user, password, myOptions); - const userId = ctx.req.accessToken.userId; + const {id: userId} = await models.VnUser.findOne({ + where: { + name: user + } + }); - const resultCheckLogin = + const [[{vIsAuthorized, vMessage}]] = await Self.rawSql('CALL vn.device_checkLogin(?, ?);', [userId, android_id], myOptions); - const [{vIsAuthorized, vMessage}] = resultCheckLogin[0]; - if (!vIsAuthorized) throw new UserError('Not authorized'); @@ -69,25 +64,14 @@ module.exports = Self => { where: { workerFk: userId } - }); + }, myOptions); - if (!isUserInOperator){ - await models.Operator.create({ 'workerFk': userId }); - - const getDataUser = await models.Operator.findOne({ - where: { - workerFk: userId - } - }); + if (!isUserInOperator) + await models.Operator.create({'workerFk': userId}); - const resultDevice = await models.DeviceProduction.findOne({ - where: { - android_id: android_id - } - }); - - if (resultDevice) - serialNumber = resultDevice.serialNumber ?? ''; + const serialNumber = (await models.DeviceProduction.findOne({ + where: {android_id: android_id} + }, myOptions))?.serialNumber ?? ''; await models.DeviceLog.create({ 'android_id': android_id, @@ -95,32 +79,45 @@ module.exports = Self => { 'nameApp': nameApp, 'versionApp': versionApp, 'serialNumber': serialNumber - }); + }, myOptions); + ctx.req.accessToken = {userId}; + const getDataUser = await models.VnUser.getCurrentUserData(ctx); - + const getDataOperator = await models.Operator.findOne({ + where: {workerFk: userId}, + fields: ['numberOfWagons', 'warehouseFk', 'itemPackingTypeFk', 'sectorFk', 'sector', + 'trainFk', 'train', 'labelerFk', 'printer'], + include: [ + { + relation: 'sector', + scope: { + fields: ['warehouseFk', 'description'], + } + }, { + relation: 'printer', + scope: { + fields: ['name'], + } + }, { + relation: 'train', + scope: { + fields: ['name'], + } + } - console.log(vIsAuthorized); - console.log(vMessage); - // const insertDeviceLog = await models.DeviceLog.create( - // { - // 'android_id': android_id, - // 'userFk': userId, - // 'versionApp': versionApp, - // 'nameApp': nameApp, - // 'serialNumber': [serialNumber] - // }, - // options - // ); + ] + }, myOptions); - // const queryDeviceCheck = - // `CALL device_checkLogin(?, ?)`; + const getVersion = await models.MobileAppVersionControl.getVersion(ctx, nameApp); - // const [queryDeviceCheckLogin] = await Self.rawSql(queryDeviceCheck, [userId, android_id], options); - - // if (!queryDeviceCheckLogin.vIsAuthorized) - // throw new UserError('User not authorized'); - - // return insertDeviceLog; - return []; + const combinedResult = { + ...login, + ...getDataOperator.__data, + ...getDataUser.__data, + ...getVersion, + message: vMessage, + serialNumber, + }; + return combinedResult; }; }; diff --git a/modules/account/back/methods/account/specs/login-app.spec.js b/modules/account/back/methods/account/specs/login-app.spec.js new file mode 100644 index 000000000..527429435 --- /dev/null +++ b/modules/account/back/methods/account/specs/login-app.spec.js @@ -0,0 +1,20 @@ +const {models} = require('vn-loopback/server/server'); + +describe('Account loginApp()', () => { + fit('should throw an error when user/password is wrong', async() => { + let req = models.Account.loginApp('user', 'pass'); + + await expectAsync(req).toBeRejected(); + }); + + fit('should return data from user', async() => { + let user = 'employee'; + let password = 'nightmare'; + let androidId = 'androidid11234567890'; + let nameApp = 'warehouse'; + let versionApp = '10'; + + let req = models.Account.loginApp(user, password, androidId, nameApp, versionApp); + await expectAsync(req).toBeResolved(); + }); +}); diff --git a/modules/account/back/models/account.json b/modules/account/back/models/account.json index 6c2784696..466b2bc04 100644 --- a/modules/account/back/models/account.json +++ b/modules/account/back/models/account.json @@ -31,6 +31,13 @@ "principalId": "$everyone", "permission": "ALLOW" }, + { + "property": "loginApp", + "accessType": "EXECUTE", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + }, { "property": "logout", "accessType": "EXECUTE", @@ -46,4 +53,4 @@ "permission": "ALLOW" } ] -} +} \ No newline at end of file From 0ab620b4854006a36882dcbc683fd759a94a2860 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 17 Jun 2024 16:50:00 +0200 Subject: [PATCH 05/46] feat newLogin refs #6868 --- modules/account/back/methods/account/login-app.js | 1 + modules/account/back/methods/account/specs/login-app.spec.js | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/account/back/methods/account/login-app.js b/modules/account/back/methods/account/login-app.js index b18226bd2..dc2708cbf 100644 --- a/modules/account/back/methods/account/login-app.js +++ b/modules/account/back/methods/account/login-app.js @@ -1,3 +1,4 @@ +const {ConsoleMessage} = require('puppeteer'); const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { diff --git a/modules/account/back/methods/account/specs/login-app.spec.js b/modules/account/back/methods/account/specs/login-app.spec.js index 527429435..90ce39f68 100644 --- a/modules/account/back/methods/account/specs/login-app.spec.js +++ b/modules/account/back/methods/account/specs/login-app.spec.js @@ -1,8 +1,9 @@ const {models} = require('vn-loopback/server/server'); describe('Account loginApp()', () => { + const ctx = {req: {accessToken: {}}}; fit('should throw an error when user/password is wrong', async() => { - let req = models.Account.loginApp('user', 'pass'); + let req = models.Account.loginApp(ctx, 'user', 'pass', 'androidid11234567890', 'warehouse', '10'); await expectAsync(req).toBeRejected(); }); @@ -14,7 +15,7 @@ describe('Account loginApp()', () => { let nameApp = 'warehouse'; let versionApp = '10'; - let req = models.Account.loginApp(user, password, androidId, nameApp, versionApp); + let req = models.Account.loginApp(ctx, user, password, androidId, nameApp, versionApp); await expectAsync(req).toBeResolved(); }); }); From c6da9e72e022c4101247b019887414b44c902693 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 17 Jun 2024 16:53:06 +0200 Subject: [PATCH 06/46] feat newLogin refs #6868 --- modules/account/back/methods/account/login-app.js | 2 +- .../back/methods/account/specs/login-app.spec.js | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/account/back/methods/account/login-app.js b/modules/account/back/methods/account/login-app.js index dc2708cbf..83c727f1a 100644 --- a/modules/account/back/methods/account/login-app.js +++ b/modules/account/back/methods/account/login-app.js @@ -1,4 +1,4 @@ -const {ConsoleMessage} = require('puppeteer'); + const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { diff --git a/modules/account/back/methods/account/specs/login-app.spec.js b/modules/account/back/methods/account/specs/login-app.spec.js index 90ce39f68..fc05cd726 100644 --- a/modules/account/back/methods/account/specs/login-app.spec.js +++ b/modules/account/back/methods/account/specs/login-app.spec.js @@ -3,19 +3,19 @@ const {models} = require('vn-loopback/server/server'); describe('Account loginApp()', () => { const ctx = {req: {accessToken: {}}}; fit('should throw an error when user/password is wrong', async() => { - let req = models.Account.loginApp(ctx, 'user', 'pass', 'androidid11234567890', 'warehouse', '10'); + const req = models.Account.loginApp(ctx, 'user', 'pass', 'androidid11234567890', 'warehouse', '10'); await expectAsync(req).toBeRejected(); }); fit('should return data from user', async() => { - let user = 'employee'; - let password = 'nightmare'; - let androidId = 'androidid11234567890'; - let nameApp = 'warehouse'; - let versionApp = '10'; + const user = 'employee'; + const password = 'nightmare'; + const androidId = 'androidid11234567890'; + const nameApp = 'warehouse'; + const versionApp = '10'; - let req = models.Account.loginApp(ctx, user, password, androidId, nameApp, versionApp); + const req = models.Account.loginApp(ctx, user, password, androidId, nameApp, versionApp); await expectAsync(req).toBeResolved(); }); }); From d61e32917a525d49ba556cbb8107821b9947a54a Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 21 Jun 2024 13:22:59 +0200 Subject: [PATCH 07/46] feat: refs #7562 Created deleteDeprecatedObjects --- db/dump/fixtures.after.sql | 4 +- .../util/events/deleteDeprecatedObjects.sql | 8 ++ .../procedures/deleteDeprecatedObjects.sql | 88 +++++++++++++++++++ .../11113-bronzeDendro/00-firstScript.sql | 22 +++++ 4 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 db/routines/util/events/deleteDeprecatedObjects.sql create mode 100644 db/routines/util/procedures/deleteDeprecatedObjects.sql create mode 100644 db/versions/11113-bronzeDendro/00-firstScript.sql diff --git a/db/dump/fixtures.after.sql b/db/dump/fixtures.after.sql index 562ea02d8..a276422e3 100644 --- a/db/dump/fixtures.after.sql +++ b/db/dump/fixtures.after.sql @@ -7,8 +7,8 @@ SET foreign_key_checks = 0; -- XXX: vn-database -INSERT INTO util.config (id, environment, mockTime, mockUtcTime, mockEnabled) - VALUES (1, 'local', '2001-01-01 12:00:00', '2001-01-01 11:00:00', TRUE); +INSERT INTO util.config (id, environment, mockTime, mockUtcTime, mockEnabled, daysKeepDeprecatedObjects) + VALUES (1, 'local', '2001-01-01 12:00:00', '2001-01-01 11:00:00', TRUE, 60); INSERT INTO util.binlogQueue (code,logName, `position`) VALUES ('mylogger', 'bin.000001', 4); diff --git a/db/routines/util/events/deleteDeprecatedObjects.sql b/db/routines/util/events/deleteDeprecatedObjects.sql new file mode 100644 index 000000000..0d7878a28 --- /dev/null +++ b/db/routines/util/events/deleteDeprecatedObjects.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `util`.`deleteDeprecatedObjects` + ON SCHEDULE EVERY 1 DAY + STARTS '2024-06-09 00:01:00.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL deleteDeprecatedObjects$$ +DELIMITER ; diff --git a/db/routines/util/procedures/deleteDeprecatedObjects.sql b/db/routines/util/procedures/deleteDeprecatedObjects.sql new file mode 100644 index 000000000..a46d806d7 --- /dev/null +++ b/db/routines/util/procedures/deleteDeprecatedObjects.sql @@ -0,0 +1,88 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`deleteDeprecatedObjects`() + MODIFIES SQL DATA +BEGIN +/** + * Elimina objetos deprecados de la base de datos + */ + DECLARE vQuery TEXT; + DECLARE vDated DATE + DEFAULT ( + SELECT CURDATE() - INTERVAL daysKeepDeprecatedObjects DAY + FROM config + ); + DECLARE vDone BOOL; + + DECLARE vObjects CURSOR FOR + SELECT CONCAT('ALTER TABLE ', c.TABLE_SCHEMA, '.', c.TABLE_NAME, ' DROP PRIMARY KEY;') + FROM information_schema.`COLUMNS` c + LEFT JOIN information_schema.`VIEWS` v ON v.TABLE_SCHEMA = c.TABLE_SCHEMA + AND v.TABLE_NAME = c.TABLE_NAME + JOIN information_schema.STATISTICS s ON s.TABLE_SCHEMA = c.TABLE_SCHEMA + AND s.TABLE_NAME = c.TABLE_NAME + AND s.COLUMN_NAME = c.COLUMN_NAME + WHERE c.COLUMN_NAME LIKE '%\_\_' + AND REGEXP_SUBSTR(c.COLUMN_COMMENT, '[0-9]{4}-[0-9]{2}-[0-9]{2}') < vDated + AND v.TABLE_NAME IS NULL + AND s.INDEX_NAME = 'PRIMARY' + UNION ALL + SELECT CONCAT('ALTER TABLE ', c.TABLE_SCHEMA, '.', c.TABLE_NAME, ' DROP FOREIGN KEY ', kcu.CONSTRAINT_NAME, ';') + FROM information_schema.`COLUMNS` c + LEFT JOIN information_schema.`VIEWS` v ON v.TABLE_SCHEMA = c.TABLE_SCHEMA + AND v.TABLE_NAME = c.TABLE_NAME + JOIN information_schema.KEY_COLUMN_USAGE kcu ON kcu.TABLE_SCHEMA = c.TABLE_SCHEMA + AND kcu.TABLE_NAME = c.TABLE_NAME + AND kcu.COLUMN_NAME = c.COLUMN_NAME + WHERE c.COLUMN_NAME LIKE '%\_\_' + AND REGEXP_SUBSTR(c.COLUMN_COMMENT, '[0-9]{4}-[0-9]{2}-[0-9]{2}') < vDated + AND v.TABLE_NAME IS NULL + AND kcu.REFERENCED_COLUMN_NAME IS NOT NULL + UNION ALL + SELECT CONCAT('ALTER TABLE ', c.TABLE_SCHEMA, '.', c.TABLE_NAME, ' DROP COLUMN ', c.COLUMN_NAME, ';') + FROM information_schema.`COLUMNS` c + LEFT JOIN information_schema.`VIEWS` v ON v.TABLE_SCHEMA = c.TABLE_SCHEMA + AND v.TABLE_NAME = c.TABLE_NAME + LEFT JOIN information_schema.KEY_COLUMN_USAGE kcu ON kcu.TABLE_SCHEMA = c.TABLE_SCHEMA + AND kcu.TABLE_NAME = c.TABLE_NAME + AND kcu.COLUMN_NAME = c.COLUMN_NAME + WHERE c.COLUMN_NAME LIKE '%\_\_' + AND REGEXP_SUBSTR(c.COLUMN_COMMENT, '[0-9]{4}-[0-9]{2}-[0-9]{2}') < vDated + AND v.TABLE_NAME IS NULL + UNION ALL + SELECT CONCAT('DROP TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, ';') + FROM information_schema.TABLES + WHERE TABLE_NAME LIKE '%\_\_' + AND REGEXP_SUBSTR(TABLE_COMMENT, '[0-9]{4}-[0-9]{2}-[0-9]{2}') < vDated; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + CALL mail_insert( + 'cau@verdnatura.es', + NULL, + 'Error en la eliminación automática de objetos deprecados', + CONCAT('
', vQuery, '
', + '

Revisa la tabla util.eventLog para más detalles.

') + ); + RESIGNAL; + END; + + IF vDated IS NULL THEN + CALL throw('Variable config not set'); + END IF; + + OPEN vObjects; + l: LOOP + SET vDone = FALSE; + FETCH vObjects INTO vQuery; + + IF vDone THEN + LEAVE l; + END IF; + + CALL `exec`(vQuery); + END LOOP; + CLOSE vObjects; +END$$ +DELIMITER ; diff --git a/db/versions/11113-bronzeDendro/00-firstScript.sql b/db/versions/11113-bronzeDendro/00-firstScript.sql new file mode 100644 index 000000000..b9a324c5e --- /dev/null +++ b/db/versions/11113-bronzeDendro/00-firstScript.sql @@ -0,0 +1,22 @@ +ALTER TABLE util.config + ADD daysKeepDeprecatedObjects int(11) unsigned NULL COMMENT 'Número de días que se mantendrán los objetos deprecados.'; + +UPDATE IGNORE util.config + SET daysKeepDeprecatedObjects = 60; + +ALTER TABLE IF EXISTS `vn`.`payrollWorker` + MODIFY COLUMN IF EXISTS `nss__` varchar(23) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', + MODIFY COLUMN IF EXISTS `codpuesto__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', + MODIFY COLUMN IF EXISTS `codcontrato__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', + MODIFY COLUMN IF EXISTS `FAntiguedad__` date NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', + MODIFY COLUMN IF EXISTS `grupotarifa__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', + MODIFY COLUMN IF EXISTS `codcategoria__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', + MODIFY COLUMN IF EXISTS `ContratoTemporal__` tinyint(1) NOT NULL DEFAULT 0 COMMENT '@deprecated 2024-03-15 refs #6738'; + +ALTER TABLE IF EXISTS `vn`.`payrollWorkCenter` + MODIFY COLUMN IF EXISTS `Centro__` varchar(255) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', + MODIFY COLUMN IF EXISTS `nss_cotizacion__` varchar(15) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', + MODIFY COLUMN IF EXISTS `domicilio__` varchar(255) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', + MODIFY COLUMN IF EXISTS `poblacion__` varchar(45) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', + MODIFY COLUMN IF EXISTS `cp__` varchar(5) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', + MODIFY COLUMN IF EXISTS `empresa_id__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738'; From c330e8c7156a55b9b99c4f7fa1e66aadcf894af0 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 21 Jun 2024 13:24:20 +0200 Subject: [PATCH 08/46] feat: refs #7562 Minor change --- db/routines/util/procedures/deleteDeprecatedObjects.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/util/procedures/deleteDeprecatedObjects.sql b/db/routines/util/procedures/deleteDeprecatedObjects.sql index a46d806d7..5911e0ab0 100644 --- a/db/routines/util/procedures/deleteDeprecatedObjects.sql +++ b/db/routines/util/procedures/deleteDeprecatedObjects.sql @@ -8,7 +8,7 @@ BEGIN DECLARE vQuery TEXT; DECLARE vDated DATE DEFAULT ( - SELECT CURDATE() - INTERVAL daysKeepDeprecatedObjects DAY + SELECT VN_CURDATE() - INTERVAL daysKeepDeprecatedObjects DAY FROM config ); DECLARE vDone BOOL; From c0668d054f86894f8e3f6ff6a4f7b3e02519266d Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 21 Jun 2024 13:51:33 +0200 Subject: [PATCH 09/46] feat: refs #7562 Changes --- db/dump/fixtures.after.sql | 4 +- .../procedures/deleteDeprecatedObjects.sql | 38 +++++++++++-------- .../11113-bronzeDendro/00-firstScript.sql | 6 ++- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/db/dump/fixtures.after.sql b/db/dump/fixtures.after.sql index a276422e3..1353e481b 100644 --- a/db/dump/fixtures.after.sql +++ b/db/dump/fixtures.after.sql @@ -7,8 +7,8 @@ SET foreign_key_checks = 0; -- XXX: vn-database -INSERT INTO util.config (id, environment, mockTime, mockUtcTime, mockEnabled, daysKeepDeprecatedObjects) - VALUES (1, 'local', '2001-01-01 12:00:00', '2001-01-01 11:00:00', TRUE, 60); +INSERT INTO util.config (id, environment, mockTime, mockUtcTime, mockEnabled, dateRegex, deprecatedMarkRegex, daysKeepDeprecatedObjects) + VALUES (1, 'local', '2001-01-01 12:00:00', '2001-01-01 11:00:00', TRUE, '[0-9]{4}-[0-9]{2}-[0-9]{2}', '__$', 60); INSERT INTO util.binlogQueue (code,logName, `position`) VALUES ('mylogger', 'bin.000001', 4); diff --git a/db/routines/util/procedures/deleteDeprecatedObjects.sql b/db/routines/util/procedures/deleteDeprecatedObjects.sql index 5911e0ab0..729f3faf1 100644 --- a/db/routines/util/procedures/deleteDeprecatedObjects.sql +++ b/db/routines/util/procedures/deleteDeprecatedObjects.sql @@ -6,11 +6,9 @@ BEGIN * Elimina objetos deprecados de la base de datos */ DECLARE vQuery TEXT; - DECLARE vDated DATE - DEFAULT ( - SELECT VN_CURDATE() - INTERVAL daysKeepDeprecatedObjects DAY - FROM config - ); + DECLARE vDated DATE; + DECLARE vDateRegex VARCHAR(255); + DECLARE vMarkRegex VARCHAR(255); DECLARE vDone BOOL; DECLARE vObjects CURSOR FOR @@ -21,8 +19,8 @@ BEGIN JOIN information_schema.STATISTICS s ON s.TABLE_SCHEMA = c.TABLE_SCHEMA AND s.TABLE_NAME = c.TABLE_NAME AND s.COLUMN_NAME = c.COLUMN_NAME - WHERE c.COLUMN_NAME LIKE '%\_\_' - AND REGEXP_SUBSTR(c.COLUMN_COMMENT, '[0-9]{4}-[0-9]{2}-[0-9]{2}') < vDated + WHERE c.COLUMN_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci + AND REGEXP_SUBSTR(c.COLUMN_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated AND v.TABLE_NAME IS NULL AND s.INDEX_NAME = 'PRIMARY' UNION ALL @@ -33,8 +31,8 @@ BEGIN JOIN information_schema.KEY_COLUMN_USAGE kcu ON kcu.TABLE_SCHEMA = c.TABLE_SCHEMA AND kcu.TABLE_NAME = c.TABLE_NAME AND kcu.COLUMN_NAME = c.COLUMN_NAME - WHERE c.COLUMN_NAME LIKE '%\_\_' - AND REGEXP_SUBSTR(c.COLUMN_COMMENT, '[0-9]{4}-[0-9]{2}-[0-9]{2}') < vDated + WHERE c.COLUMN_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci + AND REGEXP_SUBSTR(c.COLUMN_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated AND v.TABLE_NAME IS NULL AND kcu.REFERENCED_COLUMN_NAME IS NOT NULL UNION ALL @@ -45,20 +43,20 @@ BEGIN LEFT JOIN information_schema.KEY_COLUMN_USAGE kcu ON kcu.TABLE_SCHEMA = c.TABLE_SCHEMA AND kcu.TABLE_NAME = c.TABLE_NAME AND kcu.COLUMN_NAME = c.COLUMN_NAME - WHERE c.COLUMN_NAME LIKE '%\_\_' - AND REGEXP_SUBSTR(c.COLUMN_COMMENT, '[0-9]{4}-[0-9]{2}-[0-9]{2}') < vDated + WHERE c.COLUMN_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci + AND REGEXP_SUBSTR(c.COLUMN_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated AND v.TABLE_NAME IS NULL UNION ALL SELECT CONCAT('DROP TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, ';') FROM information_schema.TABLES - WHERE TABLE_NAME LIKE '%\_\_' - AND REGEXP_SUBSTR(TABLE_COMMENT, '[0-9]{4}-[0-9]{2}-[0-9]{2}') < vDated; + WHERE TABLE_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci + AND REGEXP_SUBSTR(TABLE_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - CALL mail_insert( + CALL vn.mail_insert( 'cau@verdnatura.es', NULL, 'Error en la eliminación automática de objetos deprecados', @@ -68,8 +66,16 @@ BEGIN RESIGNAL; END; - IF vDated IS NULL THEN - CALL throw('Variable config not set'); + SELECT dateRegex, + deprecatedMarkRegex, + VN_CURDATE() - INTERVAL daysKeepDeprecatedObjects DAY + INTO vDateRegex, + vMarkRegex, + vDated + FROM config; + + IF vDateRegex IS NULL OR vMarkRegex IS NULL OR vDated IS NULL THEN + CALL throw('Some config parameters are not set'); END IF; OPEN vObjects; diff --git a/db/versions/11113-bronzeDendro/00-firstScript.sql b/db/versions/11113-bronzeDendro/00-firstScript.sql index b9a324c5e..98ac69966 100644 --- a/db/versions/11113-bronzeDendro/00-firstScript.sql +++ b/db/versions/11113-bronzeDendro/00-firstScript.sql @@ -1,8 +1,12 @@ ALTER TABLE util.config + ADD COLUMN dateRegex varchar(255) NULL COMMENT 'Expresión regular para obtener las fechas.', + ADD deprecatedMarkRegex varchar(255) NULL COMMENT 'Expresión regular para obtener los objetos deprecados.', ADD daysKeepDeprecatedObjects int(11) unsigned NULL COMMENT 'Número de días que se mantendrán los objetos deprecados.'; UPDATE IGNORE util.config - SET daysKeepDeprecatedObjects = 60; + SET dateRegex = '[0-9]{4}-[0-9]{2}-[0-9]{2}', + deprecatedMarkRegex = '__$', + daysKeepDeprecatedObjects = 60; ALTER TABLE IF EXISTS `vn`.`payrollWorker` MODIFY COLUMN IF EXISTS `nss__` varchar(23) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', From aedc8071e1e8175a98c33add6b1c60ff9ffe7a97 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 21 Jun 2024 14:27:22 +0200 Subject: [PATCH 10/46] feat: refs #7562 Changes --- db/routines/util/procedures/deleteDeprecatedObjects.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/routines/util/procedures/deleteDeprecatedObjects.sql b/db/routines/util/procedures/deleteDeprecatedObjects.sql index 729f3faf1..a251c3d98 100644 --- a/db/routines/util/procedures/deleteDeprecatedObjects.sql +++ b/db/routines/util/procedures/deleteDeprecatedObjects.sql @@ -23,7 +23,7 @@ BEGIN AND REGEXP_SUBSTR(c.COLUMN_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated AND v.TABLE_NAME IS NULL AND s.INDEX_NAME = 'PRIMARY' - UNION ALL + UNION SELECT CONCAT('ALTER TABLE ', c.TABLE_SCHEMA, '.', c.TABLE_NAME, ' DROP FOREIGN KEY ', kcu.CONSTRAINT_NAME, ';') FROM information_schema.`COLUMNS` c LEFT JOIN information_schema.`VIEWS` v ON v.TABLE_SCHEMA = c.TABLE_SCHEMA @@ -35,7 +35,7 @@ BEGIN AND REGEXP_SUBSTR(c.COLUMN_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated AND v.TABLE_NAME IS NULL AND kcu.REFERENCED_COLUMN_NAME IS NOT NULL - UNION ALL + UNION SELECT CONCAT('ALTER TABLE ', c.TABLE_SCHEMA, '.', c.TABLE_NAME, ' DROP COLUMN ', c.COLUMN_NAME, ';') FROM information_schema.`COLUMNS` c LEFT JOIN information_schema.`VIEWS` v ON v.TABLE_SCHEMA = c.TABLE_SCHEMA @@ -46,7 +46,7 @@ BEGIN WHERE c.COLUMN_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci AND REGEXP_SUBSTR(c.COLUMN_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated AND v.TABLE_NAME IS NULL - UNION ALL + UNION SELECT CONCAT('DROP TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, ';') FROM information_schema.TABLES WHERE TABLE_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci From ac0c3b79b4647a51c576cd88b288a03f9975f11e Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 15 Jul 2024 15:51:52 +0200 Subject: [PATCH 11/46] feat createLogin refs #6868 --- .../back/methods/account/handle-user.js | 111 ++++++++++++++++++ modules/account/back/models/account.js | 1 + 2 files changed, 112 insertions(+) create mode 100644 modules/account/back/methods/account/handle-user.js diff --git a/modules/account/back/methods/account/handle-user.js b/modules/account/back/methods/account/handle-user.js new file mode 100644 index 000000000..18beb1796 --- /dev/null +++ b/modules/account/back/methods/account/handle-user.js @@ -0,0 +1,111 @@ + +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethodCtx('handleUser', { + description: 'Manage various aspects related to a user with the app', + accepts: [ + { + arg: 'androidId', + type: 'String', + description: 'Android id' + }, { + arg: 'versionApp', + type: 'String', + description: 'Version app' + }, { + arg: 'nameApp', + type: 'String', + description: 'Version app' + }, + + ], + returns: { + type: 'object', + root: true + }, + http: { + path: `/handleUser`, + verb: 'POST' + } + }); + + Self.loginApp = async(ctx, android_id, versionApp, nameApp, options) => { + const models = Self.app.models; + const myOptions = {}; + if (typeof options == 'object') + Object.assign(myOptions, options); + + // const login = await models.Account.login(ctx, user, password, myOptions); + + const accessToken = ctx.req.accessToken; + let user = await models.VnUser.findById(accessToken.userId); + console.log(user.id); + + const [[{vIsAuthorized, vMessage}]] = + await Self.rawSql('CALL vn.device_checkLogin(?, ?);', + [user.id, android_id], myOptions); + + if (!vIsAuthorized) + throw new UserError('Not authorized'); + + const isUserInOperator = await models.Operator.findOne({ + where: { + workerFk: user.id + } + }, myOptions); + + if (!isUserInOperator) + await models.Operator.create({'workerFk': user.id}); + + const serialNumber = (await models.DeviceProduction.findOne({ + where: {android_id: android_id} + }, myOptions))?.serialNumber ?? ''; + + await models.DeviceLog.create({ + 'android_id': android_id, + 'userFk': user.id, + 'nameApp': nameApp, + 'versionApp': versionApp, + 'serialNumber': serialNumber + }, myOptions); + // ctx.req.accessToken = {userId}; + const getDataUser = await models.VnUser.getCurrentUserData(ctx); + + const getDataOperator = await models.Operator.findOne({ + where: {workerFk: user.id}, + fields: ['numberOfWagons', 'warehouseFk', 'itemPackingTypeFk', 'sectorFk', 'sector', + 'trainFk', 'train', 'labelerFk', 'printer'], + include: [ + { + relation: 'sector', + scope: { + fields: ['warehouseFk', 'description'], + } + }, { + relation: 'printer', + scope: { + fields: ['name'], + } + }, { + relation: 'train', + scope: { + fields: ['name'], + } + } + + ] + }, myOptions); + + const getVersion = await models.MobileAppVersionControl.getVersion(ctx, nameApp); + + const combinedResult = { + ...getDataOperator.__data, + ...getDataUser.__data, + ...getVersion, + message: vMessage, + serialNumber, + }; + return combinedResult; + }; +}; diff --git a/modules/account/back/models/account.js b/modules/account/back/models/account.js index f89d3079e..4dd1987d5 100644 --- a/modules/account/back/models/account.js +++ b/modules/account/back/models/account.js @@ -11,6 +11,7 @@ module.exports = Self => { require('../methods/account/change-password')(Self); require('../methods/account/set-password')(Self); require('../methods/account/login-app')(Self); + require('../methods/account/handle-user')(Self); Self.setUnverifiedPassword = async(id, pass, options) => { const {emailVerified} = await models.VnUser.findById(id, {fields: ['emailVerified']}, options); From ae6963c26d9f0d3a5ef4e15661f942b304d34e79 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 16 Jul 2024 08:19:13 +0200 Subject: [PATCH 12/46] feat handleUser refs #6868 --- modules/account/back/methods/account/handle-user.js | 5 +---- modules/account/back/models/account.js | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/modules/account/back/methods/account/handle-user.js b/modules/account/back/methods/account/handle-user.js index 18beb1796..136ce4800 100644 --- a/modules/account/back/methods/account/handle-user.js +++ b/modules/account/back/methods/account/handle-user.js @@ -30,17 +30,14 @@ module.exports = Self => { } }); - Self.loginApp = async(ctx, android_id, versionApp, nameApp, options) => { + Self.handleUser = async(ctx, android_id, versionApp, nameApp, options) => { const models = Self.app.models; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); - // const login = await models.Account.login(ctx, user, password, myOptions); - const accessToken = ctx.req.accessToken; let user = await models.VnUser.findById(accessToken.userId); - console.log(user.id); const [[{vIsAuthorized, vMessage}]] = await Self.rawSql('CALL vn.device_checkLogin(?, ?);', diff --git a/modules/account/back/models/account.js b/modules/account/back/models/account.js index 4dd1987d5..08a5e0811 100644 --- a/modules/account/back/models/account.js +++ b/modules/account/back/models/account.js @@ -10,7 +10,6 @@ module.exports = Self => { require('../methods/account/logout')(Self); require('../methods/account/change-password')(Self); require('../methods/account/set-password')(Self); - require('../methods/account/login-app')(Self); require('../methods/account/handle-user')(Self); Self.setUnverifiedPassword = async(id, pass, options) => { From 144cf20e7148d67d6b3c40da6b6f7ad0615d2e42 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 16 Jul 2024 10:14:19 +0200 Subject: [PATCH 13/46] feat handleUser refs #6868 --- .../account/back/methods/account/login-app.js | 124 ------------------ ...{login-app.spec.js => handle-user.spec.js} | 4 +- 2 files changed, 2 insertions(+), 126 deletions(-) delete mode 100644 modules/account/back/methods/account/login-app.js rename modules/account/back/methods/account/specs/{login-app.spec.js => handle-user.spec.js} (80%) diff --git a/modules/account/back/methods/account/login-app.js b/modules/account/back/methods/account/login-app.js deleted file mode 100644 index 83c727f1a..000000000 --- a/modules/account/back/methods/account/login-app.js +++ /dev/null @@ -1,124 +0,0 @@ - -const UserError = require('vn-loopback/util/user-error'); - -module.exports = Self => { - Self.remoteMethodCtx('loginApp', { - description: 'Login a user with username and password for app', - accepts: [ - { - arg: 'user', - type: 'String', - description: 'The user name', - required: true - }, { - arg: 'password', - type: 'String', - required: true, - description: 'The password' - }, { - arg: 'androidId', - type: 'String', - description: 'Android id' - }, { - arg: 'versionApp', - type: 'String', - description: 'Version app' - }, { - arg: 'nameApp', - type: 'String', - description: 'Version app' - }, - - ], - returns: { - type: 'object', - root: true - }, - http: { - path: `/loginApp`, - verb: 'POST' - } - }); - - Self.loginApp = async(ctx, user, password, android_id, versionApp, nameApp, options) => { - const models = Self.app.models; - const myOptions = {}; - if (typeof options == 'object') - Object.assign(myOptions, options); - - const login = await models.Account.login(ctx, user, password, myOptions); - - const {id: userId} = await models.VnUser.findOne({ - where: { - name: user - } - }); - - const [[{vIsAuthorized, vMessage}]] = - await Self.rawSql('CALL vn.device_checkLogin(?, ?);', - [userId, android_id], myOptions); - - if (!vIsAuthorized) - throw new UserError('Not authorized'); - - const isUserInOperator = await models.Operator.findOne({ - where: { - workerFk: userId - } - }, myOptions); - - if (!isUserInOperator) - await models.Operator.create({'workerFk': userId}); - - const serialNumber = (await models.DeviceProduction.findOne({ - where: {android_id: android_id} - }, myOptions))?.serialNumber ?? ''; - - await models.DeviceLog.create({ - 'android_id': android_id, - 'userFk': userId, - 'nameApp': nameApp, - 'versionApp': versionApp, - 'serialNumber': serialNumber - }, myOptions); - ctx.req.accessToken = {userId}; - const getDataUser = await models.VnUser.getCurrentUserData(ctx); - - const getDataOperator = await models.Operator.findOne({ - where: {workerFk: userId}, - fields: ['numberOfWagons', 'warehouseFk', 'itemPackingTypeFk', 'sectorFk', 'sector', - 'trainFk', 'train', 'labelerFk', 'printer'], - include: [ - { - relation: 'sector', - scope: { - fields: ['warehouseFk', 'description'], - } - }, { - relation: 'printer', - scope: { - fields: ['name'], - } - }, { - relation: 'train', - scope: { - fields: ['name'], - } - } - - ] - }, myOptions); - - const getVersion = await models.MobileAppVersionControl.getVersion(ctx, nameApp); - - const combinedResult = { - ...login, - ...getDataOperator.__data, - ...getDataUser.__data, - ...getVersion, - message: vMessage, - serialNumber, - }; - return combinedResult; - }; -}; diff --git a/modules/account/back/methods/account/specs/login-app.spec.js b/modules/account/back/methods/account/specs/handle-user.spec.js similarity index 80% rename from modules/account/back/methods/account/specs/login-app.spec.js rename to modules/account/back/methods/account/specs/handle-user.spec.js index fc05cd726..621ff28ae 100644 --- a/modules/account/back/methods/account/specs/login-app.spec.js +++ b/modules/account/back/methods/account/specs/handle-user.spec.js @@ -1,9 +1,9 @@ const {models} = require('vn-loopback/server/server'); -describe('Account loginApp()', () => { +describe('Account handleUser()', () => { const ctx = {req: {accessToken: {}}}; fit('should throw an error when user/password is wrong', async() => { - const req = models.Account.loginApp(ctx, 'user', 'pass', 'androidid11234567890', 'warehouse', '10'); + const req = models.Account.handleUser(ctx, 'user', 'pass', 'androidid11234567890', 'warehouse', '10'); await expectAsync(req).toBeRejected(); }); From 7870416860504662b3a332adf90676ac69e257fb Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 16 Jul 2024 17:08:38 +0200 Subject: [PATCH 14/46] feat handleUser refs #6868 --- .../back/methods/account/handle-user.js | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/modules/account/back/methods/account/handle-user.js b/modules/account/back/methods/account/handle-user.js index 136ce4800..02b505e39 100644 --- a/modules/account/back/methods/account/handle-user.js +++ b/modules/account/back/methods/account/handle-user.js @@ -9,7 +9,13 @@ module.exports = Self => { arg: 'androidId', type: 'String', description: 'Android id' - }, { + }, + { + arg: 'deviceId', + type: 'String', + description: 'Device id' + }, + { arg: 'versionApp', type: 'String', description: 'Version app' @@ -30,9 +36,10 @@ module.exports = Self => { } }); - Self.handleUser = async(ctx, android_id, versionApp, nameApp, options) => { + Self.handleUser = async(ctx, androidId, deviceId, versionApp, nameApp, options) => { const models = Self.app.models; const myOptions = {}; + if (typeof options == 'object') Object.assign(myOptions, options); @@ -41,7 +48,7 @@ module.exports = Self => { const [[{vIsAuthorized, vMessage}]] = await Self.rawSql('CALL vn.device_checkLogin(?, ?);', - [user.id, android_id], myOptions); + [user.id, androidId], myOptions); if (!vIsAuthorized) throw new UserError('Not authorized'); @@ -55,18 +62,17 @@ module.exports = Self => { if (!isUserInOperator) await models.Operator.create({'workerFk': user.id}); - const serialNumber = (await models.DeviceProduction.findOne({ - where: {android_id: android_id} - }, myOptions))?.serialNumber ?? ''; + const whereCondition = deviceId ? {id: deviceId} : {android_id: androidId}; + const serialNumber = + (await models.DeviceProduction.findOne({where: whereCondition}, myOptions))?.serialNumber ?? ''; await models.DeviceLog.create({ - 'android_id': android_id, + 'android_id': androidId, 'userFk': user.id, 'nameApp': nameApp, 'versionApp': versionApp, 'serialNumber': serialNumber }, myOptions); - // ctx.req.accessToken = {userId}; const getDataUser = await models.VnUser.getCurrentUserData(ctx); const getDataOperator = await models.Operator.findOne({ From a82df8e2a278711b563f87be024d700d5c232149 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 16 Jul 2024 17:20:35 +0200 Subject: [PATCH 15/46] feat handleUser refs #6868 --- .../methods/account/specs/handle-user.spec.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/modules/account/back/methods/account/specs/handle-user.spec.js b/modules/account/back/methods/account/specs/handle-user.spec.js index 621ff28ae..486d9dc7a 100644 --- a/modules/account/back/methods/account/specs/handle-user.spec.js +++ b/modules/account/back/methods/account/specs/handle-user.spec.js @@ -1,21 +1,16 @@ const {models} = require('vn-loopback/server/server'); describe('Account handleUser()', () => { - const ctx = {req: {accessToken: {}}}; - fit('should throw an error when user/password is wrong', async() => { - const req = models.Account.handleUser(ctx, 'user', 'pass', 'androidid11234567890', 'warehouse', '10'); + const ctx = {req: {accessToken: {userId: 9}}}; - await expectAsync(req).toBeRejected(); - }); - - fit('should return data from user', async() => { - const user = 'employee'; - const password = 'nightmare'; + it('should return data from user', async() => { const androidId = 'androidid11234567890'; + const deviceId = 1; const nameApp = 'warehouse'; const versionApp = '10'; - const req = models.Account.loginApp(ctx, user, password, androidId, nameApp, versionApp); - await expectAsync(req).toBeResolved(); + const data = await models.Account.handleUser(ctx, androidId, deviceId, versionApp, nameApp); + + expect(data.numberOfWagons).toBe(2); }); }); From 2568ac4e923c0e33be1db57d53a6684323ce7188 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 23 Jul 2024 13:24:43 +0200 Subject: [PATCH 16/46] feat: refs #6346 new wagon type section --- db/dump/fixtures.before.sql | 13 ++-- .../11088-bronzeAspidistra/00-firstScript.sql | 26 ++++++++ .../back/methods/wagonType/createWagonType.js | 57 ----------------- .../back/methods/wagonType/deleteWagonType.js | 43 ------------- .../back/methods/wagonType/editWagonType.js | 64 ------------------- .../wagonType/specs/crudWagonType.spec.js | 48 +------------- modules/wagon/back/models/wagon-config.json | 13 ++++ modules/wagon/back/models/wagon-type-tray.js | 16 +++++ .../wagon/back/models/wagon-type-tray.json | 8 +-- modules/wagon/back/models/wagon-type.js | 15 ++++- 10 files changed, 81 insertions(+), 222 deletions(-) create mode 100644 db/versions/11088-bronzeAspidistra/00-firstScript.sql delete mode 100644 modules/wagon/back/methods/wagonType/createWagonType.js delete mode 100644 modules/wagon/back/methods/wagonType/deleteWagonType.js delete mode 100644 modules/wagon/back/methods/wagonType/editWagonType.js create mode 100644 modules/wagon/back/models/wagon-type-tray.js diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 30f1ceb5e..3b799a610 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3024,9 +3024,6 @@ INSERT INTO `vn`.`workerTimeControlMail` (`id`, `workerFk`, `year`, `week`, `sta (3, 9, 2000, 51, 'CONFIRMED', util.VN_NOW(), 1, NULL), (4, 9, 2001, 1, 'SENDED', util.VN_NOW(), 1, NULL); -INSERT INTO `vn`.`wagonConfig` (`id`, `width`, `height`, `maxWagonHeight`, `minHeightBetweenTrays`, `maxTrays`) - VALUES - (1, 1350, 1900, 200, 50, 6); INSERT INTO `vn`.`wagonTypeColor` (`id`, `name`, `rgb`) VALUES @@ -3035,15 +3032,19 @@ INSERT INTO `vn`.`wagonTypeColor` (`id`, `name`, `rgb`) (3, 'green', '#00ff00'), (4, 'blue', '#0000ff'); +INSERT INTO `vn`.`wagonConfig` (`id`, `width`, `height`, `maxWagonHeight`, `minHeightBetweenTrays`, `maxTrays`, `defaultTrayColorFk`) + VALUES + (1, 1350, 1900, 200, 50, 6, 1); + INSERT INTO `vn`.`wagonType` (`id`, `name`, `divisible`) VALUES (1, 'Wagon Type #1', 1); -INSERT INTO `vn`.`wagonTypeTray` (`id`, `typeFk`, `height`, `colorFk`) +INSERT INTO `vn`.`wagonTypeTray` (`id`, `wagonTypeFk`, `height`, `wagonTypeColorFk`) VALUES - (1, 1, 100, 1), + (1, 1, 0, 1), (2, 1, 50, 2), - (3, 1, 0, 3); + (3, 1, 100, 3); INSERT INTO `salix`.`accessTokenConfig` (`id`, `renewPeriod`, `courtesyTime`, `renewInterval`) VALUES diff --git a/db/versions/11088-bronzeAspidistra/00-firstScript.sql b/db/versions/11088-bronzeAspidistra/00-firstScript.sql new file mode 100644 index 000000000..2cc4e715e --- /dev/null +++ b/db/versions/11088-bronzeAspidistra/00-firstScript.sql @@ -0,0 +1,26 @@ +-- Place your SQL code here +DROP TABLE IF EXISTS vn.wagonTypeTray; + +CREATE TABLE vn.wagonTypeTray ( + id INT UNSIGNED auto_increment NULL, + wagonTypeFk int(11) unsigned NULL, + height INT UNSIGNED NULL, + wagonTypeColorFk int(11) unsigned NULL, + CONSTRAINT wagonTypeTray_pk PRIMARY KEY (id), + CONSTRAINT wagonTypeTray_wagonType_FK FOREIGN KEY (wagonTypeFk) REFERENCES vn.wagonType(id), + CONSTRAINT wagonTypeTray_wagonTypeColor_FK FOREIGN KEY (wagonTypeColorFk) REFERENCES vn.wagonTypeColor(id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + +ALTER TABLE vn.wagonConfig ADD IF NOT EXISTS defaultHeight INT UNSIGNED DEFAULT 0 NULL COMMENT 'Default height in cm for a base tray'; +ALTER TABLE vn.wagonConfig ADD IF NOT EXISTS defaultTrayColorFk int(11) unsigned NULL COMMENT 'Default color for a base tray'; +ALTER TABLE vn.wagonConfig ADD CONSTRAINT wagonConfig_wagonTypeColor_FK FOREIGN KEY (defaultTrayColorFk) REFERENCES vn.wagonTypeColor(id); + +ALTER TABLE vn.wagonTypeTray DROP FOREIGN KEY wagonTypeTray_wagonType_FK; +ALTER TABLE vn.wagonTypeTray ADD CONSTRAINT wagonTypeTray_wagonType_FK FOREIGN KEY (wagonTypeFk) REFERENCES vn.wagonType(id) ON DELETE CASCADE ON UPDATE RESTRICT; + + + +-- insertar datos por defecto \ No newline at end of file diff --git a/modules/wagon/back/methods/wagonType/createWagonType.js b/modules/wagon/back/methods/wagonType/createWagonType.js deleted file mode 100644 index fed915b28..000000000 --- a/modules/wagon/back/methods/wagonType/createWagonType.js +++ /dev/null @@ -1,57 +0,0 @@ -module.exports = Self => { - Self.remoteMethodCtx('createWagonType', { - description: 'Creates a new wagon type', - accessType: 'WRITE', - accepts: [ - { - arg: 'name', - type: 'String', - required: true - }, - { - arg: 'divisible', - type: 'boolean', - required: true - }, { - arg: 'trays', - type: 'any', - required: true - } - ], - http: { - path: `/createWagonType`, - verb: 'PATCH' - } - }); - - Self.createWagonType = async(ctx, options) => { - const args = ctx.args; - const models = Self.app.models; - const myOptions = {}; - let tx; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - - try { - const newWagonType = await models.WagonType.create({name: args.name, divisible: args.divisible}, myOptions); - args.trays.forEach(async tray => { - await models.WagonTypeTray.create({ - typeFk: newWagonType.id, - height: tray.position, - colorFk: tray.color.id - }, myOptions); - }); - - if (tx) await tx.commit(); - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } - }; -}; diff --git a/modules/wagon/back/methods/wagonType/deleteWagonType.js b/modules/wagon/back/methods/wagonType/deleteWagonType.js deleted file mode 100644 index 46b65e32f..000000000 --- a/modules/wagon/back/methods/wagonType/deleteWagonType.js +++ /dev/null @@ -1,43 +0,0 @@ -module.exports = Self => { - Self.remoteMethodCtx('deleteWagonType', { - description: 'Deletes a wagon type', - accessType: 'WRITE', - accepts: [ - { - arg: 'id', - type: 'Number', - required: true - } - ], - http: { - path: `/deleteWagonType`, - verb: 'DELETE' - } - }); - - Self.deleteWagonType = async(ctx, options) => { - const args = ctx.args; - const models = Self.app.models; - const myOptions = {}; - let tx; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - - try { - await models.Wagon.destroyAll({typeFk: args.id}, myOptions); - await models.WagonTypeTray.destroyAll({typeFk: args.id}, myOptions); - await models.WagonType.destroyAll({id: args.id}, myOptions); - - if (tx) await tx.commit(); - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } - }; -}; diff --git a/modules/wagon/back/methods/wagonType/editWagonType.js b/modules/wagon/back/methods/wagonType/editWagonType.js deleted file mode 100644 index bd5ad1f16..000000000 --- a/modules/wagon/back/methods/wagonType/editWagonType.js +++ /dev/null @@ -1,64 +0,0 @@ -module.exports = Self => { - Self.remoteMethodCtx('editWagonType', { - description: 'Edits a new wagon type', - accessType: 'WRITE', - accepts: [ - { - arg: 'id', - type: 'String', - required: true - }, - { - arg: 'name', - type: 'String', - required: true - }, - { - arg: 'divisible', - type: 'boolean', - required: true - }, { - arg: 'trays', - type: 'any', - required: true - } - ], - http: { - path: `/editWagonType`, - verb: 'PATCH' - } - }); - - Self.editWagonType = async(ctx, options) => { - const args = ctx.args; - const models = Self.app.models; - const myOptions = {}; - let tx; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - - try { - const wagonType = await models.WagonType.findById(args.id, null, myOptions); - wagonType.updateAttributes({name: args.name, divisible: args.divisible}, myOptions); - models.WagonTypeTray.destroyAll({typeFk: args.id}, myOptions); - args.trays.forEach(async tray => { - await models.WagonTypeTray.create({ - typeFk: args.id, - height: tray.position, - colorFk: tray.color.id - }, myOptions); - }); - - if (tx) await tx.commit(); - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } - }; -}; diff --git a/modules/wagon/back/methods/wagonType/specs/crudWagonType.spec.js b/modules/wagon/back/methods/wagonType/specs/crudWagonType.spec.js index 92ac61060..96f0980f9 100644 --- a/modules/wagon/back/methods/wagonType/specs/crudWagonType.spec.js +++ b/modules/wagon/back/methods/wagonType/specs/crudWagonType.spec.js @@ -1,58 +1,16 @@ const models = require('vn-loopback/server/server').models; describe('WagonType crudWagonType()', () => { - const ctx = { - args: { - name: 'Mock wagon type', - divisible: true, - trays: [{position: 0, color: {id: 1}}, - {position: 50, color: {id: 2}}, - {position: 100, color: {id: 3}}] - } - }; - it(`should create, edit and delete a new wagon type and its trays`, async() => { const tx = await models.WagonType.beginTransaction({}); try { const options = {transaction: tx}; - // create - await models.WagonType.createWagonType(ctx, options); + const wagonType = await models.WagonType.create({name: 'Mock wagon type'}, options); + const newWagonTrays = await models.WagonTypeTray.findOne({where: {typeFk: wagonType.id}}, options); - const newWagonType = await models.WagonType.findOne({where: {name: ctx.args.name}}, options); - const newWagonTrays = await models.WagonTypeTray.find({where: {typeFk: newWagonType.id}}, options); - - expect(newWagonType).not.toEqual(null); - expect(newWagonType.name).toEqual(ctx.args.name); - expect(newWagonType.divisible).toEqual(ctx.args.divisible); - expect(newWagonTrays.length).toEqual(ctx.args.trays.length); - - ctx.args = { - id: newWagonType.id, - name: 'Edited wagon type', - divisible: false, - trays: [{position: 0, color: {id: 1}}] - }; - - // edit - await models.WagonType.editWagonType(ctx, options); - - const editedWagonType = await models.WagonType.findById(newWagonType.id, null, options); - const editedWagonTrays = await models.WagonTypeTray.find({where: {typeFk: newWagonType.id}}, options); - - expect(editedWagonType.name).toEqual(ctx.args.name); - expect(editedWagonType.divisible).toEqual(ctx.args.divisible); - expect(editedWagonTrays.length).toEqual(ctx.args.trays.length); - - // delete - await models.WagonType.deleteWagonType(ctx, options); - - const deletedWagonType = await models.WagonType.findById(newWagonType.id, null, options); - const deletedWagonTrays = await models.WagonTypeTray.find({where: {typeFk: newWagonType.id}}, options); - - expect(deletedWagonType).toEqual(null); - expect(deletedWagonTrays).toEqual([]); + expect(newWagonTrays).toBeDefined(); await tx.rollback(); } catch (e) { diff --git a/modules/wagon/back/models/wagon-config.json b/modules/wagon/back/models/wagon-config.json index 3d96e2864..d76558564 100644 --- a/modules/wagon/back/models/wagon-config.json +++ b/modules/wagon/back/models/wagon-config.json @@ -25,6 +25,19 @@ }, "maxTrays": { "type": "number" + }, + "defaultHeight": { + "type": "number" + }, + "defaultTrayColorFk": { + "type": "number" } + }, + "relations": { + "WagonTypeColor": { + "type": "belongsTo", + "model": "WagonTypeColor", + "foreignKey": "defaultTrayColorFk" + } } } diff --git a/modules/wagon/back/models/wagon-type-tray.js b/modules/wagon/back/models/wagon-type-tray.js new file mode 100644 index 000000000..e32938743 --- /dev/null +++ b/modules/wagon/back/models/wagon-type-tray.js @@ -0,0 +1,16 @@ +// module.exports = Self => { +// Self.observe('before save', async ctx => { +// if (ctx.isNewInstance) { +// const models = Self.app.models; +// const config = await models.WagonConfig.findOne(); + +// await models.WagonTypeTray.create({ +// wagonTypeFk: config.wagonTypeFk, +// height: config.height, +// wagonTypeColorFk: config.wagonTypeColorFk +// }, ctx.options); +// } +// if (ctx.instance < config.minHeightBetweenTrays) +// throw new Error('Height must be greater than ' + config.minHeightBetweenTrays); +// }); +// }; diff --git a/modules/wagon/back/models/wagon-type-tray.json b/modules/wagon/back/models/wagon-type-tray.json index b61510bcf..61b32694d 100644 --- a/modules/wagon/back/models/wagon-type-tray.json +++ b/modules/wagon/back/models/wagon-type-tray.json @@ -11,13 +11,13 @@ "id": true, "type": "number" }, - "typeFk": { + "wagonTypeFk": { "type": "number" }, "height": { "type": "number" }, - "colorFk": { + "wagonTypeColorFk": { "type": "number" } }, @@ -25,12 +25,12 @@ "type": { "type": "belongsTo", "model": "WagonType", - "foreignKey": "typeFk" + "foreignKey": "wagonTypeFk" }, "color": { "type": "belongsTo", "model": "WagonTypeColor", - "foreignKey": "colorFk" + "foreignKey": "wagonTypeColorFk" } } } diff --git a/modules/wagon/back/models/wagon-type.js b/modules/wagon/back/models/wagon-type.js index bebf7a9d9..0610adcb4 100644 --- a/modules/wagon/back/models/wagon-type.js +++ b/modules/wagon/back/models/wagon-type.js @@ -1,5 +1,14 @@ module.exports = Self => { - require('../methods/wagonType/createWagonType')(Self); - require('../methods/wagonType/editWagonType')(Self); - require('../methods/wagonType/deleteWagonType')(Self); + Self.observe('after save', async ctx => { + if (ctx.isNewInstance) { + const models = Self.app.models; + const config = await models.WagonConfig.findOne(); + + await models.WagonTypeTray.create({ + wagonTypeFk: ctx.instance.id, + height: config.defaultHeight, + wagonTypeColorFk: config.defaultTrayColorFk + }, ctx.options); + } + }); }; From 2ba391fc85bacc338914002bdab00c449339e188 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 2 Sep 2024 07:57:00 +0200 Subject: [PATCH 17/46] feat: refs #7562 Deleted deleteDeprecatedObjects objects --- .../util/events/deleteDeprecatedObjects.sql | 8 -- .../procedures/deleteDeprecatedObjects.sql | 94 ------------------- 2 files changed, 102 deletions(-) delete mode 100644 db/routines/util/events/deleteDeprecatedObjects.sql delete mode 100644 db/routines/util/procedures/deleteDeprecatedObjects.sql diff --git a/db/routines/util/events/deleteDeprecatedObjects.sql b/db/routines/util/events/deleteDeprecatedObjects.sql deleted file mode 100644 index 0d7878a28..000000000 --- a/db/routines/util/events/deleteDeprecatedObjects.sql +++ /dev/null @@ -1,8 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `util`.`deleteDeprecatedObjects` - ON SCHEDULE EVERY 1 DAY - STARTS '2024-06-09 00:01:00.000' - ON COMPLETION PRESERVE - ENABLE -DO CALL deleteDeprecatedObjects$$ -DELIMITER ; diff --git a/db/routines/util/procedures/deleteDeprecatedObjects.sql b/db/routines/util/procedures/deleteDeprecatedObjects.sql deleted file mode 100644 index a251c3d98..000000000 --- a/db/routines/util/procedures/deleteDeprecatedObjects.sql +++ /dev/null @@ -1,94 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`deleteDeprecatedObjects`() - MODIFIES SQL DATA -BEGIN -/** - * Elimina objetos deprecados de la base de datos - */ - DECLARE vQuery TEXT; - DECLARE vDated DATE; - DECLARE vDateRegex VARCHAR(255); - DECLARE vMarkRegex VARCHAR(255); - DECLARE vDone BOOL; - - DECLARE vObjects CURSOR FOR - SELECT CONCAT('ALTER TABLE ', c.TABLE_SCHEMA, '.', c.TABLE_NAME, ' DROP PRIMARY KEY;') - FROM information_schema.`COLUMNS` c - LEFT JOIN information_schema.`VIEWS` v ON v.TABLE_SCHEMA = c.TABLE_SCHEMA - AND v.TABLE_NAME = c.TABLE_NAME - JOIN information_schema.STATISTICS s ON s.TABLE_SCHEMA = c.TABLE_SCHEMA - AND s.TABLE_NAME = c.TABLE_NAME - AND s.COLUMN_NAME = c.COLUMN_NAME - WHERE c.COLUMN_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci - AND REGEXP_SUBSTR(c.COLUMN_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated - AND v.TABLE_NAME IS NULL - AND s.INDEX_NAME = 'PRIMARY' - UNION - SELECT CONCAT('ALTER TABLE ', c.TABLE_SCHEMA, '.', c.TABLE_NAME, ' DROP FOREIGN KEY ', kcu.CONSTRAINT_NAME, ';') - FROM information_schema.`COLUMNS` c - LEFT JOIN information_schema.`VIEWS` v ON v.TABLE_SCHEMA = c.TABLE_SCHEMA - AND v.TABLE_NAME = c.TABLE_NAME - JOIN information_schema.KEY_COLUMN_USAGE kcu ON kcu.TABLE_SCHEMA = c.TABLE_SCHEMA - AND kcu.TABLE_NAME = c.TABLE_NAME - AND kcu.COLUMN_NAME = c.COLUMN_NAME - WHERE c.COLUMN_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci - AND REGEXP_SUBSTR(c.COLUMN_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated - AND v.TABLE_NAME IS NULL - AND kcu.REFERENCED_COLUMN_NAME IS NOT NULL - UNION - SELECT CONCAT('ALTER TABLE ', c.TABLE_SCHEMA, '.', c.TABLE_NAME, ' DROP COLUMN ', c.COLUMN_NAME, ';') - FROM information_schema.`COLUMNS` c - LEFT JOIN information_schema.`VIEWS` v ON v.TABLE_SCHEMA = c.TABLE_SCHEMA - AND v.TABLE_NAME = c.TABLE_NAME - LEFT JOIN information_schema.KEY_COLUMN_USAGE kcu ON kcu.TABLE_SCHEMA = c.TABLE_SCHEMA - AND kcu.TABLE_NAME = c.TABLE_NAME - AND kcu.COLUMN_NAME = c.COLUMN_NAME - WHERE c.COLUMN_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci - AND REGEXP_SUBSTR(c.COLUMN_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated - AND v.TABLE_NAME IS NULL - UNION - SELECT CONCAT('DROP TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, ';') - FROM information_schema.TABLES - WHERE TABLE_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci - AND REGEXP_SUBSTR(TABLE_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - CALL vn.mail_insert( - 'cau@verdnatura.es', - NULL, - 'Error en la eliminación automática de objetos deprecados', - CONCAT('
', vQuery, '
', - '

Revisa la tabla util.eventLog para más detalles.

') - ); - RESIGNAL; - END; - - SELECT dateRegex, - deprecatedMarkRegex, - VN_CURDATE() - INTERVAL daysKeepDeprecatedObjects DAY - INTO vDateRegex, - vMarkRegex, - vDated - FROM config; - - IF vDateRegex IS NULL OR vMarkRegex IS NULL OR vDated IS NULL THEN - CALL throw('Some config parameters are not set'); - END IF; - - OPEN vObjects; - l: LOOP - SET vDone = FALSE; - FETCH vObjects INTO vQuery; - - IF vDone THEN - LEAVE l; - END IF; - - CALL `exec`(vQuery); - END LOOP; - CLOSE vObjects; -END$$ -DELIMITER ; From 29b0851741b20d5641d283cebd3125bebd50017c Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 3 Sep 2024 14:35:05 +0200 Subject: [PATCH 18/46] refactor: refs #6346 hook added in wagon-type-tray model --- .../11088-bronzeAspidistra/00-firstScript.sql | 5 --- loopback/locale/es.json | 8 +++- modules/wagon/back/models/wagon-type-tray.js | 42 ++++++++++++------- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/db/versions/11088-bronzeAspidistra/00-firstScript.sql b/db/versions/11088-bronzeAspidistra/00-firstScript.sql index 2cc4e715e..98203c9d1 100644 --- a/db/versions/11088-bronzeAspidistra/00-firstScript.sql +++ b/db/versions/11088-bronzeAspidistra/00-firstScript.sql @@ -1,4 +1,3 @@ --- Place your SQL code here DROP TABLE IF EXISTS vn.wagonTypeTray; CREATE TABLE vn.wagonTypeTray ( @@ -20,7 +19,3 @@ ALTER TABLE vn.wagonConfig ADD CONSTRAINT wagonConfig_wagonTypeColor_FK FOREIGN ALTER TABLE vn.wagonTypeTray DROP FOREIGN KEY wagonTypeTray_wagonType_FK; ALTER TABLE vn.wagonTypeTray ADD CONSTRAINT wagonTypeTray_wagonType_FK FOREIGN KEY (wagonTypeFk) REFERENCES vn.wagonType(id) ON DELETE CASCADE ON UPDATE RESTRICT; - - - --- insertar datos por defecto \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index e2be5d013..47601ae41 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -367,5 +367,9 @@ "It has been invoiced but the PDF of refund not be generated": "Se ha facturado pero no se ha podido generar el PDF del abono", "Payment method is required": "El método de pago es obligatorio", "Cannot send mail": "Não é possível enviar o email", - "CONSTRAINT `supplierAccountTooShort` failed for `vn`.`supplier`": "La cuenta debe tener exactamente 10 dígitos" -} + "CONSTRAINT `supplierAccountTooShort` failed for `vn`.`supplier`": "La cuenta debe tener exactamente 10 dígitos", + "There is already a tray with the same height": "Ya existe una bandeja con la misma altura", + "You must define wagon and height": "Debes definir un tipo de vagón y la altura", + "The maximum height of the wagon is": "La altura máxima es %d", + "The height must be greater than": "The height must be greater than %d" +} \ No newline at end of file diff --git a/modules/wagon/back/models/wagon-type-tray.js b/modules/wagon/back/models/wagon-type-tray.js index e32938743..5bcb1d3c7 100644 --- a/modules/wagon/back/models/wagon-type-tray.js +++ b/modules/wagon/back/models/wagon-type-tray.js @@ -1,16 +1,28 @@ -// module.exports = Self => { -// Self.observe('before save', async ctx => { -// if (ctx.isNewInstance) { -// const models = Self.app.models; -// const config = await models.WagonConfig.findOne(); +const UserError = require('vn-loopback/util/user-error'); -// await models.WagonTypeTray.create({ -// wagonTypeFk: config.wagonTypeFk, -// height: config.height, -// wagonTypeColorFk: config.wagonTypeColorFk -// }, ctx.options); -// } -// if (ctx.instance < config.minHeightBetweenTrays) -// throw new Error('Height must be greater than ' + config.minHeightBetweenTrays); -// }); -// }; +module.exports = Self => { + Self.observe('before save', async ctx => { + if (ctx.isNewInstance) { + const models = Self.app.models; + const {wagonTypeFk, height} = ctx.instance; + const trays = await models.WagonTypeTray.find({where: {wagonTypeFk}}); + + const config = await models.WagonConfig.findOne(); + const tray = await models.WagonTypeTray.find({where: {wagonTypeFk, height}}); + + if (!trays.length) return; + + if (tray.length) + throw new UserError('There is already a tray with the same height'); + + if (!wagonTypeFk && !height) + throw new UserError('You must define wagon and height'); + + if (height < config.minHeightBetweenTrays) + throw new UserError('The height must be greater than', 'HEIGHT_GREATER_THAN', config.minHeightBetweenTrays); + + if (height > config.maxWagonHeight) + throw new UserError('The maximum height of the wagon is', 'MAX_WAGON_HEIGHT', config.maxWagonHeight); + } + }); +}; From 36cf6b1aeee927320e58e19917405d88d26f533a Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 3 Sep 2024 16:50:55 +0200 Subject: [PATCH 19/46] feat: refs #6868 refs# 6868 handleUser --- modules/account/back/models/account.js | 1 - .../account => worker/back/methods/device}/handle-user.js | 0 .../back/methods/device}/specs/handle-user.spec.js | 4 ++-- modules/worker/back/models/device.js | 1 + 4 files changed, 3 insertions(+), 3 deletions(-) rename modules/{account/back/methods/account => worker/back/methods/device}/handle-user.js (100%) rename modules/{account/back/methods/account => worker/back/methods/device}/specs/handle-user.spec.js (72%) diff --git a/modules/account/back/models/account.js b/modules/account/back/models/account.js index 08a5e0811..ceb26053c 100644 --- a/modules/account/back/models/account.js +++ b/modules/account/back/models/account.js @@ -10,7 +10,6 @@ module.exports = Self => { require('../methods/account/logout')(Self); require('../methods/account/change-password')(Self); require('../methods/account/set-password')(Self); - require('../methods/account/handle-user')(Self); Self.setUnverifiedPassword = async(id, pass, options) => { const {emailVerified} = await models.VnUser.findById(id, {fields: ['emailVerified']}, options); diff --git a/modules/account/back/methods/account/handle-user.js b/modules/worker/back/methods/device/handle-user.js similarity index 100% rename from modules/account/back/methods/account/handle-user.js rename to modules/worker/back/methods/device/handle-user.js diff --git a/modules/account/back/methods/account/specs/handle-user.spec.js b/modules/worker/back/methods/device/specs/handle-user.spec.js similarity index 72% rename from modules/account/back/methods/account/specs/handle-user.spec.js rename to modules/worker/back/methods/device/specs/handle-user.spec.js index 486d9dc7a..c4cd37e33 100644 --- a/modules/account/back/methods/account/specs/handle-user.spec.js +++ b/modules/worker/back/methods/device/specs/handle-user.spec.js @@ -1,6 +1,6 @@ const {models} = require('vn-loopback/server/server'); -describe('Account handleUser()', () => { +describe('Device handleUser()', () => { const ctx = {req: {accessToken: {userId: 9}}}; it('should return data from user', async() => { @@ -9,7 +9,7 @@ describe('Account handleUser()', () => { const nameApp = 'warehouse'; const versionApp = '10'; - const data = await models.Account.handleUser(ctx, androidId, deviceId, versionApp, nameApp); + const data = await models.Device.handleUser(ctx, androidId, deviceId, versionApp, nameApp); expect(data.numberOfWagons).toBe(2); }); diff --git a/modules/worker/back/models/device.js b/modules/worker/back/models/device.js index cda7a958f..6a7d5dba5 100644 --- a/modules/worker/back/models/device.js +++ b/modules/worker/back/models/device.js @@ -1,6 +1,7 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { + require('../methods/device/handle-user')(Self); Self.rewriteDbError(function(err) { if (err.code === 'ER_DUP_ENTRY') return new UserError(``); From 7486c4a3c6d5eefc8046f5997f88d8e0216d7532 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 6 Sep 2024 07:48:53 +0200 Subject: [PATCH 20/46] feat: refs #7562 refs #7532 Requested changes --- db/dump/fixtures.after.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/dump/fixtures.after.sql b/db/dump/fixtures.after.sql index b3fcad6af..59730d592 100644 --- a/db/dump/fixtures.after.sql +++ b/db/dump/fixtures.after.sql @@ -7,8 +7,8 @@ SET foreign_key_checks = 0; -- XXX: vn-database -INSERT INTO util.config (id, environment, mockTime, mockUtcTime, mockEnabled, dateRegex, deprecatedMarkRegex, daysKeepDeprecatedObjects) - VALUES (1, 'local', '2001-01-01 12:00:00', '2001-01-01 11:00:00', TRUE, '[0-9]{4}-[0-9]{2}-[0-9]{2}', '__$', 60); +INSERT INTO util.config (id, environment, mockTime, mockUtcTime, mockEnabled) + VALUES (1, 'local', '2001-01-01 12:00:00', '2001-01-01 11:00:00', TRUE); /* #5483 INSERT INTO vn.entryConfig (defaultEntry, mailToNotify, inventorySupplierFk, maxLockTime, defaultSupplierFk) From 4daea90b1b6ecc05b43aa1b4411ebe044db5108e Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 6 Sep 2024 08:25:21 +0200 Subject: [PATCH 21/46] feat: refs #7562 refs #7759 Requested changes --- myt.config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/myt.config.yml b/myt.config.yml index ffa4188b2..683090ecc 100755 --- a/myt.config.yml +++ b/myt.config.yml @@ -2,6 +2,7 @@ code: vn-database versionSchema: util replace: true sumViews: false +defaultDefiner: vn@localhost mockDate: '2001-01-01 12:00:00' subdir: db schemas: From bf1a43a23ec43d1a129e2b02ef03f301cd1ecd71 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 9 Sep 2024 14:43:16 +0200 Subject: [PATCH 22/46] refactor: refs #7900 Deleted sectorProdPriority column --- db/routines/vn/procedures/productionSectorList.sql | 1 - db/routines/vn/views/itemShelvingAvailable.sql | 1 - db/routines/vn2008/views/state.sql | 1 - db/versions/11222-azureCordyline/00-firstScript.sql | 1 + 4 files changed, 1 insertion(+), 3 deletions(-) create mode 100644 db/versions/11222-azureCordyline/00-firstScript.sql diff --git a/db/routines/vn/procedures/productionSectorList.sql b/db/routines/vn/procedures/productionSectorList.sql index f61ec7ec9..ed6eff147 100644 --- a/db/routines/vn/procedures/productionSectorList.sql +++ b/db/routines/vn/procedures/productionSectorList.sql @@ -55,7 +55,6 @@ BEGIN i.itemPackingTypeFk, isa.`size`, isa.Estado, - isa.sectorProdPriority, isa.available, isa.sectorFk, isa.matricula, diff --git a/db/routines/vn/views/itemShelvingAvailable.sql b/db/routines/vn/views/itemShelvingAvailable.sql index 561569285..15083e6cc 100644 --- a/db/routines/vn/views/itemShelvingAvailable.sql +++ b/db/routines/vn/views/itemShelvingAvailable.sql @@ -10,7 +10,6 @@ AS SELECT `s`.`id` AS `saleFk`, `s`.`concept` AS `concept`, `i`.`size` AS `size`, `st`.`name` AS `Estado`, - `st`.`sectorProdPriority` AS `sectorProdPriority`, `stock`.`visible` AS `available`, `stock`.`sectorFk` AS `sectorFk`, `stock`.`shelvingFk` AS `matricula`, diff --git a/db/routines/vn2008/views/state.sql b/db/routines/vn2008/views/state.sql index 63f6589af..9f7fcccd8 100644 --- a/db/routines/vn2008/views/state.sql +++ b/db/routines/vn2008/views/state.sql @@ -6,7 +6,6 @@ AS SELECT `s`.`id` AS `id`, `s`.`order` AS `order`, `s`.`alertLevel` AS `alert_level`, `s`.`code` AS `code`, - `s`.`sectorProdPriority` AS `sectorProdPriority`, `s`.`nextStateFk` AS `nextStateFk`, `s`.`isPreviousPreparable` AS `isPreviousPreparable`, `s`.`isPicked` AS `isPicked` diff --git a/db/versions/11222-azureCordyline/00-firstScript.sql b/db/versions/11222-azureCordyline/00-firstScript.sql new file mode 100644 index 000000000..c63228911 --- /dev/null +++ b/db/versions/11222-azureCordyline/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.state DROP COLUMN sectorProdPriority; From 1aa888b1a30f20adac3372a9428281710be8d113 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 9 Sep 2024 15:11:09 +0200 Subject: [PATCH 23/46] feat(WorkerDms_filter): refs #7182 split code. fix: filter --- .../back/methods/worker-dms/docuwareFilter.js | 74 +++++++++++++++ .../worker/back/methods/worker-dms/filter.js | 90 ++++++------------- 2 files changed, 99 insertions(+), 65 deletions(-) create mode 100644 modules/worker/back/methods/worker-dms/docuwareFilter.js diff --git a/modules/worker/back/methods/worker-dms/docuwareFilter.js b/modules/worker/back/methods/worker-dms/docuwareFilter.js new file mode 100644 index 000000000..0311153b0 --- /dev/null +++ b/modules/worker/back/methods/worker-dms/docuwareFilter.js @@ -0,0 +1,74 @@ +module.exports = Self => { + Self.remoteMethodCtx('filter', { + description: 'Find docuware documents', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'number', + description: 'The worker id', + http: {source: 'path'} + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/:id/filter`, + verb: 'GET' + } + }); + + Self.filter = async(ctx, id) => { + const models = Self.app.models; + + const {dmsTypeFk} = await models.Docuware.findOne({ + 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 docuwareParse = { + 'Filename': 'dmsFk', + 'Tipo Documento': 'description', + 'Stored on': 'created', + 'Document ID': 'id', + 'URL': 'download', + 'Stored by': 'name', + 'Estado': 'state' + }; + + workerDocuware = + await models.Docuware.getById('hr', worker.lastName + ' ' + worker.firstName, docuwareParse) ?? []; + const url = (await Self.app.models.Url.getUrl('docuware')) + 'WebClient'; + for (document of workerDocuware) { + const docuwareId = document.id; + const defaultData = { + id: docuwareId, + workerFk: id, + dmsFk: docuwareId, + dms: { + id: docuwareId, + file: docuwareId + '.pdf', + isDocuware: true, + hasFile: false, + reference: worker.fi, + dmsFk: docuwareId, + url, + description: document.description + ' - ' + document.state, + download: document.download, + created: document.created, + dmsType: {name: 'Docuware'}, + worker: {id: null, user: {name: document.name}}, + } + }; + Object.assign(document, defaultData); + } + }; + + return workerDocuware; +}; diff --git a/modules/worker/back/methods/worker-dms/filter.js b/modules/worker/back/methods/worker-dms/filter.js index b7802a689..b92ba139b 100644 --- a/modules/worker/back/methods/worker-dms/filter.js +++ b/modules/worker/back/methods/worker-dms/filter.js @@ -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,6 +36,7 @@ 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 @@ -44,68 +45,27 @@ module.exports = Self => { 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, { - role: { - neq: null - } - }] - }; - stmt.merge(conn.makeSuffix(mergeWhere(filter.where, where))); - - // Get workerDms alloweds - 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({ - fields: ['dmsTypeFk'], - where: {code: 'hr', action: 'find'} - }); - const docuwareDmsType = docuware.dmsTypeFk; - 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', - 'Tipo Documento': 'description', - 'Stored on': 'created', - 'Document ID': 'id', - 'URL': 'download', - 'Stored by': 'name', - 'Estado': 'state' - }; - - workerDocuware = - await models.Docuware.getById('hr', worker.lastName + ' ' + worker.firstName, docuwareParse) ?? []; - const url = (await Self.app.models.Url.getUrl('docuware')) + 'WebClient'; - for (document of workerDocuware) { - const docuwareId = document.id; - const defaultData = { - id: docuwareId, - workerFk: id, - dmsFk: docuwareId, - dms: { - id: docuwareId, - file: docuwareId + '.pdf', - isDocuware: true, - hasFile: false, - reference: worker.fi, - dmsFk: docuwareId, - url, - description: document.description + ' - ' + document.state, - download: document.download, - created: document.created, - dmsType: {name: 'Docuware'}, - worker: {id: null, user: {name: document.name}}, + const yourOwnDms = { + or: [ + {and: [ + {isReadableByWorker: true}, + {worker: userId} + ]}, + { + role: { + neq: null } - }; - Object.assign(document, defaultData); - } - } - return workerDms.concat(workerDocuware); + }] + }; + 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}}}); + + const find = await models.WorkerDms.find(allowedFilter); + + return find; }; }; From 125c0c9b3b64fdc538ff8becfba50b45ac3c6675 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 10 Sep 2024 07:50:40 +0200 Subject: [PATCH 24/46] refactor: refs #6346 requested changes --- .../11088-bronzeAspidistra/00-firstScript.sql | 2 +- loopback/locale/en.json | 6 +- loopback/locale/es.json | 5 +- .../methods/wagonType/specs/wagonTray.spec.js | 58 +++++++++++++++++++ modules/wagon/back/models/wagon-type-tray.js | 7 +-- 5 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 modules/wagon/back/methods/wagonType/specs/wagonTray.spec.js diff --git a/db/versions/11088-bronzeAspidistra/00-firstScript.sql b/db/versions/11088-bronzeAspidistra/00-firstScript.sql index 98203c9d1..11effc5d2 100644 --- a/db/versions/11088-bronzeAspidistra/00-firstScript.sql +++ b/db/versions/11088-bronzeAspidistra/00-firstScript.sql @@ -1,6 +1,6 @@ DROP TABLE IF EXISTS vn.wagonTypeTray; -CREATE TABLE vn.wagonTypeTray ( +CREATE OR REPLACE TABLE vn.wagonTypeTray ( id INT UNSIGNED auto_increment NULL, wagonTypeFk int(11) unsigned NULL, height INT UNSIGNED NULL, diff --git a/loopback/locale/en.json b/loopback/locale/en.json index d9d9c8511..1753d1d07 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -236,6 +236,8 @@ "Cannot send mail": "Cannot send mail", "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`": "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`", "This postcode already exists": "This postcode already exists", - "Original invoice not found": "Original invoice not found" - + "Original invoice not found": "Original invoice not found", + "There is already a tray with the same height": "There is already a tray with the same height", + "The height must be greater than 50cm": "The height must be greater than 50cm", + "The maximum height of the wagon is 200cm": "The maximum height of the wagon is 200cm" } diff --git a/loopback/locale/es.json b/loopback/locale/es.json index d7c2d31a0..a14262c49 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -374,7 +374,6 @@ "Original invoice not found": "Factura original no encontrada", "The entry has no lines or does not exist": "La entrada no tiene lineas o no existe", "There is already a tray with the same height": "Ya existe una bandeja con la misma altura", - "You must define wagon and height": "Debes definir un tipo de vagón y la altura", - "The maximum height of the wagon is": "La altura máxima es %d", - "The height must be greater than": "The height must be greater than %d" + "The height must be greater than 50cm": "La altura debe ser superior a 50cm", + "The maximum height of the wagon is 200cm": "La altura máxima es 200cm" } \ No newline at end of file diff --git a/modules/wagon/back/methods/wagonType/specs/wagonTray.spec.js b/modules/wagon/back/methods/wagonType/specs/wagonTray.spec.js new file mode 100644 index 000000000..9e4ae0907 --- /dev/null +++ b/modules/wagon/back/methods/wagonType/specs/wagonTray.spec.js @@ -0,0 +1,58 @@ +const models = require('vn-loopback/server/server').models; + +fdescribe('WagonTray max height()', () => { + it(`should throw an error if the tray's height is above the maximum of the wagon`, async() => { + const tx = await models.WagonTypeTray.beginTransaction({}); + + let error; + try { + const options = {transaction: tx}; + + await models.WagonTypeTray.create({height: 210, wagonTypeFk: 1, wagonTypeColorFk: 4}, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toBe('The maximum height of the wagon is 200cm'); + }); + + it(`should throw an error if the tray's height is already in the wagon`, async() => { + const tx = await models.WagonTypeTray.beginTransaction({}); + + let error; + try { + const options = {transaction: tx}; + + await models.WagonTypeTray.create({height: 50, wagonTypeFk: 1, wagonTypeColorFk: 2}, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toBe('There is already a tray with the same height'); + }); + + it(`should throw an error if the tray's height is below the minimum between the trays`, async() => { + const tx = await models.WagonTypeTray.beginTransaction({}); + + let error; + try { + const options = {transaction: tx}; + + await models.WagonTypeTray.create({height: 40, wagonTypeFk: 1, wagonTypeColorFk: 4}, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toBe('The height must be greater than 50cm'); + }); +}); + diff --git a/modules/wagon/back/models/wagon-type-tray.js b/modules/wagon/back/models/wagon-type-tray.js index 5bcb1d3c7..219f20bfb 100644 --- a/modules/wagon/back/models/wagon-type-tray.js +++ b/modules/wagon/back/models/wagon-type-tray.js @@ -15,14 +15,11 @@ module.exports = Self => { if (tray.length) throw new UserError('There is already a tray with the same height'); - if (!wagonTypeFk && !height) - throw new UserError('You must define wagon and height'); - if (height < config.minHeightBetweenTrays) - throw new UserError('The height must be greater than', 'HEIGHT_GREATER_THAN', config.minHeightBetweenTrays); + throw new UserError('The height must be greater than 50cm'); if (height > config.maxWagonHeight) - throw new UserError('The maximum height of the wagon is', 'MAX_WAGON_HEIGHT', config.maxWagonHeight); + throw new UserError('The maximum height of the wagon is 200cm'); } }); }; From 97597156091e18cdea6529f941c5fc87eb77e199 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 10 Sep 2024 07:52:09 +0200 Subject: [PATCH 25/46] fix: refs #6346 created test --- db/.pullinfo.json | 2 +- modules/wagon/back/methods/wagonType/specs/wagonTray.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/.pullinfo.json b/db/.pullinfo.json index 27d2c7535..5b75584d1 100644 --- a/db/.pullinfo.json +++ b/db/.pullinfo.json @@ -9,7 +9,7 @@ }, "vn": { "view": { - "expeditionPallet_Print": "ced2b84a114fcb99fce05f0c34f4fc03f3fa387bef92621be1bc306608a84345" + "expeditionPallet_Print": "99f75145ac2e7b612a6d71e74b6e55f194a465780fd9875a15eb01e6596b447e" } } } diff --git a/modules/wagon/back/methods/wagonType/specs/wagonTray.spec.js b/modules/wagon/back/methods/wagonType/specs/wagonTray.spec.js index 9e4ae0907..783c1a621 100644 --- a/modules/wagon/back/methods/wagonType/specs/wagonTray.spec.js +++ b/modules/wagon/back/methods/wagonType/specs/wagonTray.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -fdescribe('WagonTray max height()', () => { +describe('WagonTray max height()', () => { it(`should throw an error if the tray's height is above the maximum of the wagon`, async() => { const tx = await models.WagonTypeTray.beginTransaction({}); From b492a1e6a8858f39f118bc0a356b14ff5f1b7860 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 11 Sep 2024 08:05:26 +0200 Subject: [PATCH 26/46] feat: refs #6868 refs# 6868 handleUser --- db/versions/11223-turquoiseLilium/00-firstScript.sql | 2 ++ modules/account/back/models/account.json | 7 ------- 2 files changed, 2 insertions(+), 7 deletions(-) create mode 100644 db/versions/11223-turquoiseLilium/00-firstScript.sql diff --git a/db/versions/11223-turquoiseLilium/00-firstScript.sql b/db/versions/11223-turquoiseLilium/00-firstScript.sql new file mode 100644 index 000000000..9003451c4 --- /dev/null +++ b/db/versions/11223-turquoiseLilium/00-firstScript.sql @@ -0,0 +1,2 @@ +INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) +VALUES( 'Device', 'handleUser', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/modules/account/back/models/account.json b/modules/account/back/models/account.json index 466b2bc04..fc1bbeb3d 100644 --- a/modules/account/back/models/account.json +++ b/modules/account/back/models/account.json @@ -31,13 +31,6 @@ "principalId": "$everyone", "permission": "ALLOW" }, - { - "property": "loginApp", - "accessType": "EXECUTE", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - }, { "property": "logout", "accessType": "EXECUTE", From 8dc83e244473b172cac65892ceef5b6de2183d3e Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 11 Sep 2024 08:16:21 +0200 Subject: [PATCH 27/46] feat: refs #7182 optimize workerDms filter --- .../worker/back/methods/worker-dms/filter.js | 57 ++++++++++++++++++- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/modules/worker/back/methods/worker-dms/filter.js b/modules/worker/back/methods/worker-dms/filter.js index b92ba139b..ed0490f54 100644 --- a/modules/worker/back/methods/worker-dms/filter.js +++ b/modules/worker/back/methods/worker-dms/filter.js @@ -57,15 +57,66 @@ module.exports = Self => { } }] }; + 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}}}); + const allowedFilter = mergeFilters(filter, {where: {dmsFk: {inq: allowedIds}, workerFk: id}}); - const find = await models.WorkerDms.find(allowedFilter); + const workerDms = await models.WorkerDms.find(allowedFilter); - return find; + const workerDocuware = filter.skip ? [] : await getDocuwareasync(ctx, id); + return workerDms.concat(workerDocuware); + + async function getDocuwareasync(ctx, id) { + const {dmsTypeFk} = await models.Docuware.findOne({ + 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 docuwareParse = { + 'Filename': 'dmsFk', + 'Tipo Documento': 'description', + 'Stored on': 'created', + 'Document ID': 'id', + 'URL': 'download', + 'Stored by': 'name', + 'Estado': 'state' + }; + + workerDocuware = + await models.Docuware.getById('hr', worker.lastName + ' ' + worker.firstName, docuwareParse) ?? []; + const url = (await Self.app.models.Url.getUrl('docuware')) + 'WebClient'; + for (document of workerDocuware) { + const docuwareId = document.id; + const defaultData = { + id: docuwareId, + workerFk: id, + dmsFk: docuwareId, + dms: { + id: docuwareId, + file: docuwareId + '.pdf', + isDocuware: true, + hasFile: false, + reference: worker.fi, + dmsFk: docuwareId, + url, + description: document.description + ' - ' + document.state, + download: document.download, + created: document.created, + dmsType: {name: 'Docuware'}, + worker: {id: null, user: {name: document.name}}, + } + }; + Object.assign(document, defaultData); + } + return workerDocuware; + } }; }; From fbfbf21e06f044ee929820e19d79279e8dd9433f Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 11 Sep 2024 08:17:18 +0200 Subject: [PATCH 28/46] fix: refs #7182 unnesesary file --- .../back/methods/worker-dms/docuwareFilter.js | 74 ------------------- 1 file changed, 74 deletions(-) delete mode 100644 modules/worker/back/methods/worker-dms/docuwareFilter.js diff --git a/modules/worker/back/methods/worker-dms/docuwareFilter.js b/modules/worker/back/methods/worker-dms/docuwareFilter.js deleted file mode 100644 index 0311153b0..000000000 --- a/modules/worker/back/methods/worker-dms/docuwareFilter.js +++ /dev/null @@ -1,74 +0,0 @@ -module.exports = Self => { - Self.remoteMethodCtx('filter', { - description: 'Find docuware documents', - accessType: 'READ', - accepts: [ - { - arg: 'id', - type: 'number', - description: 'The worker id', - http: {source: 'path'} - } - ], - returns: { - type: ['object'], - root: true - }, - http: { - path: `/:id/filter`, - verb: 'GET' - } - }); - - Self.filter = async(ctx, id) => { - const models = Self.app.models; - - const {dmsTypeFk} = await models.Docuware.findOne({ - 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 docuwareParse = { - 'Filename': 'dmsFk', - 'Tipo Documento': 'description', - 'Stored on': 'created', - 'Document ID': 'id', - 'URL': 'download', - 'Stored by': 'name', - 'Estado': 'state' - }; - - workerDocuware = - await models.Docuware.getById('hr', worker.lastName + ' ' + worker.firstName, docuwareParse) ?? []; - const url = (await Self.app.models.Url.getUrl('docuware')) + 'WebClient'; - for (document of workerDocuware) { - const docuwareId = document.id; - const defaultData = { - id: docuwareId, - workerFk: id, - dmsFk: docuwareId, - dms: { - id: docuwareId, - file: docuwareId + '.pdf', - isDocuware: true, - hasFile: false, - reference: worker.fi, - dmsFk: docuwareId, - url, - description: document.description + ' - ' + document.state, - download: document.download, - created: document.created, - dmsType: {name: 'Docuware'}, - worker: {id: null, user: {name: document.name}}, - } - }; - Object.assign(document, defaultData); - } - }; - - return workerDocuware; -}; From c21da8d258196466544549fadad1c7cd7b54c823 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 11 Sep 2024 10:31:43 +0200 Subject: [PATCH 29/46] fix: refs #7182 function name --- modules/worker/back/methods/worker-dms/filter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/worker/back/methods/worker-dms/filter.js b/modules/worker/back/methods/worker-dms/filter.js index ed0490f54..394988f9e 100644 --- a/modules/worker/back/methods/worker-dms/filter.js +++ b/modules/worker/back/methods/worker-dms/filter.js @@ -67,10 +67,10 @@ module.exports = Self => { const workerDms = await models.WorkerDms.find(allowedFilter); - const workerDocuware = filter.skip ? [] : await getDocuwareasync(ctx, id); + const workerDocuware = filter.skip ? [] : await getDocuware(ctx, id); return workerDms.concat(workerDocuware); - async function getDocuwareasync(ctx, id) { + async function getDocuware(ctx, id) { const {dmsTypeFk} = await models.Docuware.findOne({ fields: ['dmsTypeFk'], where: {code: 'hr', action: 'find'} From 87182abf7ed82754f44e66bc42c34471aa9a6ee9 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 11 Sep 2024 12:47:51 +0200 Subject: [PATCH 30/46] fix: available refs #6861 --- db/routines/vn/procedures/itemShelving_add.sql | 5 ++++- db/routines/vn/procedures/sale_boxPickingPrint.sql | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/itemShelving_add.sql b/db/routines/vn/procedures/itemShelving_add.sql index a1bca5b6c..ed22b9d92 100644 --- a/db/routines/vn/procedures/itemShelving_add.sql +++ b/db/routines/vn/procedures/itemShelving_add.sql @@ -46,7 +46,8 @@ BEGIN AND buyFk = vBuyFk) THEN UPDATE itemShelving - SET visible = visible + vQuantity + SET visible = visible + vQuantity, + available = available + vQuantity WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking; ELSE @@ -55,6 +56,7 @@ BEGIN itemFk, shelvingFk, visible, + available, grouping, packing, packagingFk, @@ -62,6 +64,7 @@ BEGIN SELECT vItemFk, vShelvingFk, vQuantity, + available, IFNULL(vGrouping, b.grouping), IFNULL(vPacking, b.packing), IFNULL(vPackagingFk, b.packagingFk), diff --git a/db/routines/vn/procedures/sale_boxPickingPrint.sql b/db/routines/vn/procedures/sale_boxPickingPrint.sql index dbb3b6c14..bf7afbf7d 100644 --- a/db/routines/vn/procedures/sale_boxPickingPrint.sql +++ b/db/routines/vn/procedures/sale_boxPickingPrint.sql @@ -160,7 +160,10 @@ w1: WHILE vQuantity >= vPacking DO UPDATE sale SET quantity = quantity - vPacking WHERE id = vSaleFk; - UPDATE itemShelving SET visible = visible - vPacking WHERE id = vItemShelvingFk; + UPDATE itemShelving + SET visible = visible - vPacking, + available = available - vPacking + WHERE id = vItemShelvingFk; SET vNewSaleFk = NULL; From db7d5c5e5289769d642663242727680309a07eb5 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 11 Sep 2024 13:18:09 +0200 Subject: [PATCH 31/46] fix: available refs #6861 --- db/routines/vn/procedures/itemShelving_add.sql | 2 -- 1 file changed, 2 deletions(-) diff --git a/db/routines/vn/procedures/itemShelving_add.sql b/db/routines/vn/procedures/itemShelving_add.sql index ed22b9d92..3f6c1f39d 100644 --- a/db/routines/vn/procedures/itemShelving_add.sql +++ b/db/routines/vn/procedures/itemShelving_add.sql @@ -56,7 +56,6 @@ BEGIN itemFk, shelvingFk, visible, - available, grouping, packing, packagingFk, @@ -64,7 +63,6 @@ BEGIN SELECT vItemFk, vShelvingFk, vQuantity, - available, IFNULL(vGrouping, b.grouping), IFNULL(vPacking, b.packing), IFNULL(vPackagingFk, b.packagingFk), From d15be5100d8b58cfad3ee673f0008b30196582e6 Mon Sep 17 00:00:00 2001 From: ivanm Date: Wed, 11 Sep 2024 13:42:04 +0200 Subject: [PATCH 32/46] refactor: refs #7952 Deprecate creditInsurance.creditClassification --- db/routines/vn/procedures/creditInsurance_getRisk.sql | 2 +- .../vn/triggers/creditInsurance_afterInsert.sql | 2 +- .../vn/triggers/creditInsurance_beforeInsert.sql | 10 ---------- db/routines/vn/triggers/solunionCAP_afterInsert.sql | 2 +- db/routines/vn/triggers/solunionCAP_afterUpdate.sql | 4 ++-- db/routines/vn/triggers/solunionCAP_beforeDelete.sql | 2 +- db/versions/11224-whiteMastic/00-firstScript.sql | 2 ++ 7 files changed, 8 insertions(+), 16 deletions(-) delete mode 100644 db/routines/vn/triggers/creditInsurance_beforeInsert.sql create mode 100644 db/versions/11224-whiteMastic/00-firstScript.sql diff --git a/db/routines/vn/procedures/creditInsurance_getRisk.sql b/db/routines/vn/procedures/creditInsurance_getRisk.sql index ea19f8aef..5562c91d4 100644 --- a/db/routines/vn/procedures/creditInsurance_getRisk.sql +++ b/db/routines/vn/procedures/creditInsurance_getRisk.sql @@ -10,7 +10,7 @@ BEGIN SELECT * FROM ( SELECT cc.client clientFk, ci.grade FROM creditClassification cc - JOIN creditInsurance ci ON cc.id = ci.creditClassification + JOIN creditInsurance ci ON cc.id = ci.creditClassificationFk WHERE dateEnd IS NULL ORDER BY ci.creationDate DESC LIMIT 10000000000000000000) t1 diff --git a/db/routines/vn/triggers/creditInsurance_afterInsert.sql b/db/routines/vn/triggers/creditInsurance_afterInsert.sql index c865f31a4..f4857a730 100644 --- a/db/routines/vn/triggers/creditInsurance_afterInsert.sql +++ b/db/routines/vn/triggers/creditInsurance_afterInsert.sql @@ -5,7 +5,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`creditInsurance_afterIn BEGIN UPDATE `client` c JOIN vn.creditClassification cc ON cc.client = c.id - SET creditInsurance = NEW.credit WHERE cc.id = NEW.creditClassification; + SET creditInsurance = NEW.credit WHERE cc.id = NEW.creditClassificationFk; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/creditInsurance_beforeInsert.sql b/db/routines/vn/triggers/creditInsurance_beforeInsert.sql deleted file mode 100644 index 8e036d373..000000000 --- a/db/routines/vn/triggers/creditInsurance_beforeInsert.sql +++ /dev/null @@ -1,10 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`creditInsurance_beforeInsert` - BEFORE INSERT ON `creditInsurance` - FOR EACH ROW -BEGIN - IF NEW.creditClassificationFk THEN - SET NEW.creditClassification = NEW.creditClassificationFk; - END IF; -END$$ -DELIMITER ; diff --git a/db/routines/vn/triggers/solunionCAP_afterInsert.sql b/db/routines/vn/triggers/solunionCAP_afterInsert.sql index b4df7dc61..d09cadd95 100644 --- a/db/routines/vn/triggers/solunionCAP_afterInsert.sql +++ b/db/routines/vn/triggers/solunionCAP_afterInsert.sql @@ -5,7 +5,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`solunionCAP_afterInsert BEGIN UPDATE client c JOIN creditClassification cc ON cc.client = c.id - JOIN creditInsurance ci ON ci.creditClassification = cc.id + JOIN creditInsurance ci ON ci.creditClassificationFk = cc.id SET creditInsurance = ci.credit * 2 WHERE ci.id = NEW.creditInsurance; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/solunionCAP_afterUpdate.sql b/db/routines/vn/triggers/solunionCAP_afterUpdate.sql index ccfba96f2..1199067bb 100644 --- a/db/routines/vn/triggers/solunionCAP_afterUpdate.sql +++ b/db/routines/vn/triggers/solunionCAP_afterUpdate.sql @@ -6,12 +6,12 @@ BEGIN IF NEW.dateLeaving IS NOT NULL THEN UPDATE client c JOIN creditClassification cc ON cc.client = c.id - JOIN creditInsurance ci ON ci.creditClassification = cc.id + JOIN creditInsurance ci ON ci.creditClassificationFk = cc.id SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance; ELSE UPDATE client c JOIN creditClassification cc ON cc.client = c.id - JOIN creditInsurance ci ON ci.creditClassification = cc.id + JOIN creditInsurance ci ON ci.creditClassificationFk = cc.id SET creditInsurance = ci.credit * 2 WHERE ci.id = OLD.creditInsurance; END IF; END$$ diff --git a/db/routines/vn/triggers/solunionCAP_beforeDelete.sql b/db/routines/vn/triggers/solunionCAP_beforeDelete.sql index a8b6732c1..7913a0d78 100644 --- a/db/routines/vn/triggers/solunionCAP_beforeDelete.sql +++ b/db/routines/vn/triggers/solunionCAP_beforeDelete.sql @@ -5,7 +5,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`solunionCAP_beforeDelet BEGIN UPDATE client c JOIN creditClassification cc ON cc.client = c.id - JOIN creditInsurance ci ON ci.creditClassification = cc.id + JOIN creditInsurance ci ON ci.creditClassificationFk = cc.id SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance; END$$ DELIMITER ; diff --git a/db/versions/11224-whiteMastic/00-firstScript.sql b/db/versions/11224-whiteMastic/00-firstScript.sql new file mode 100644 index 000000000..52267cd91 --- /dev/null +++ b/db/versions/11224-whiteMastic/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.creditInsurance + CHANGE creditClassification creditClassification__ int(11) DEFAULT NULL COMMENT '@deprecated 2024-09-11'; From 7e06c2ab37eefd06b850c01645cf4d66f99e2515 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 11 Sep 2024 13:57:03 +0200 Subject: [PATCH 33/46] fix: available refs #6861 --- db/routines/vn/procedures/itemShelving_add.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/itemShelving_add.sql b/db/routines/vn/procedures/itemShelving_add.sql index 3f6c1f39d..98ec9b088 100644 --- a/db/routines/vn/procedures/itemShelving_add.sql +++ b/db/routines/vn/procedures/itemShelving_add.sql @@ -69,6 +69,6 @@ BEGIN id FROM buy b WHERE id = vBuyFk; - END IF; + END IF; END$$ DELIMITER ; \ No newline at end of file From 0feb44e404307638223a753e442dd7cd13e3110e Mon Sep 17 00:00:00 2001 From: ivanm Date: Wed, 11 Sep 2024 15:07:37 +0200 Subject: [PATCH 34/46] refactor: refs #7923 Delete Logiflora functions --- db/routines/edi/events/floramondo.sql | 8 - .../procedures/floramondo_offerRefresh.sql | 522 ------------------ .../vn/functions/entry_getForLogiflora.sql | 64 --- .../vn/functions/travel_getForLogiflora.sql | 52 -- 4 files changed, 646 deletions(-) delete mode 100644 db/routines/edi/events/floramondo.sql delete mode 100644 db/routines/edi/procedures/floramondo_offerRefresh.sql delete mode 100644 db/routines/vn/functions/entry_getForLogiflora.sql delete mode 100644 db/routines/vn/functions/travel_getForLogiflora.sql diff --git a/db/routines/edi/events/floramondo.sql b/db/routines/edi/events/floramondo.sql deleted file mode 100644 index 0a38f3537..000000000 --- a/db/routines/edi/events/floramondo.sql +++ /dev/null @@ -1,8 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `edi`.`floramondo` - ON SCHEDULE EVERY 6 MINUTE - STARTS '2022-01-28 09:52:45.000' - ON COMPLETION NOT PRESERVE - DISABLE -DO CALL edi.floramondo_offerRefresh()$$ -DELIMITER ; diff --git a/db/routines/edi/procedures/floramondo_offerRefresh.sql b/db/routines/edi/procedures/floramondo_offerRefresh.sql deleted file mode 100644 index 18d3f8b7e..000000000 --- a/db/routines/edi/procedures/floramondo_offerRefresh.sql +++ /dev/null @@ -1,522 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`floramondo_offerRefresh`() -proc: BEGIN - DECLARE vLanded DATETIME; - DECLARE vDone INT DEFAULT FALSE; - DECLARE vFreeId INT; - DECLARE vSupplyResponseFk INT; - DECLARE vLastInserted DATETIME; - DECLARE vIsAuctionDay BOOLEAN; - DECLARE vMaxNewItems INT DEFAULT 10000; - DECLARE vStartingTime DATETIME; - DECLARE vAalsmeerMarketPlaceID VARCHAR(13) DEFAULT '8713783439043'; - DECLARE vDayRange INT; - - DECLARE cur1 CURSOR FOR - SELECT id - FROM edi.item_free; - - DECLARE cur2 CURSOR FOR - SELECT srId - FROM itemToInsert; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - DECLARE EXIT HANDLER FOR SQLSTATE '45000' - BEGIN - ROLLBACK; - RESIGNAL; - END; - - DECLARE CONTINUE HANDLER FOR SQLEXCEPTION - BEGIN - DO RELEASE_LOCK('edi.floramondo_offerRefresh'); - SET @isTriggerDisabled = FALSE; - RESIGNAL; - END; - - IF 'test' = (SELECT environment FROM util.config) THEN - LEAVE proc; - END IF; - - IF !GET_LOCK('edi.floramondo_offerRefresh', 0) THEN - LEAVE proc; - END IF; - - SELECT dayRange INTO vDayRange - FROM offerRefreshConfig; - - IF vDayRange IS NULL THEN - CALL util.throw("Variable vDayRange not declared"); - END IF; - - SET vStartingTime = util.VN_NOW(); - - TRUNCATE edi.offerList; - - INSERT INTO edi.offerList(supplier, total) - SELECT v.name, COUNT(DISTINCT sr.ID) total - FROM edi.supplyResponse sr - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - WHERE sr.NumberOfUnits > 0 - AND sr.EmbalageCode != 999 - GROUP BY sr.vmpID; - - UPDATE edi.offerList o - JOIN (SELECT v.name, COUNT(*) total - FROM edi.supplyOffer sr - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - GROUP BY sr.vmpID) sub ON o.supplier = sub.name - SET o.`filter` = sub.total; - - -- Elimina de la lista de items libres aquellos que ya existen - DELETE itf.* - FROM edi.item_free itf - JOIN vn.item i ON i.id = itf.id; - - CREATE OR REPLACE TEMPORARY TABLE tmp - (INDEX (`Item_ArticleCode`)) - ENGINE = MEMORY - SELECT t.* - FROM ( - SELECT * - FROM edi.supplyOffer - ORDER BY (MarketPlaceID = vAalsmeerMarketPlaceID) DESC, - NumberOfUnits DESC LIMIT 10000000000000000000) t - GROUP BY t.srId; - - CREATE OR REPLACE TEMPORARY TABLE edi.offer (INDEX (`srID`), INDEX (`EmbalageCode`), - INDEX (`ef1`), INDEX (`ef2`), INDEX (`ef3`), INDEX (`ef4`),INDEX (`ef5`), INDEX (`ef6`), - INDEX (`s1Value`), INDEX (`s2Value`), INDEX (`s3Value`), INDEX (`s4Value`),INDEX (`s5Value`), INDEX (`s6Value`)) - ENGINE = MEMORY - SELECT so.*, - ev1.type_description s1Value, - ev2.type_description s2Value, - ev3.type_description s3Value, - ev4.type_description s4Value, - ev5.type_description s5Value, - ev6.type_description s6Value, - eif1.feature ef1, - eif2.feature ef2, - eif3.feature ef3, - eif4.feature ef4, - eif5.feature ef5, - eif6.feature ef6 - FROM tmp so - LEFT JOIN edi.item_feature eif1 ON eif1.item_id = so.Item_ArticleCode - AND eif1.presentation_order = 1 - AND eif1.expiry_date IS NULL - LEFT JOIN edi.item_feature eif2 ON eif2.item_id = so.Item_ArticleCode - AND eif2.presentation_order = 2 - AND eif2.expiry_date IS NULL - LEFT JOIN edi.item_feature eif3 ON eif3.item_id = so.Item_ArticleCode - AND eif3.presentation_order = 3 - AND eif3.expiry_date IS NULL - LEFT JOIN edi.item_feature eif4 ON eif4.item_id = so.Item_ArticleCode - AND eif4.presentation_order = 4 - AND eif4.expiry_date IS NULL - LEFT JOIN edi.item_feature eif5 ON eif5.item_id = so.Item_ArticleCode - AND eif5.presentation_order = 5 - AND eif5.expiry_date IS NULL - LEFT JOIN edi.item_feature eif6 ON eif6.item_id = so.Item_ArticleCode - AND eif6.presentation_order = 6 - AND eif6.expiry_date IS NULL - LEFT JOIN edi.`value` ev1 ON ev1.type_id = eif1.feature - AND so.s1 = ev1.type_value - LEFT JOIN edi.`value` ev2 ON ev2.type_id = eif2.feature - AND so.s2 = ev2.type_value - LEFT JOIN edi.`value` ev3 ON ev3.type_id = eif3.feature - AND so.s3 = ev3.type_value - LEFT JOIN edi.`value` ev4 ON ev4.type_id = eif4.feature - AND so.s4 = ev4.type_value - LEFT JOIN edi.`value` ev5 ON ev5.type_id = eif5.feature - AND so.s5 = ev5.type_value - LEFT JOIN edi.`value` ev6 ON ev6.type_id = eif6.feature - AND so.s6 = ev6.type_value - ORDER BY Price; - - DROP TEMPORARY TABLE tmp; - - DELETE o - FROM edi.offer o - LEFT JOIN vn.tag t1 ON t1.ediTypeFk = o.ef1 AND t1.overwrite = 'size' - LEFT JOIN vn.tag t2 ON t2.ediTypeFk = o.ef2 AND t2.overwrite = 'size' - LEFT JOIN vn.tag t3 ON t3.ediTypeFk = o.ef3 AND t3.overwrite = 'size' - LEFT JOIN vn.tag t4 ON t4.ediTypeFk = o.ef4 AND t4.overwrite = 'size' - LEFT JOIN vn.tag t5 ON t5.ediTypeFk = o.ef5 AND t5.overwrite = 'size' - LEFT JOIN vn.tag t6 ON t6.ediTypeFk = o.ef6 AND t6.overwrite = 'size' - JOIN vn.floramondoConfig fc ON TRUE - WHERE (t1.id IS NOT NULL AND CONVERT(s1Value, UNSIGNED) > fc.itemMaxSize) - OR (t2.id IS NOT NULL AND CONVERT(s2Value, UNSIGNED) > fc.itemMaxSize) - OR (t3.id IS NOT NULL AND CONVERT(s3Value, UNSIGNED) > fc.itemMaxSize) - OR (t4.id IS NOT NULL AND CONVERT(s4Value, UNSIGNED) > fc.itemMaxSize) - OR (t5.id IS NOT NULL AND CONVERT(s5Value, UNSIGNED) > fc.itemMaxSize) - OR (t6.id IS NOT NULL AND CONVERT(s6Value, UNSIGNED) > fc.itemMaxSize); - - START TRANSACTION; - - -- Actualizamos el campo supplyResponseFk para aquellos articulos que ya estan creados y reutilizamos - UPDATE IGNORE edi.offer o - JOIN vn.item i - ON i.name = o.product_name - AND i.subname <=> o.company_name - AND i.value5 <=> o.s1Value - AND i.value6 <=> o.s2Value - AND i.value7 <=> o.s3Value - AND i.value8 <=> o.s4Value - AND i.value9 <=> o.s5Value - AND i.value10 <=> o.s6Value - AND i.NumberOfItemsPerCask <=> o.NumberOfItemsPerCask - AND i.EmbalageCode <=> o.EmbalageCode - AND i.quality <=> o.Quality - JOIN vn.itemType it ON it.id = i.typeFk - LEFT JOIN vn.sale s ON s.itemFk = i.id - LEFT JOIN vn.ticket t ON t.id = s.ticketFk - AND t.shipped > (util.VN_CURDATE() - INTERVAL 1 WEEK) - LEFT JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - LEFT JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID - LEFT JOIN edi.putOrder po ON po.supplyResponseID = i.supplyResponseFk - AND po.OrderTradeLineDateTime > (util.VN_CURDATE() - INTERVAL 1 WEEK) - SET i.supplyResponseFk = o.srID - WHERE (sr.ID IS NULL - OR sr.NumberOfUnits = 0 - OR di.LatestOrderDateTime < util.VN_NOW() - OR di.ID IS NULL) - AND it.isInventory - AND t.id IS NULL - AND po.id IS NULL; - - CREATE OR REPLACE TEMPORARY TABLE itemToInsert - ENGINE = MEMORY - SELECT o.*, CAST(NULL AS DECIMAL(6,0)) itemFk - FROM edi.offer o - LEFT JOIN vn.item i ON i.supplyResponseFk = o.srId - WHERE i.id IS NULL - LIMIT vMaxNewItems; - - -- Reciclado de nº de item - OPEN cur1; - OPEN cur2; - - read_loop: LOOP - - FETCH cur2 INTO vSupplyResponseFk; - FETCH cur1 INTO vFreeId; - - IF vDone THEN - LEAVE read_loop; - END IF; - - UPDATE itemToInsert - SET itemFk = vFreeId - WHERE srId = vSupplyResponseFk; - - END LOOP; - - CLOSE cur1; - CLOSE cur2; - - -- Insertamos todos los items en Articles de la oferta - INSERT INTO vn.item(id, - `name`, - longName, - subName, - expenseFk, - typeFk, - intrastatFk, - originFk, - supplyResponseFk, - numberOfItemsPerCask, - embalageCode, - quality, - isFloramondo) - SELECT iti.itemFk, - iti.product_name, - iti.product_name, - iti.company_name, - iti.expenseFk, - iti.itemTypeFk, - iti.intrastatFk, - iti.originFk, - iti.`srId`, - iti.NumberOfItemsPerCask, - iti.EmbalageCode, - iti.Quality, - TRUE - FROM itemToInsert iti; - - -- Inserta la foto de los articulos nuevos (prioridad alta) - INSERT IGNORE INTO vn.itemImageQueue(itemFk, url) - SELECT i.id, PictureReference - FROM itemToInsert ii - JOIN vn.item i ON i.supplyResponseFk = ii.srId - WHERE PictureReference IS NOT NULL - AND i.image IS NULL; - - INSERT INTO edi.`log`(tableName, fieldName,fieldValue) - SELECT 'itemImageQueue','NumImagenesPtes', COUNT(*) - FROM vn.itemImageQueue - WHERE attempts = 0; - - -- Inserta si se añadiesen tags nuevos - INSERT IGNORE INTO vn.tag (name, ediTypeFk) - SELECT description, type_id FROM edi.type; - - -- Desabilita el trigger para recalcular los tags al final - SET @isTriggerDisabled = TRUE; - - -- Inserta los tags sólo en los articulos nuevos - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.product_name, 1 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Producto' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ii.product_name IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.Quality, 3 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Calidad' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ii.Quality IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.company_name, 4 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Productor' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ii.company_name IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s1Value, 5 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef1 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s1Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s2Value, 6 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef2 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s2Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s3Value, 7 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef3 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s3Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s4Value, 8 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef4 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s4Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s5Value, 9 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef5 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s5Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s6Value, 10 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef6 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s6Value IS NULL; - - INSERT IGNORE INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id, IFNULL(ink.name, ik.color), 11 - FROM itemToInsert ii - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - JOIN vn.tag t ON t.`name` = 'Color' - LEFT JOIN edi.feature f ON f.item_id = ii.Item_ArticleCode - LEFT JOIN edi.`type` tp ON tp.type_id = f.feature_type_id - AND tp.`description` = 'Hoofdkleur 1' - LEFT JOIN vn.ink ON ink.dutchCode = f.feature_value - LEFT JOIN vn.itemInk ik ON ik.longName = i.longName - WHERE ink.name IS NOT NULL - OR ik.color IS NOT NULL; - - CREATE OR REPLACE TABLE tmp.item - (PRIMARY KEY (id)) - SELECT i.id FROM vn.item i - JOIN itemToInsert ii ON i.supplyResponseFk = ii.`srId`; - - CALL vn.item_refreshTags(); - - DROP TABLE tmp.item; - - SELECT MIN(LatestDeliveryDateTime) INTO vLanded - FROM edi.supplyResponse sr - JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID - JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID - JOIN vn.floramondoConfig fc - WHERE mp.isLatestOrderDateTimeRelevant - AND di.LatestOrderDateTime > IF( - fc.MaxLatestOrderHour > HOUR(util.VN_NOW()), - util.VN_CURDATE(), - util.VN_CURDATE() + INTERVAL 1 DAY); - - UPDATE vn.floramondoConfig - SET nextLanded = vLanded - WHERE vLanded IS NOT NULL; - - -- Elimina la oferta obsoleta - UPDATE vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.agencyMode am ON am.id = tr.agencyModeFk - JOIN vn.item i ON i.id = b.itemFk - LEFT JOIN edi.supplyResponse sr ON i.supplyResponseFk = sr.ID - LEFT JOIN edi.deliveryInformation di ON di.ID = b.deliveryFk - SET b.quantity = 0 - WHERE (IFNULL(di.LatestOrderDateTime,util.VN_NOW()) <= util.VN_NOW() - OR i.supplyResponseFk IS NULL - OR sr.NumberOfUnits = 0) - AND am.name = 'LOGIFLORA' - AND e.isRaid; - - -- Localiza las entradas de cada almacen - UPDATE edi.warehouseFloramondo - SET entryFk = vn.entry_getForLogiflora(vLanded + INTERVAL travellingDays DAY, warehouseFk); - - IF vLanded IS NOT NULL THEN - -- Actualiza la oferta existente - UPDATE vn.buy b - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.offer o ON i.supplyResponseFk = o.`srId` - SET b.quantity = o.NumberOfUnits * o.NumberOfItemsPerCask, - b.buyingValue = o.price - WHERE (b.quantity <> o.NumberOfUnits * o.NumberOfItemsPerCask - OR b.buyingValue <> o.price); - - -- Inserta el resto - SET vLastInserted := util.VN_NOW(); - - -- Inserta la oferta - INSERT INTO vn.buy ( - entryFk, - itemFk, - quantity, - buyingValue, - stickers, - packing, - `grouping`, - groupingMode, - packagingFk, - deliveryFk) - SELECT wf.entryFk, - i.id, - o.NumberOfUnits * o.NumberOfItemsPerCask quantity, - o.Price, - o.NumberOfUnits etiquetas, - o.NumberOfItemsPerCask packing, - GREATEST(1, IFNULL(o.MinimumQuantity,0)) * o.NumberOfItemsPerCask `grouping`, - 'packing', - o.embalageCode, - o.diId - FROM edi.offer o - JOIN vn.item i ON i.supplyResponseFk = o.srId - JOIN edi.warehouseFloramondo wf - JOIN vn.packaging p ON p.id - LIKE o.embalageCode - LEFT JOIN vn.buy b ON b.itemFk = i.id - AND b.entryFk = wf.entryFk - WHERE b.id IS NULL; -- Quitar esta linea y mirar de crear los packages a tiempo REAL - - INSERT INTO vn.itemCost( - itemFk, - warehouseFk, - cm3, - cm3delivery) - SELECT b.itemFk, - wf.warehouseFk, - @cm3 := vn.buy_getUnitVolume(b.id), - IFNULL((vc.standardFlowerBox * 1000) / i.packingOut, @cm3) - FROM warehouseFloramondo wf - JOIN vn.volumeConfig vc - JOIN vn.buy b ON b.entryFk = wf.entryFk - JOIN vn.item i ON i.id = b.itemFk - LEFT JOIN vn.itemCost ic ON ic.itemFk = b.itemFk - AND ic.warehouseFk = wf.warehouseFk - WHERE (ic.cm3 IS NULL OR ic.cm3 = 0) - ON DUPLICATE KEY UPDATE cm3 = @cm3, cm3delivery = IFNULL((vc.standardFlowerBox * 1000) / i.packingOut, @cm3); - - CREATE OR REPLACE TEMPORARY TABLE tmp.buyRecalc - SELECT b.id - FROM vn.buy b - JOIN warehouseFloramondo wf ON wf.entryFk = b.entryFk - WHERE b.created >= vLastInserted; - - CALL vn.buy_recalcPrices(); - - UPDATE edi.offerList o - JOIN (SELECT v.name, COUNT(DISTINCT b.itemFk) total - FROM vn.buy b - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - JOIN vn.warehouse w ON w.id = wf.warehouseFk - WHERE w.name = 'VNH' - AND b.quantity > 0 - GROUP BY sr.vmpID) sub ON o.supplier = sub.name - SET o.vnh = sub.total; - - UPDATE edi.offerList o - JOIN (SELECT v.name, COUNT(DISTINCT b.itemFk) total - FROM vn.buy b - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - JOIN vn.warehouse w ON w.id = wf.warehouseFk - WHERE w.name = 'ALGEMESI' - AND b.quantity > 0 - GROUP BY sr.vmpID) sub ON o.supplier = sub.name - SET o.algemesi = sub.total; - END IF; - - DROP TEMPORARY TABLE - edi.offer, - itemToInsert; - - SET @isTriggerDisabled = FALSE; - - COMMIT; - - -- Esto habria que pasarlo a procesos programados o trabajar con tags y dejar las familias - UPDATE vn.item i - SET typeFk = 121 - WHERE i.longName LIKE 'Rosa Garden %' - AND typeFk = 17; - - UPDATE vn.item i - SET typeFk = 156 - WHERE i.longName LIKE 'Rosa ec %' - AND typeFk = 17; - - -- Refresca las fotos de los items existentes que mostramos (prioridad baja) - INSERT IGNORE INTO vn.itemImageQueue(itemFk, url, priority) - SELECT i.id, sr.PictureReference, 100 - FROM edi.supplyResponse sr - JOIN vn.item i ON i.supplyResponseFk = sr.ID - JOIN edi.supplyOffer so ON so.srId = sr.ID - JOIN hedera.image i2 ON i2.name = i.image - AND i2.collectionFk = 'catalog' - WHERE i2.updated <= (UNIX_TIMESTAMP(util.VN_NOW()) - vDayRange) - AND sr.NumberOfUnits; - - INSERT INTO edi.`log` - SET tableName = 'floramondo_offerRefresh', - fieldName = 'Tiempo de proceso', - fieldValue = TIMEDIFF(util.VN_NOW(), vStartingTime); - - DO RELEASE_LOCK('edi.floramondo_offerRefresh'); -END$$ -DELIMITER ; diff --git a/db/routines/vn/functions/entry_getForLogiflora.sql b/db/routines/vn/functions/entry_getForLogiflora.sql deleted file mode 100644 index 57e787afa..000000000 --- a/db/routines/vn/functions/entry_getForLogiflora.sql +++ /dev/null @@ -1,64 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`entry_getForLogiflora`(vLanded DATE, vWarehouseFk INT) - RETURNS int(11) - NOT DETERMINISTIC - READS SQL DATA -BEGIN - - /** - * Devuelve una entrada para Logiflora. Si no existe la crea. - * - * @param vLanded Fecha de llegada al almacén - * @param vWarehouseFk Identificador de vn.warehouse - */ - - DECLARE vTravelFk INT; - DECLARE vEntryFk INT; - DECLARE previousEntryFk INT; - - SET vTravelFk = vn.travel_getForLogiflora(vLanded, vWarehouseFk); - - IF vLanded THEN - - SELECT IFNULL(MAX(id),0) INTO vEntryFk - FROM vn.entry - WHERE travelFk = vTravelFk - AND isRaid; - - IF NOT vEntryFk THEN - - INSERT INTO vn.entry(travelFk, supplierFk, commission, companyFk, currencyFk, isRaid) - SELECT vTravelFk, s.id, 4, c.id, cu.id, TRUE - FROM vn.supplier s - JOIN vn.company c ON c.code = 'VNL' - JOIN vn.currency cu ON cu.code = 'EUR' - WHERE s.name = 'KONINKLIJE COOPERATIEVE BLOEMENVEILING FLORAHOLLAN'; - - SELECT MAX(id) INTO vEntryFk - FROM vn.entry - WHERE travelFk = vTravelFk; - - END IF; - - END IF; - - SELECT entryFk INTO previousEntryFk - FROM edi.warehouseFloramondo wf - WHERE wf.warehouseFk = vWarehouseFk; - - IF IFNULL(previousEntryFk,0) != vEntryFk THEN - - UPDATE buy b - SET b.printedStickers = 0 - WHERE entryFk = previousEntryFk; - - DELETE FROM buy WHERE entryFk = previousEntryFk; - - DELETE FROM entry WHERE id = previousEntryFk; - - END IF; - - RETURN vEntryFk; - -END$$ -DELIMITER ; diff --git a/db/routines/vn/functions/travel_getForLogiflora.sql b/db/routines/vn/functions/travel_getForLogiflora.sql deleted file mode 100644 index 39c3086b7..000000000 --- a/db/routines/vn/functions/travel_getForLogiflora.sql +++ /dev/null @@ -1,52 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`travel_getForLogiflora`(vLanded DATE, vWarehouseFk INT) - RETURNS int(11) - NOT DETERMINISTIC - READS SQL DATA -BEGIN - - /** - * Devuelve un número de travel para compras de Logiflora a partir de la fecha de llegada y del almacén. - * Si no existe lo genera. - * - * @param vLanded Fecha de llegada al almacén - * @param vWarehouseFk Identificador de vn.warehouse - */ - - DECLARE vTravelFk INT; - - IF vLanded THEN - - SELECT IFNULL(MAX(tr.id),0) INTO vTravelFk - FROM vn.travel tr - JOIN vn.warehouse wIn ON wIn.id = tr.warehouseInFk - JOIN vn.warehouse wOut ON wOut.id = tr.warehouseOutFk - JOIN vn.agencyMode am ON am.id = tr.agencyModeFk - WHERE wIn.id = vWarehouseFk - AND wOut.name = 'Holanda' - AND am.name = 'LOGIFLORA' - AND landed = vLanded; - - IF NOT vTravelFk THEN - - INSERT INTO vn.travel(landed, shipped, warehouseInFk, warehouseOutFk, agencyModeFk) - SELECT vLanded, util.VN_CURDATE(), vWarehouseFk, wOut.id, am.id - FROM vn.warehouse wOut - JOIN vn.agencyMode am ON am.name = 'LOGIFLORA' - WHERE wOut.name = 'Holanda'; - - SELECT MAX(tr.id) INTO vTravelFk - FROM vn.travel tr - JOIN vn.warehouse wIn ON wIn.id = tr.warehouseInFk - JOIN vn.warehouse wOut ON wOut.id = tr.warehouseOutFk - WHERE wIn.id = vWarehouseFk - AND wOut.name = 'Holanda' - AND landed = vLanded; - END IF; - - END IF; - - RETURN vTravelFk; - -END$$ -DELIMITER ; From 6075ec6518d919ab7f31075b975d9431a94dac95 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 12 Sep 2024 09:06:03 +0200 Subject: [PATCH 35/46] feat: refs #7562 Requested changes --- .../11113-bronzeDendro/00-firstScript.sql | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/db/versions/11113-bronzeDendro/00-firstScript.sql b/db/versions/11113-bronzeDendro/00-firstScript.sql index 98ac69966..63db65378 100644 --- a/db/versions/11113-bronzeDendro/00-firstScript.sql +++ b/db/versions/11113-bronzeDendro/00-firstScript.sql @@ -1,26 +1,16 @@ -ALTER TABLE util.config - ADD COLUMN dateRegex varchar(255) NULL COMMENT 'Expresión regular para obtener las fechas.', - ADD deprecatedMarkRegex varchar(255) NULL COMMENT 'Expresión regular para obtener los objetos deprecados.', - ADD daysKeepDeprecatedObjects int(11) unsigned NULL COMMENT 'Número de días que se mantendrán los objetos deprecados.'; - -UPDATE IGNORE util.config - SET dateRegex = '[0-9]{4}-[0-9]{2}-[0-9]{2}', - deprecatedMarkRegex = '__$', - daysKeepDeprecatedObjects = 60; - ALTER TABLE IF EXISTS `vn`.`payrollWorker` - MODIFY COLUMN IF EXISTS `nss__` varchar(23) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', - MODIFY COLUMN IF EXISTS `codpuesto__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', - MODIFY COLUMN IF EXISTS `codcontrato__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', - MODIFY COLUMN IF EXISTS `FAntiguedad__` date NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', - MODIFY COLUMN IF EXISTS `grupotarifa__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', - MODIFY COLUMN IF EXISTS `codcategoria__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', - MODIFY COLUMN IF EXISTS `ContratoTemporal__` tinyint(1) NOT NULL DEFAULT 0 COMMENT '@deprecated 2024-03-15 refs #6738'; + MODIFY COLUMN IF EXISTS `nss__` varchar(23) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `codpuesto__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `codcontrato__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `FAntiguedad__` date NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `grupotarifa__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `codcategoria__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `ContratoTemporal__` tinyint(1) NOT NULL DEFAULT 0 COMMENT '@deprecated 2024-03-15'; ALTER TABLE IF EXISTS `vn`.`payrollWorkCenter` - MODIFY COLUMN IF EXISTS `Centro__` varchar(255) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', - MODIFY COLUMN IF EXISTS `nss_cotizacion__` varchar(15) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', - MODIFY COLUMN IF EXISTS `domicilio__` varchar(255) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', - MODIFY COLUMN IF EXISTS `poblacion__` varchar(45) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', - MODIFY COLUMN IF EXISTS `cp__` varchar(5) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738', - MODIFY COLUMN IF EXISTS `empresa_id__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738'; + MODIFY COLUMN IF EXISTS `Centro__` varchar(255) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `nss_cotizacion__` varchar(15) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `domicilio__` varchar(255) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `poblacion__` varchar(45) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `cp__` varchar(5) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `empresa_id__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15'; From b6cba2325aeefa88e5c50fd271c0beecfae43950 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 12 Sep 2024 11:02:41 +0200 Subject: [PATCH 36/46] feat: refs #7562 myt version increased to 1.6.10 --- package.json | 2 +- pnpm-lock.yaml | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 1d3b9d253..d50631eb7 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@babel/register": "^7.7.7", "@commitlint/cli": "^19.2.1", "@commitlint/config-conventional": "^19.1.0", - "@verdnatura/myt": "^1.6.9", + "@verdnatura/myt": "^1.6.10", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b4030d779..458ce647c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -143,8 +143,8 @@ devDependencies: specifier: ^19.1.0 version: 19.1.0 '@verdnatura/myt': - specifier: ^1.6.9 - version: 1.6.9 + specifier: ^1.6.10 + version: 1.6.10 angular-mocks: specifier: ^1.7.9 version: 1.8.3 @@ -2846,8 +2846,8 @@ packages: dev: false optional: true - /@verdnatura/myt@1.6.9: - resolution: {integrity: sha512-29IauYra9igfdPWwV4+pVV/tBXvIg0fkVHEpSz8Zz3G3lRtzm286FN2Kv6hZkxmD/F1n52O37jN9WLiLHDTW1Q==} + /@verdnatura/myt@1.6.10: + resolution: {integrity: sha512-fih/TFll5Sn/SxxafUmYh6CW0Qwpck8PpQ63/CKm4ya8rz8gYPq0THM2B5N8yEJ3PiolMg0wrWWas9j+taAh6w==} hasBin: true dependencies: '@sqltools/formatter': 1.2.5 @@ -3306,6 +3306,7 @@ packages: /are-we-there-yet@1.1.7: resolution: {integrity: sha512-nxwy40TuMiUGqMyRHgCSWZ9FM4VAoRP4xUYSTv5ImRog+h9yISPbVH7H8fASCIzYn9wlEv4zvFL7uKDMCFQm3g==} + deprecated: This package is no longer supported. dependencies: delegates: 1.0.0 readable-stream: 2.3.8 @@ -6593,6 +6594,7 @@ packages: /gauge@2.7.4: resolution: {integrity: sha512-14x4kjc6lkD3ltw589k0NrPD6cCNTD6CWoVUNpB85+DrtONoZn+Rug6xZU5RvSC4+TZPxA5AnBibQYAvZn41Hg==} + deprecated: This package is no longer supported. dependencies: aproba: 1.2.0 console-control-strings: 1.1.0 @@ -10814,6 +10816,7 @@ packages: /npmlog@4.1.2: resolution: {integrity: sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==} + deprecated: This package is no longer supported. dependencies: are-we-there-yet: 1.1.7 console-control-strings: 1.1.0 @@ -11055,6 +11058,7 @@ packages: /osenv@0.1.5: resolution: {integrity: sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==} + deprecated: This package is no longer supported. dependencies: os-homedir: 1.0.2 os-tmpdir: 1.0.2 From 6b6eea78dadcc1d94d4ba3725ee5ba243d4ca599 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 12 Sep 2024 13:21:01 +0200 Subject: [PATCH 37/46] feat: refs #7562 myt version increased to 1.6.11 --- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index d50631eb7..2ae7c3764 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@babel/register": "^7.7.7", "@commitlint/cli": "^19.2.1", "@commitlint/config-conventional": "^19.1.0", - "@verdnatura/myt": "^1.6.10", + "@verdnatura/myt": "^1.6.11", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 458ce647c..e2480cf4a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -143,8 +143,8 @@ devDependencies: specifier: ^19.1.0 version: 19.1.0 '@verdnatura/myt': - specifier: ^1.6.10 - version: 1.6.10 + specifier: ^1.6.11 + version: 1.6.11 angular-mocks: specifier: ^1.7.9 version: 1.8.3 @@ -2846,8 +2846,8 @@ packages: dev: false optional: true - /@verdnatura/myt@1.6.10: - resolution: {integrity: sha512-fih/TFll5Sn/SxxafUmYh6CW0Qwpck8PpQ63/CKm4ya8rz8gYPq0THM2B5N8yEJ3PiolMg0wrWWas9j+taAh6w==} + /@verdnatura/myt@1.6.11: + resolution: {integrity: sha512-uqdbSJSznBBzAoRkvBt600nUMEPL1PJ2v73eWMZbaoGUMiZiNAehYjs4gIrObP1cxC85JOx97XoLpG0BzPsaig==} hasBin: true dependencies: '@sqltools/formatter': 1.2.5 From 1abf6a14f95be25297e3b52e1610cf916cf81eb9 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 12 Sep 2024 13:26:09 +0200 Subject: [PATCH 38/46] fix: workerDms filter workerFk --- modules/worker/back/methods/worker-dms/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/worker/back/methods/worker-dms/filter.js b/modules/worker/back/methods/worker-dms/filter.js index 0d13276b1..597084e60 100644 --- a/modules/worker/back/methods/worker-dms/filter.js +++ b/modules/worker/back/methods/worker-dms/filter.js @@ -50,7 +50,7 @@ module.exports = Self => { or: [ {and: [ {isReadableByWorker: true}, - {worker: userId} + {'wd.workerFk': userId} ]}, { role: { From b1027f454b3f056892f4111441be6ab2807acafa Mon Sep 17 00:00:00 2001 From: Pako Date: Thu, 12 Sep 2024 14:13:17 +0200 Subject: [PATCH 39/46] locallyTested --- db/routines/vn/procedures/collection_new.sql | 3 ++- .../vn/procedures/productionControl.sql | 21 +++++++++++++++---- .../11229-salmonAsparagus/00-firstScript.sql | 3 +++ 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 db/versions/11229-salmonAsparagus/00-firstScript.sql diff --git a/db/routines/vn/procedures/collection_new.sql b/db/routines/vn/procedures/collection_new.sql index a5a9a61c7..53f5500a0 100644 --- a/db/routines/vn/procedures/collection_new.sql +++ b/db/routines/vn/procedures/collection_new.sql @@ -167,7 +167,8 @@ BEGIN OR LENGTH(pb.problem) OR pb.lines > vLinesLimit OR pb.m3 > vVolumeLimit - OR sub.maxSize > vSizeLimit; + OR sub.maxSize > vSizeLimit + OR pb.hasPlantTray; END IF; -- Hay que excluir aquellos que no tengan la misma hora de preparacion, si procede diff --git a/db/routines/vn/procedures/productionControl.sql b/db/routines/vn/procedures/productionControl.sql index e5323e84e..101a0f058 100644 --- a/db/routines/vn/procedures/productionControl.sql +++ b/db/routines/vn/procedures/productionControl.sql @@ -211,8 +211,6 @@ proc: BEGIN salesInParkingCount INT DEFAULT 0) ENGINE = MEMORY; - -- Insertamos todos los tickets que tienen productos parkineados - -- en sectores de previa, segun el sector CREATE OR REPLACE TEMPORARY TABLE tItemShelvingStock (PRIMARY KEY(itemFk, sectorFk)) ENGINE = MEMORY @@ -245,7 +243,6 @@ proc: BEGIN AND s.quantity > 0 GROUP BY pb.ticketFk; - -- Se calcula la cantidad de productos que estan ya preparados porque su saleGroup está aparcado UPDATE tmp.ticketWithPrevia twp JOIN ( SELECT pb.ticketFk, COUNT(DISTINCT s.id) salesInParkingCount @@ -259,12 +256,28 @@ proc: BEGIN ) sub ON twp.ticketFk = sub.ticketFk SET twp.salesInParkingCount = sub.salesInParkingCount; - -- Marcamos como pendientes aquellos que no coinciden las cantidades UPDATE tmp.productionBuffer pb JOIN tmp.ticketWithPrevia twp ON twp.ticketFk = pb.ticketFk SET pb.previousWithoutParking = TRUE WHERE twp.salesCount > twp.salesInParkingCount; + -- hasPlantTray + ALTER TABLE tmp.productionBuffer + ADD hasPlantTray BOOL DEFAULT FALSE; + + UPDATE tmp.productionBuffer pb + JOIN sale s ON s.ticketFk = pb.ticketFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + JOIN cache.last_buy lb ON lb.warehouse_id = vWarehouseFk AND lb.item_id = s.itemFk + JOIN buy b ON b.id = lb.buy_id + JOIN packaging p ON p.id = b.packagingFk + JOIN productionConfig pc + SET hasPlantTray = TRUE + WHERE ic.code = 'plant' + AND p.`depth` >= pc.minPlantTrayLength; + DROP TEMPORARY TABLE tmp.productionTicket, tmp.ticket, diff --git a/db/versions/11229-salmonAsparagus/00-firstScript.sql b/db/versions/11229-salmonAsparagus/00-firstScript.sql new file mode 100644 index 000000000..d590ed958 --- /dev/null +++ b/db/versions/11229-salmonAsparagus/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.productionConfig ADD minPlantTrayLength INT DEFAULT 53 NOT NULL +COMMENT 'minimum length for plant tray restriction. Avoid to make collection of the ticket with this kind of item'; From a0bfc2059530cee109a52d5a7e512af722b44ea8 Mon Sep 17 00:00:00 2001 From: Pako Date: Thu, 12 Sep 2024 14:34:19 +0200 Subject: [PATCH 40/46] revision --- db/routines/vn/procedures/productionControl.sql | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/db/routines/vn/procedures/productionControl.sql b/db/routines/vn/procedures/productionControl.sql index 101a0f058..842a306b4 100644 --- a/db/routines/vn/procedures/productionControl.sql +++ b/db/routines/vn/procedures/productionControl.sql @@ -266,14 +266,14 @@ proc: BEGIN ADD hasPlantTray BOOL DEFAULT FALSE; UPDATE tmp.productionBuffer pb - JOIN sale s ON s.ticketFk = pb.ticketFk - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN itemCategory ic ON ic.id = it.categoryFk - JOIN cache.last_buy lb ON lb.warehouse_id = vWarehouseFk AND lb.item_id = s.itemFk - JOIN buy b ON b.id = lb.buy_id - JOIN packaging p ON p.id = b.packagingFk - JOIN productionConfig pc + JOIN sale s ON s.ticketFk = pb.ticketFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + JOIN cache.last_buy lb ON lb.warehouse_id = vWarehouseFk AND lb.item_id = s.itemFk + JOIN buy b ON b.id = lb.buy_id + JOIN packaging p ON p.id = b.packagingFk + JOIN productionConfig pc SET hasPlantTray = TRUE WHERE ic.code = 'plant' AND p.`depth` >= pc.minPlantTrayLength; From 3d598a4ec4afcc57d5edd309f7479aa88e884f99 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 12 Sep 2024 14:57:19 +0200 Subject: [PATCH 41/46] fix: refs #7952 Version --- db/versions/11224-whiteMastic/00-firstScript.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/versions/11224-whiteMastic/00-firstScript.sql b/db/versions/11224-whiteMastic/00-firstScript.sql index 52267cd91..de74dfc55 100644 --- a/db/versions/11224-whiteMastic/00-firstScript.sql +++ b/db/versions/11224-whiteMastic/00-firstScript.sql @@ -1,2 +1,3 @@ +ALTER TABLE vn.creditInsurance DROP FOREIGN KEY CreditInsurance_Fk1; ALTER TABLE vn.creditInsurance CHANGE creditClassification creditClassification__ int(11) DEFAULT NULL COMMENT '@deprecated 2024-09-11'; From 93e71638581a6d9067f09b36057e551d7b621b87 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 12 Sep 2024 17:09:27 +0200 Subject: [PATCH 42/46] feat: refs #6868 refs# 6868 handleUser --- .../worker/back/methods/device/handle-user.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/worker/back/methods/device/handle-user.js b/modules/worker/back/methods/device/handle-user.js index 02b505e39..87aec378e 100644 --- a/modules/worker/back/methods/device/handle-user.js +++ b/modules/worker/back/methods/device/handle-user.js @@ -59,8 +59,12 @@ module.exports = Self => { } }, myOptions); - if (!isUserInOperator) - await models.Operator.create({'workerFk': user.id}); + if (!isUserInOperator) { + await models.Operator.create({ + 'workerFk': user.id, + 'isOnReservationMode': false + }); + } const whereCondition = deviceId ? {id: deviceId} : {android_id: androidId}; const serialNumber = @@ -103,12 +107,21 @@ module.exports = Self => { const getVersion = await models.MobileAppVersionControl.getVersion(ctx, nameApp); const combinedResult = { + ...getDataOperator.toObject(), + ...getDataUser.toObject(), + ...getVersion, + message: vMessage, + serialNumber, + }; + + const combinedResult2 = { ...getDataOperator.__data, ...getDataUser.__data, ...getVersion, message: vMessage, serialNumber, }; + console.log('conbinedResult2', combinedResult2); return combinedResult; }; }; From 2d4e6670099ef4f2ab8a38dd09923edf9e22385b Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 13 Sep 2024 07:02:30 +0200 Subject: [PATCH 43/46] feat: refs #6868 refs# 6868 handleUser --- modules/worker/back/methods/device/handle-user.js | 9 --------- .../worker/back/methods/device/specs/handle-user.spec.js | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/modules/worker/back/methods/device/handle-user.js b/modules/worker/back/methods/device/handle-user.js index 87aec378e..ac4ff2704 100644 --- a/modules/worker/back/methods/device/handle-user.js +++ b/modules/worker/back/methods/device/handle-user.js @@ -113,15 +113,6 @@ module.exports = Self => { message: vMessage, serialNumber, }; - - const combinedResult2 = { - ...getDataOperator.__data, - ...getDataUser.__data, - ...getVersion, - message: vMessage, - serialNumber, - }; - console.log('conbinedResult2', combinedResult2); return combinedResult; }; }; diff --git a/modules/worker/back/methods/device/specs/handle-user.spec.js b/modules/worker/back/methods/device/specs/handle-user.spec.js index c4cd37e33..37f76b765 100644 --- a/modules/worker/back/methods/device/specs/handle-user.spec.js +++ b/modules/worker/back/methods/device/specs/handle-user.spec.js @@ -3,7 +3,7 @@ const {models} = require('vn-loopback/server/server'); describe('Device handleUser()', () => { const ctx = {req: {accessToken: {userId: 9}}}; - it('should return data from user', async() => { + fit('should return data from user', async() => { const androidId = 'androidid11234567890'; const deviceId = 1; const nameApp = 'warehouse'; From e80fe1d0dc8a5189652a1c44ec0985e0c1afd2da Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 13 Sep 2024 07:10:47 +0200 Subject: [PATCH 44/46] feat: refs #6868 refs# 6868 handleUser --- modules/worker/back/methods/device/specs/handle-user.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/worker/back/methods/device/specs/handle-user.spec.js b/modules/worker/back/methods/device/specs/handle-user.spec.js index 37f76b765..c4cd37e33 100644 --- a/modules/worker/back/methods/device/specs/handle-user.spec.js +++ b/modules/worker/back/methods/device/specs/handle-user.spec.js @@ -3,7 +3,7 @@ const {models} = require('vn-loopback/server/server'); describe('Device handleUser()', () => { const ctx = {req: {accessToken: {userId: 9}}}; - fit('should return data from user', async() => { + it('should return data from user', async() => { const androidId = 'androidid11234567890'; const deviceId = 1; const nameApp = 'warehouse'; From ebbc1431522cd2675915f835c7e2ea74a4d357f1 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 13 Sep 2024 08:29:41 +0200 Subject: [PATCH 45/46] fix: sql wagonTypeTray --- db/versions/11088-bronzeAspidistra/00-firstScript.sql | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/db/versions/11088-bronzeAspidistra/00-firstScript.sql b/db/versions/11088-bronzeAspidistra/00-firstScript.sql index 11effc5d2..5de386df1 100644 --- a/db/versions/11088-bronzeAspidistra/00-firstScript.sql +++ b/db/versions/11088-bronzeAspidistra/00-firstScript.sql @@ -1,12 +1,10 @@ -DROP TABLE IF EXISTS vn.wagonTypeTray; - CREATE OR REPLACE TABLE vn.wagonTypeTray ( id INT UNSIGNED auto_increment NULL, wagonTypeFk int(11) unsigned NULL, height INT UNSIGNED NULL, wagonTypeColorFk int(11) unsigned NULL, CONSTRAINT wagonTypeTray_pk PRIMARY KEY (id), - CONSTRAINT wagonTypeTray_wagonType_FK FOREIGN KEY (wagonTypeFk) REFERENCES vn.wagonType(id), + CONSTRAINT wagonTypeTray_wagonType_FK FOREIGN KEY (wagonTypeFk) REFERENCES vn.wagonType(id) ON DELETE CASCADE ON UPDATE RESTRICT, CONSTRAINT wagonTypeTray_wagonTypeColor_FK FOREIGN KEY (wagonTypeColorFk) REFERENCES vn.wagonTypeColor(id) ) ENGINE=InnoDB @@ -17,5 +15,3 @@ ALTER TABLE vn.wagonConfig ADD IF NOT EXISTS defaultHeight INT UNSIGNED DEFAULT ALTER TABLE vn.wagonConfig ADD IF NOT EXISTS defaultTrayColorFk int(11) unsigned NULL COMMENT 'Default color for a base tray'; ALTER TABLE vn.wagonConfig ADD CONSTRAINT wagonConfig_wagonTypeColor_FK FOREIGN KEY (defaultTrayColorFk) REFERENCES vn.wagonTypeColor(id); -ALTER TABLE vn.wagonTypeTray DROP FOREIGN KEY wagonTypeTray_wagonType_FK; -ALTER TABLE vn.wagonTypeTray ADD CONSTRAINT wagonTypeTray_wagonType_FK FOREIGN KEY (wagonTypeFk) REFERENCES vn.wagonType(id) ON DELETE CASCADE ON UPDATE RESTRICT; From bbb3889154253962b6e59f102190812fb748df08 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 13 Sep 2024 08:54:03 +0200 Subject: [PATCH 46/46] fix: sql wagonTypeTray --- db/versions/11088-bronzeAspidistra/00-firstScript.sql | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/db/versions/11088-bronzeAspidistra/00-firstScript.sql b/db/versions/11088-bronzeAspidistra/00-firstScript.sql index 5de386df1..751bbf7e3 100644 --- a/db/versions/11088-bronzeAspidistra/00-firstScript.sql +++ b/db/versions/11088-bronzeAspidistra/00-firstScript.sql @@ -1,7 +1,9 @@ +ALTER TABLE vn.collectionWagonTicket DROP FOREIGN KEY IF EXISTS collectionWagonTicket_tray; +ALTER TABLE vn.wagonConfig DROP FOREIGN KEY IF EXISTS wagonConfig_wagonTypeColor_FK; CREATE OR REPLACE TABLE vn.wagonTypeTray ( - id INT UNSIGNED auto_increment NULL, - wagonTypeFk int(11) unsigned NULL, - height INT UNSIGNED NULL, + id INT(11) UNSIGNED, + wagonTypeFk INT(11) unsigned NULL, + height INT(11) UNSIGNED NULL, wagonTypeColorFk int(11) unsigned NULL, CONSTRAINT wagonTypeTray_pk PRIMARY KEY (id), CONSTRAINT wagonTypeTray_wagonType_FK FOREIGN KEY (wagonTypeFk) REFERENCES vn.wagonType(id) ON DELETE CASCADE ON UPDATE RESTRICT, @@ -14,4 +16,4 @@ COLLATE=utf8mb3_unicode_ci; ALTER TABLE vn.wagonConfig ADD IF NOT EXISTS defaultHeight INT UNSIGNED DEFAULT 0 NULL COMMENT 'Default height in cm for a base tray'; ALTER TABLE vn.wagonConfig ADD IF NOT EXISTS defaultTrayColorFk int(11) unsigned NULL COMMENT 'Default color for a base tray'; ALTER TABLE vn.wagonConfig ADD CONSTRAINT wagonConfig_wagonTypeColor_FK FOREIGN KEY (defaultTrayColorFk) REFERENCES vn.wagonTypeColor(id); - +ALTER TABLE vn.collectionWagonTicket ADD CONSTRAINT collectionWagonTicket_tray FOREIGN KEY (trayFk) REFERENCES vn.wagonTypeTray(id);