Skip to content

Commit

Permalink
Move refresh of EstablishmentLastActivityView into shared util
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanc19 committed Sep 19, 2024
1 parent 1850eb7 commit 67a4a9b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ const moment = require('moment');

const models = require('../../index');

const refreshInactiveWorkplaces = async () => {
return models.sequelize.query('REFRESH MATERIALIZED VIEW cqc."EstablishmentLastActivity"');
};

const getInactiveWorkplaces = async () => {
const lastMonth = moment().subtract(1, 'months');

Expand Down Expand Up @@ -66,5 +62,4 @@ const getInactiveWorkplaces = async () => {

module.exports = {
getInactiveWorkplaces,
refreshInactiveWorkplaces,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ const moment = require('moment');

const models = require('../../index');

const refreshInactiveWorkplacesForDeletion = async () => {
return models.sequelize.query('REFRESH MATERIALIZED VIEW cqc."EstablishmentLastActivity"');
};

const getInactiveWorkplacesForDeletion = async () => {
const lastMonth = moment().subtract(1, 'months').endOf('month');
const twentyFourLastMonths = lastMonth.clone().subtract(24, 'months').format('YYYY-MM-DD');
Expand Down Expand Up @@ -59,5 +55,4 @@ const getInactiveWorkplacesForDeletion = async () => {

module.exports = {
getInactiveWorkplacesForDeletion,
refreshInactiveWorkplacesForDeletion,
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const nextEmail = require('./nextEmail');
const {
getInactiveWorkplaces,
refreshInactiveWorkplaces,
} = require('../../../models/email-campaigns/inactive-workplaces/getInactiveWorkplaces');
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 @@ -30,7 +28,7 @@ const transformInactiveWorkplaces = (inactiveWorkplace) => {
};

const findInactiveWorkplaces = async () => {
await refreshInactiveWorkplaces();
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,7 @@
const {
getInactiveWorkplacesForDeletion,
refreshInactiveWorkplacesForDeletion,
} = 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 +34,7 @@ const formattedAddress = (inactiveWorkplace) => {
};

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

Expand Down
5 changes: 5 additions & 0 deletions backend/server/utils/db/inactiveWorkplacesUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const models = require('../../models');

module.exports.refreshEstablishmentLastActivityView = async () => {
return models.sequelize.query('REFRESH MATERIALIZED VIEW cqc."EstablishmentLastActivity"');
};

0 comments on commit 67a4a9b

Please sign in to comment.