feat: Add targeted notices to Condopay

Implements the ability to send notices to specific families within a condominium, rather than broadcasting to all. This includes:
- Updating the `Notice` type with `targetFamilyIds`.
- Adding a `target_families` JSON column to the `notices` table in the database, with a migration for existing installations.
- Modifying the API to handle the new `targetFamilyIds` field during notice creation and retrieval.
- Updating the UI to allow users to select specific families for notices.
This commit is contained in:
2025-12-09 14:04:49 +01:00
parent bd6fce6f51
commit ca38e891c9
6 changed files with 209 additions and 62 deletions

View File

@@ -269,11 +269,29 @@ const initDb = async () => {
link VARCHAR(255),
date ${TIMESTAMP_TYPE} DEFAULT CURRENT_TIMESTAMP,
active BOOLEAN DEFAULT TRUE,
target_families JSON ${DB_CLIENT === 'postgres' ? 'NULL' : 'NULL'},
created_at ${TIMESTAMP_TYPE} DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (condo_id) REFERENCES condos(id) ON DELETE CASCADE
)
`);
// Migration for notices: Add target_families
try {
let hasTargets = false;
if (DB_CLIENT === 'postgres') {
const [cols] = await connection.query("SELECT column_name FROM information_schema.columns WHERE table_name='notices'");
hasTargets = cols.some(c => c.column_name === 'target_families');
} else {
const [cols] = await connection.query("SHOW COLUMNS FROM notices");
hasTargets = cols.some(c => c.Field === 'target_families');
}
if (!hasTargets) {
console.log('Migrating: Adding target_families to notices...');
await connection.query("ALTER TABLE notices ADD COLUMN target_families JSON");
}
} catch(e) { console.warn("Notices migration warning:", e.message); }
// 7. Notice Reads
await connection.query(`
CREATE TABLE IF NOT EXISTS notice_reads (