@@ -1408,7 +1408,7 @@ fun Database.Read.getMessageAccountsForRecipients(
1408
1408
recipients : List <MessageRecipient >
1409
1409
): Map <MessageRecipientType , List <Id <* >>> {
1410
1410
val recipientMap =
1411
- MessageRecipientType .values() .associateWith { emptyList<Id <* >>() }.toMutableMap()
1411
+ MessageRecipientType .entries .associateWith { emptyList<Id <* >>() }.toMutableMap()
1412
1412
recipients
1413
1413
.groupBy { it.type }
1414
1414
.forEach { (type, recipients) -> recipientMap[type] = recipients.map { it.id } }
@@ -1451,11 +1451,13 @@ WITH sender AS (
1451
1451
JOIN daycare d ON pl.unit_id = d.id
1452
1452
LEFT JOIN person p ON p.id = pl.child_id
1453
1453
LEFT JOIN service_need sn ON sn.placement_id = pl.placement_id AND daterange(sn.start_date, sn.end_date, '[]') @> ${bind(date)}
1454
+ JOIN sender ON TRUE
1454
1455
WHERE (d.care_area_id = ANY(${bind(currentRecipients[MessageRecipientType .AREA ])} )
1455
1456
OR pl.unit_id = ANY(${bind(currentRecipients[MessageRecipientType .UNIT ])} )
1456
1457
OR pl.group_id = ANY(${bind(currentRecipients[MessageRecipientType .GROUP ])} )
1457
1458
OR pl.child_id = ANY(${bind(currentRecipients[MessageRecipientType .CHILD ])} ))
1458
1459
AND ${predicate(filterPredicates)}
1460
+ AND (sender.type = 'MUNICIPAL'::message_account_type OR pl.group_id IS NOT NULL)
1459
1461
AND (
1460
1462
EXISTS (
1461
1463
SELECT 1
@@ -1486,12 +1488,14 @@ WITH sender AS (
1486
1488
LEFT JOIN daycare_group_placement dgp ON pl.id = dgp.daycare_placement_id
1487
1489
LEFT JOIN person p ON p.id = pl.child_id
1488
1490
LEFT JOIN service_need sn ON false
1491
+ JOIN sender ON TRUE
1489
1492
WHERE (pl.start_date > ${bind(date)} OR dgp.start_date > ${bind(date)} )
1490
1493
AND (d.care_area_id = ANY(${bind(starterRecipients[MessageRecipientType .AREA ])} )
1491
1494
OR pl.unit_id = ANY(${bind(starterRecipients[MessageRecipientType .UNIT ])} )
1492
1495
OR dgp.daycare_group_id = ANY(${bind(starterRecipients[MessageRecipientType .GROUP ])} )
1493
1496
OR pl.child_id = ANY(${bind(starterRecipients[MessageRecipientType .CHILD ])} ))
1494
1497
AND ${predicate(filterPredicates)}
1498
+ AND (sender.type = 'MUNICIPAL'::message_account_type OR dgp.daycare_group_id IS NOT NULL)
1495
1499
AND (
1496
1500
EXISTS (
1497
1501
SELECT 1
0 commit comments