feat: enhance Admin and report services with CRUD operations and intervention links

This commit is contained in:
gabdevele
2026-06-15 11:47:44 +02:00 Unverified
parent d684477ac3
commit 170fadbfe0
13 changed files with 1258 additions and 164 deletions
@@ -0,0 +1,37 @@
CREATE TABLE IF NOT EXISTS report_category_team_categories (
report_category_id BIGINT UNSIGNED NOT NULL,
team_category_id BIGINT UNSIGNED NOT NULL,
PRIMARY KEY (report_category_id, team_category_id),
CONSTRAINT report_category_team_categories_report_fk
FOREIGN KEY (report_category_id) REFERENCES report_categories(id),
CONSTRAINT report_category_team_categories_team_fk
FOREIGN KEY (team_category_id) REFERENCES team_categories(id)
);
CREATE TABLE IF NOT EXISTS intervention_access_links (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
report_id BIGINT UNSIGNED NOT NULL,
assignment_id BIGINT UNSIGNED NOT NULL,
token_hash VARCHAR(255) NOT NULL,
created_by_user_id BIGINT UNSIGNED NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
expires_at DATETIME NOT NULL,
revoked_at DATETIME NULL,
last_accessed_at DATETIME NULL,
UNIQUE KEY intervention_access_links_token_hash_unique (token_hash),
KEY intervention_access_links_report_assignment_idx (report_id, assignment_id),
CONSTRAINT intervention_access_links_report_fk
FOREIGN KEY (report_id) REFERENCES reports(id),
CONSTRAINT intervention_access_links_assignment_fk
FOREIGN KEY (assignment_id) REFERENCES assignments(id),
CONSTRAINT intervention_access_links_user_fk
FOREIGN KEY (created_by_user_id) REFERENCES users(id)
);
INSERT IGNORE INTO report_category_team_categories (report_category_id, team_category_id)
SELECT rc.id, tc.id
FROM report_categories rc
JOIN team_categories tc ON
(rc.name = 'Buche stradali' AND tc.name = 'Manutenzione strade') OR
(rc.name = 'Illuminazione guasta' AND tc.name = 'Illuminazione pubblica') OR
(rc.name = 'Rifiuti abbandonati' AND tc.name = 'Igiene urbana');