diff --git a/express-api/src/services/notifications/notificationServices.ts b/express-api/src/services/notifications/notificationServices.ts index 6ad6429b5a..747a830874 100644 --- a/express-api/src/services/notifications/notificationServices.ts +++ b/express-api/src/services/notifications/notificationServices.ts @@ -48,7 +48,6 @@ export enum NotificationAudience { export enum AgencyResponseType { Unsubscribe = 0, Subscribe = 1, - Watch = 2, } export interface ProjectNotificationFilter { projectId: number; @@ -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( @@ -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) => @@ -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(); @@ -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; diff --git a/express-api/src/typeorm/Migrations/1745434734346-RemoveWatchResponseType.ts b/express-api/src/typeorm/Migrations/1745434734346-RemoveWatchResponseType.ts new file mode 100644 index 0000000000..c466ae30c8 --- /dev/null +++ b/express-api/src/typeorm/Migrations/1745434734346-RemoveWatchResponseType.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class RemoveWatchResponseType1745434734346 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + // 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 { + // There is no going back from this. + // The enum value is removed from the database and the code. + } +} diff --git a/react-app/src/constants/agencyResponseTypes.ts b/react-app/src/constants/agencyResponseTypes.ts index 43316caf38..ff7bdfb235 100644 --- a/react-app/src/constants/agencyResponseTypes.ts +++ b/react-app/src/constants/agencyResponseTypes.ts @@ -1,5 +1,4 @@ export enum AgencyResponseType { Unsubscribe = 0, Subscribe = 1, - Watch = 2, }