Skip to content

Commit

Permalink
oy2-29084 - state withdrawal emails to include all active state users…
Browse files Browse the repository at this point in the history
… from territory
  • Loading branch information
bflynn-cms authored Jul 10, 2024
1 parent 04fcae0 commit 056227e
Showing 1 changed file with 26 additions and 31 deletions.
57 changes: 26 additions & 31 deletions services/app-api/email/stateWithdrawalReceipt.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
import dynamoDb from "../libs/dynamodb-lib";
import { USER_ROLE, USER_STATUS, Workflow } from "cmscommonlib";
import { USER_STATUS, Workflow } from "cmscommonlib";

export const getAllActiveStateUserEmailAddresses = async (territory) => {
const stateSubmittingUserRoles = [
USER_ROLE.STATE_SUBMITTER,
USER_ROLE.STATE_SYSTEM_ADMIN,
];
const stateSubmittingUsers = [];

await Promise.all(
stateSubmittingUserRoles.map(async (role) => {
const qParams = {
TableName: process.env.oneMacTableName,
IndexName: "GSI2",
KeyConditionExpression: "GSI2pk = :pk and GSI2sk = :sk",
ExpressionAttributeValues: {
":pk": `${role}#${territory}`,
":sk": USER_STATUS.ACTIVE,
},
ProjectionExpression: "email, fullName",
};
try {
const results = await dynamoDb.query(qParams);
stateSubmittingUsers.push(
results.Items.map(({ fullName, email }) => `${fullName} <${email}>`)
);
} catch (e) {
console.log("query error: ", e.message);
}
})
);
const returnUsers = stateSubmittingUsers.flat();
const qParams = {
TableName: process.env.oneMacTableName,
IndexName: "GSI1",
KeyConditionExpression: "GSI1pk = :pk",
FilterExpression: "#status = :status and territory = :territory",
ExpressionAttributeNames: {
"#status": "status",
},
ExpressionAttributeValues: {
":pk": "USER",
":territory": territory,
":status": USER_STATUS.ACTIVE,
},
ProjectionExpression: "email, fullName",
};

return returnUsers;
try {
const results = await dynamoDb.query(qParams);
const returnUsers = results.Items.map(
({ fullName, email }) => `${fullName} <${email}>`
);
return returnUsers;
} catch (e) {
console.log("query error: ", e.message);
return [];
}
};

/**
Expand Down

0 comments on commit 056227e

Please sign in to comment.