refactor: refs #6824 Throw for no delete itemShelving with itemShelvingSale #3057

Merged
guillermo merged 9 commits from 6824-itemShelvingSaleNoDelete into dev 2024-10-07 05:50:49 +00:00
4 changed files with 16 additions and 1 deletions

View File

@ -23,6 +23,13 @@ BEGIN
DELETE FROM messageInbox WHERE sendDate < v2Months; DELETE FROM messageInbox WHERE sendDate < v2Months;
DELETE FROM messageInbox WHERE sendDate < v2Months; DELETE FROM messageInbox WHERE sendDate < v2Months;
DELETE FROM workerTimeControl WHERE timed < v4Years; DELETE FROM workerTimeControl WHERE timed < v4Years;
DELETE FROM itemShelvingSale
WHERE itemShelvingFk IN (
SELECT id
FROM itemShelving
WHERE created < util.VN_CURDATE()
AND visible = 0
);
DELETE FROM itemShelving WHERE created < util.VN_CURDATE() AND visible = 0; DELETE FROM itemShelving WHERE created < util.VN_CURDATE() AND visible = 0;
DELETE FROM ticketDown WHERE created < util.yesterday(); DELETE FROM ticketDown WHERE created < util.yesterday();
DELETE IGNORE FROM expedition WHERE created < v26Months; DELETE IGNORE FROM expedition WHERE created < v26Months;

View File

@ -0,0 +1,3 @@
ALTER TABLE vn.itemShelving DROP FOREIGN KEY itemShelving_fk2;
ALTER TABLE vn.itemShelving ADD CONSTRAINT itemShelving_fk2
FOREIGN KEY (shelvingFk) REFERENCES vn.shelving(code) ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@ -34,6 +34,11 @@ module.exports = Self => {
try { try {
const promises = []; const promises = [];
for (let itemShelvingId of itemShelvingIds) { for (let itemShelvingId of itemShelvingIds) {
const itemShelvingSaleToDelete = models.ItemShelvingSale.destroyAll({
Review

açò quina part del redmine es? perque si el itemShelving te sales, no es vol que se puguen borrar.

açò quina part del redmine es? perque si el itemShelving te sales, no es vol que se puguen borrar.
Review

Aixo ho faig en els tests intenta eliminar un itemShelving que conte itemShelvingSale, per lo tant, primer tinc que carregarme els itemShelvingSale i despres els itemShelvings, si no els tests fallen.

Aixo ho faig en els tests intenta eliminar un itemShelving que conte itemShelvingSale, per lo tant, primer tinc que carregarme els itemShelvingSale i despres els itemShelvings, si no els tests fallen.
itemShelvingFk: itemShelvingId
}, myOptions);
promises.push(itemShelvingSaleToDelete);
const itemShelvingToDelete = models.ItemShelving.destroyById(itemShelvingId, myOptions); const itemShelvingToDelete = models.ItemShelving.destroyById(itemShelvingId, myOptions);
promises.push(itemShelvingToDelete); promises.push(itemShelvingToDelete);
} }

View File

@ -10,7 +10,7 @@ describe('ItemShelving deleteItemShelvings()', () => {
const itemShelvingIds = [1, 2]; const itemShelvingIds = [1, 2];
const result = await models.ItemShelving.deleteItemShelvings(itemShelvingIds, options); const result = await models.ItemShelving.deleteItemShelvings(itemShelvingIds, options);
expect(result.length).toEqual(2); expect(result.length).toEqual(4);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {