Skip to content

Commit

Permalink
Move inactive workplaces for deletion into same resolver to reduce re…
Browse files Browse the repository at this point in the history
…freshing of view
  • Loading branch information
duncanc19 committed Sep 19, 2024
1 parent 67a4a9b commit 77a12fd
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 41 deletions.
3 changes: 2 additions & 1 deletion backend/server/reports/inactive-workplaces/index.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 });
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -28,8 +27,6 @@ const transformInactiveWorkplaces = (inactiveWorkplace) => {
};

const findInactiveWorkplaces = async () => {
await refreshEstablishmentLastActivityView();

return (await getInactiveWorkplaces()).filter(nextEmail.shouldReceive).map(transformInactiveWorkplaces);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,7 +33,6 @@ const formattedAddress = (inactiveWorkplace) => {
};

const findInactiveWorkplacesForDeletion = async () => {
await refreshEstablishmentLastActivityView();
return (await getInactiveWorkplacesForDeletion()).map(transformInactiveWorkplacesForDeletion);
};

Expand Down
42 changes: 10 additions & 32 deletions frontend/src/app/features/admin/admin.routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -234,7 +213,6 @@ const routes: Routes = [
inactiveWorkplaces: InactiveWorkplacesResolver,
emailCampaignHistory: EmailCampaignHistoryResolver,
emailTemplates: EmailTemplateResolver,
inactiveWorkplaceForDeletion: InactiveWorkplacesForDeletionResolver,
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}),
Expand Down

0 comments on commit 77a12fd

Please sign in to comment.