feat(admin): implement delete functionality for Falukant regions and update UI components

This commit is contained in:
Torsten Schulz (local)
2026-08-14 09:54:09 +02:00
parent 3f80cc40ff
commit e6f6fc984a
7 changed files with 522 additions and 68 deletions

View File

@@ -0,0 +1,63 @@
'use strict';
/**
* Older generated SRS data contained the number word "Baynte" as the
* currency phrase "20 Peso". Baynte itself means twenty, so the expected
* answer must be the number without a currency unit.
*/
module.exports = {
async up(queryInterface) {
await queryInterface.sequelize.query(`
WITH affected AS (
SELECT
id,
user_id,
course_id,
lesson_id,
direction,
CASE
WHEN LOWER(TRIM(learning)) = 'baynte' THEN 'baynte'
ELSE '20'
END AS corrected_learning,
CASE
WHEN LOWER(TRIM(reference)) = 'baynte' THEN 'baynte'
ELSE '20'
END AS corrected_reference
FROM community.vocab_srs_item
WHERE (LOWER(TRIM(learning)) = 'baynte' AND LOWER(TRIM(reference)) IN ('20 peso', '20 pesos'))
OR (LOWER(TRIM(reference)) = 'baynte' AND LOWER(TRIM(learning)) IN ('20 peso', '20 pesos'))
),
keyed AS (
SELECT
affected.*,
ENCODE(DIGEST(CONCAT_WS(
'|',
course_id::text,
COALESCE(lesson_id::text, 'course'),
UPPER(direction),
corrected_learning,
corrected_reference
), 'sha1'), 'hex') AS corrected_item_key
FROM affected
)
UPDATE community.vocab_srs_item item
SET learning = keyed.corrected_learning,
reference = keyed.corrected_reference,
item_key = keyed.corrected_item_key,
updated_at = NOW()
FROM keyed
WHERE item.id = keyed.id
AND NOT EXISTS (
SELECT 1
FROM community.vocab_srs_item duplicate
WHERE duplicate.user_id = keyed.user_id
AND duplicate.item_key = keyed.corrected_item_key
AND duplicate.id <> keyed.id
);
`);
},
async down() {
// The old answer was semantically incorrect and must not be restored.
},
};