Skip to content

PIMS-2307 Remove Watch Agency Response Type #2946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions express-api/src/services/notifications/notificationServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export enum NotificationAudience {
export enum AgencyResponseType {
Unsubscribe = 0,
Subscribe = 1,
Watch = 2,
}
export interface ProjectNotificationFilter {
projectId: number;
Expand Down Expand Up @@ -265,13 +264,11 @@ const generateProjectNotifications = async (
)
.andWhere('a.is_disabled = false')
.andWhere('a.send_email = true')
.andWhere(
'(par.agency_id IS NULL OR (par.response != :unsubscribe AND par.response != :watch))',
{
unsubscribe: AgencyResponseType.Unsubscribe,
watch: AgencyResponseType.Watch,
},
)
.andWhere('a.email IS NOT NULL')
.andWhere(`LENGTH(a.email) > 0`)
.andWhere('(par.agency_id IS NOT NULL AND par.response = :subscribe)', {
subscribe: AgencyResponseType.Subscribe,
})
.getMany();
agencies.forEach((agc) =>
returnNotifications.push(
Expand Down Expand Up @@ -305,13 +302,9 @@ const generateProjectNotifications = async (
})
.andWhere('a.email IS NOT NULL')
.andWhere(`LENGTH(a.email) > 0`)
.andWhere(
'(par.agency_id IS NULL OR (par.response != :unsubscribe AND par.response != :watch))',
{
unsubscribe: AgencyResponseType.Unsubscribe,
watch: AgencyResponseType.Watch,
},
)
.andWhere('(par.agency_id IS NOT NULL AND par.response = :subscribe)', {
subscribe: AgencyResponseType.Subscribe,
})
.getMany();

agencies.forEach((agc) =>
Expand Down Expand Up @@ -345,8 +338,8 @@ const generateProjectNotifications = async (
})
.andWhere('a.email IS NOT NULL')
.andWhere(`LENGTH(a.email) > 0`)
.andWhere('(par.agency_id IS NOT NULL AND par.response = :watch)', {
watch: AgencyResponseType.Watch,
.andWhere('(par.agency_id IS NOT NULL AND par.response = :subscribe)', {
subscribe: AgencyResponseType.Subscribe,
})
.getMany();

Expand Down Expand Up @@ -651,7 +644,6 @@ const generateProjectWatchNotifications = async (
for (const response of responses) {
switch (response.Response) {
case AgencyResponseType.Unsubscribe:
case AgencyResponseType.Watch:
//The simple case. Calling this will cancel all pending notifications for this project/agency pair.
await cancelProjectNotifications(response.ProjectId, response.AgencyId);
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class RemoveWatchResponseType1745434734346 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
// Move all Watch responses to Subscribe
// This is a one-way migration. The Watch response type is removed from the database and the code.
await queryRunner.query(`
UPDATE project_agency_response
SET response = 1
WHERE response = 2;
`);
}

public async down(): Promise<void> {
// There is no going back from this.
// The enum value is removed from the database and the code.
}
}
1 change: 0 additions & 1 deletion react-app/src/constants/agencyResponseTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export enum AgencyResponseType {
Unsubscribe = 0,
Subscribe = 1,
Watch = 2,
}