diff --git a/backend/server/reports/inactive-workplaces/index.js b/backend/server/reports/inactive-workplaces/index.js index 3bce021387..332d5ac878 100644 --- a/backend/server/reports/inactive-workplaces/index.js +++ b/backend/server/reports/inactive-workplaces/index.js @@ -1,5 +1,5 @@ const excelUtils = require('../../utils/excelUtils'); - +const { refreshEstablishmentLastActivityView } = require('../../utils/db/inactiveWorkplacesUtils'); const setParentWorkplaces = require('../../services/email-campaigns/inactive-workplaces/setParentWorkplaces'); const { generateInactiveWorkplacesTab } = require('./workplaces'); @@ -8,6 +8,7 @@ const { generateSubsidaryWorkplaceTab } = require('./subsidiaries'); const { generateInactiveWorkplacesForDeletionTab } = require('./deleteInactiveWorkplace'); const generateInactiveWorkplacesReport = async (workbook) => { + await refreshEstablishmentLastActivityView(); const parentWorkplaces = await setParentWorkplaces.findParentWorkplaces(); await generateInactiveWorkplacesTab(workbook); diff --git a/backend/server/routes/admin/email-campaigns/inactive-workplaces/index.js b/backend/server/routes/admin/email-campaigns/inactive-workplaces/index.js index 5b95243a8d..cd2c6ae868 100644 --- a/backend/server/routes/admin/email-campaigns/inactive-workplaces/index.js +++ b/backend/server/routes/admin/email-campaigns/inactive-workplaces/index.js @@ -7,14 +7,18 @@ const setInactiveWorkplaces = require('../../../../services/email-campaigns/inac const setInactiveWorkplacesForDeletion = require('../../../../services/email-campaigns/inactive-workplaces/setInactiveWorkplacesForDeletion'); const setParentWorkplaces = require('../../../../services/email-campaigns/inactive-workplaces/setParentWorkplaces'); const sendEmail = require('../../../../services/email-campaigns/inactive-workplaces/sendEmail'); +const { refreshEstablishmentLastActivityView } = require('../../../../utils/db/inactiveWorkplacesUtils'); const getInactiveWorkplaces = async (_req, res) => { try { + await refreshEstablishmentLastActivityView(); const inactiveWorkplaces = await setInactiveWorkplaces.findInactiveWorkplaces(); const parentWorkplaces = await setParentWorkplaces.findParentWorkplaces(); + const inactiveWorkplacesForDeletion = await setInactiveWorkplacesForDeletion.findInactiveWorkplacesForDeletion(); return res.json({ inactiveWorkplaces: inactiveWorkplaces.length + parentWorkplaces.length, + numberOfInactiveWorkplacesForDeletion: inactiveWorkplacesForDeletion.length, }); } catch (err) { console.error(err); @@ -25,6 +29,7 @@ const getInactiveWorkplaces = async (_req, res) => { const getInactiveWorkplcesForDeletion = async (req, res) => { try { + await refreshEstablishmentLastActivityView(); const inactiveWorkplacesForDeletion = await setInactiveWorkplacesForDeletion.findInactiveWorkplacesForDeletion(); return res.json({ numberOfInactiveWorkplacesForDeletion: inactiveWorkplacesForDeletion.length }); @@ -36,6 +41,7 @@ const getInactiveWorkplcesForDeletion = async (req, res) => { const inactiveWorkplacesIdsForDeletions = async (req, res) => { try { + await refreshEstablishmentLastActivityView(); const inactiveWorkplacesForDeletion = await setInactiveWorkplacesForDeletion.findInactiveWorkplacesForDeletion(); const establishmentIds = inactiveWorkplacesForDeletion.map((id) => id.establishmentID); await models.establishment.archiveInactiveWorkplaces(establishmentIds); diff --git a/backend/server/services/email-campaigns/inactive-workplaces/setInactiveWorkplaces.js b/backend/server/services/email-campaigns/inactive-workplaces/setInactiveWorkplaces.js index c7200743f8..9e9206abdf 100644 --- a/backend/server/services/email-campaigns/inactive-workplaces/setInactiveWorkplaces.js +++ b/backend/server/services/email-campaigns/inactive-workplaces/setInactiveWorkplaces.js @@ -1,6 +1,5 @@ const nextEmail = require('./nextEmail'); const { getInactiveWorkplaces } = require('../../../models/email-campaigns/inactive-workplaces/getInactiveWorkplaces'); -const { refreshEstablishmentLastActivityView } = require('../../../utils/db/inactiveWorkplacesUtils'); const transformInactiveWorkplaces = (inactiveWorkplace) => { const id = inactiveWorkplace.EstablishmentID; @@ -28,8 +27,6 @@ const transformInactiveWorkplaces = (inactiveWorkplace) => { }; const findInactiveWorkplaces = async () => { - await refreshEstablishmentLastActivityView(); - return (await getInactiveWorkplaces()).filter(nextEmail.shouldReceive).map(transformInactiveWorkplaces); }; diff --git a/backend/server/services/email-campaigns/inactive-workplaces/setInactiveWorkplacesForDeletion.js b/backend/server/services/email-campaigns/inactive-workplaces/setInactiveWorkplacesForDeletion.js index cb590745e9..ae8278ead9 100644 --- a/backend/server/services/email-campaigns/inactive-workplaces/setInactiveWorkplacesForDeletion.js +++ b/backend/server/services/email-campaigns/inactive-workplaces/setInactiveWorkplacesForDeletion.js @@ -1,7 +1,6 @@ const { getInactiveWorkplacesForDeletion, } = require('../../../models/email-campaigns/inactive-workplaces/getInactiveWorkplacesForDeletion'); -const { refreshEstablishmentLastActivityView } = require('../../../utils/db/inactiveWorkplacesUtils'); const transformInactiveWorkplacesForDeletion = (inactiveWorkplace) => { const name = inactiveWorkplace.NameValue; @@ -34,7 +33,6 @@ const formattedAddress = (inactiveWorkplace) => { }; const findInactiveWorkplacesForDeletion = async () => { - await refreshEstablishmentLastActivityView(); return (await getInactiveWorkplacesForDeletion()).map(transformInactiveWorkplacesForDeletion); }; diff --git a/frontend/src/app/features/admin/admin.routing.module.ts b/frontend/src/app/features/admin/admin.routing.module.ts index c64e320e8a..1651b4e7c8 100644 --- a/frontend/src/app/features/admin/admin.routing.module.ts +++ b/frontend/src/app/features/admin/admin.routing.module.ts @@ -4,38 +4,25 @@ import { RoleGuard } from '@core/guards/role/role.guard'; import { Roles } from '@core/model/roles.enum'; import { GetAdminUserResolver } from '@core/resolvers/admin/admin-users/get-admin-user.resolver'; import { GetAdminUsersResolver } from '@core/resolvers/admin/admin-users/get-admin-users.resolver'; -import { - GetCQCStatusChangeResolver, -} from '@core/resolvers/admin/cqc-main-service-change/get-cqc-main-service-change-list.resolver'; -import { - GetIndividualCqcMainServiceChangeResolver, -} from '@core/resolvers/admin/cqc-main-service-change/get-individual-cqc-main-service-change.resolver'; +import { GetCQCStatusChangeResolver } from '@core/resolvers/admin/cqc-main-service-change/get-cqc-main-service-change-list.resolver'; +import { GetIndividualCqcMainServiceChangeResolver } from '@core/resolvers/admin/cqc-main-service-change/get-individual-cqc-main-service-change.resolver'; import { EmailCampaignHistoryResolver } from '@core/resolvers/admin/email-campaign-history.resolver'; import { EmailTemplateResolver } from '@core/resolvers/admin/email-template.resolver'; -import { InactiveWorkplacesForDeletionResolver } from '@core/resolvers/admin/inactive-workplaces-for-deletion.resolver'; import { InactiveWorkplacesResolver } from '@core/resolvers/admin/inactive-workplaces.resolver'; import { GetDatesResolver } from '@core/resolvers/admin/local-authorities-return/get-dates.resolver'; import { GetLaResolver } from '@core/resolvers/admin/local-authorities-return/get-la.resolver'; import { GetLasResolver } from '@core/resolvers/admin/local-authorities-return/get-las.resolver'; -import { - GetIndividualParentRequestResolver, -} from '@core/resolvers/admin/parent-requests-list/get-parent-individual-request.resolver'; +import { GetIndividualParentRequestResolver } from '@core/resolvers/admin/parent-requests-list/get-parent-individual-request.resolver'; import { ParentRequestsListResolver } from '@core/resolvers/admin/parent-requests-list/parent-requests-list.resolver'; import { GetRegistrationsResolver } from '@core/resolvers/admin/registration-requests/get-registrations.resolver'; -import { - GetRegistrationNotesResolver, -} from '@core/resolvers/admin/registration-requests/single-registration/get-registration-notes.resolver'; -import { - GetSingleRegistrationResolver, -} from '@core/resolvers/admin/registration-requests/single-registration/get-single-registration.resolver'; +import { GetRegistrationNotesResolver } from '@core/resolvers/admin/registration-requests/single-registration/get-registration-notes.resolver'; +import { GetSingleRegistrationResolver } from '@core/resolvers/admin/registration-requests/single-registration/get-single-registration.resolver'; import { AddAdminUserComponent } from './admin-users/add-admin-user/add-admin-user.component'; import { AdminAccountViewComponent } from './admin-users/admin-account-view/admin-account-view.component'; import { AdminUsersComponent } from './admin-users/admin-users.component'; import { EditAdminUserComponent } from './admin-users/edit-admin-user/edit-admin-user.component'; -import { - CqcIndividualMainServiceChangeComponent, -} from './cqc-main-service-change/cqc-individual-main-service-change/cqc-individual-main-service-change.component'; +import { CqcIndividualMainServiceChangeComponent } from './cqc-main-service-change/cqc-individual-main-service-change/cqc-individual-main-service-change.component'; import { CQCMainServiceChangeListComponent } from './cqc-main-service-change/cqc-main-service-change-list.component'; import { EmailsComponent } from './emails/emails.component'; import { InactiveEmailsComponent } from './emails/inactive-emails/inactive-emails.component'; @@ -45,21 +32,13 @@ import { LocalAuthoritiesReturnComponent } from './local-authorities-return/loca import { LocalAuthorityComponent } from './local-authorities-return/monitor/local-authority/local-authority.component'; import { MonitorComponent } from './local-authorities-return/monitor/monitor.component'; import { SetDatesComponent } from './local-authorities-return/set-dates/set-dates.component'; -import { - ParentRequestIndividualComponent, -} from './parent-requests/parent-request-individual/parent-request-individual.component'; +import { ParentRequestIndividualComponent } from './parent-requests/parent-request-individual/parent-request-individual.component'; import { ParentRequestsListComponent } from './parent-requests/parent-requests-list.component'; -import { - PendingRegistrationRequestsComponent, -} from './registration-requests/pending-registration-requests/pending-registration-requests.component'; +import { PendingRegistrationRequestsComponent } from './registration-requests/pending-registration-requests/pending-registration-requests.component'; import { RegistrationRequestComponent } from './registration-requests/registration-request/registration-request.component'; import { RegistrationRequestsComponent } from './registration-requests/registration-requests.component'; -import { - RejectedRegistrationRequestComponent, -} from './registration-requests/rejected-registration-request/rejected-registration-request.component'; -import { - RejectedRegistrationRequestsComponent, -} from './registration-requests/rejected-registration-requests/rejected-registration-requests.component'; +import { RejectedRegistrationRequestComponent } from './registration-requests/rejected-registration-request/rejected-registration-request.component'; +import { RejectedRegistrationRequestsComponent } from './registration-requests/rejected-registration-requests/rejected-registration-requests.component'; import { ReportComponent } from './report/admin-report.component'; import { SearchForGroupComponent } from './search/search-for-group/search-for-group.component'; import { SearchForUserComponent } from './search/search-for-user/search-for-user.component'; @@ -234,7 +213,6 @@ const routes: Routes = [ inactiveWorkplaces: InactiveWorkplacesResolver, emailCampaignHistory: EmailCampaignHistoryResolver, emailTemplates: EmailTemplateResolver, - inactiveWorkplaceForDeletion: InactiveWorkplacesForDeletionResolver, }, }, ], diff --git a/frontend/src/app/features/admin/emails/inactive-emails/inactive-emails.component.ts b/frontend/src/app/features/admin/emails/inactive-emails/inactive-emails.component.ts index 76bc683dc5..3c6f49e746 100644 --- a/frontend/src/app/features/admin/emails/inactive-emails/inactive-emails.component.ts +++ b/frontend/src/app/features/admin/emails/inactive-emails/inactive-emails.component.ts @@ -18,9 +18,9 @@ import { SendEmailsConfirmationDialogComponent } from '../dialogs/send-emails-co styleUrls: ['./inactive-emails.component.scss'], }) export class InactiveEmailsComponent { - public inactiveWorkplaces = this.route.snapshot.data.inactiveWorkplaces.inactiveWorkplaces; + public inactiveWorkplaces = this.route.snapshot.data.inactiveWorkplaces?.inactiveWorkplaces; public numberOfInactiveWorkplacesForDeletion = - this.route.snapshot.data.inactiveWorkplaceForDeletion.numberOfInactiveWorkplacesForDeletion; + this.route.snapshot.data.inactiveWorkplaces?.numberOfInactiveWorkplacesForDeletion; public templates = this.route.snapshot.data.emailTemplates.templates; public history = this.route.snapshot.data.emailCampaignHistory; private subscriptions: Subscription = new Subscription(); @@ -69,7 +69,7 @@ export class InactiveEmailsComponent { this.subscriptions.add( this.emailCampaignService .inactiveWorkplcesForDeletion() - .pipe(concatMap(() => this.emailCampaignService.getInactiveWorkplcesForDeletion())) + .pipe(concatMap(() => this.emailCampaignService.getInactiveWorkplaces())) .subscribe((res) => { this.numberOfInactiveWorkplacesForDeletion = res.numberOfInactiveWorkplacesForDeletion; }),