Skip to content

Commit

Permalink
BRS-502-3: Exporter refactor - avoid pulling fiscalYearEnd objs. (#82)
Browse files Browse the repository at this point in the history
* BRS-502-3 exporter trying to pull fiscalYearEnd objects

* linting so I can sleep
  • Loading branch information
cameronpettit authored Oct 6, 2022
1 parent 247302c commit 9c2599d
Showing 2 changed files with 54 additions and 7 deletions.
39 changes: 37 additions & 2 deletions lambda/dynamoUtil.js
Original file line number Diff line number Diff line change
@@ -24,6 +24,16 @@ const PASS_TYPE_EXPIRY_HOURS = {
DAY: 0,
};

const RECORD_ACTIVITY_LIST = [
'Frontcountry Camping',
'Frontcountry Cabins',
'Backcountry Camping',
'Backcountry Cabins',
'Group Camping',
'Day Use',
'Boating'
];

const dynamodb = new AWS.DynamoDB(options);

exports.dynamodb = new AWS.DynamoDB();
@@ -33,7 +43,7 @@ async function getOne(pk, sk) {
logger.debug(`getItem: { pk: ${pk}, sk: ${sk} }`);
const params = {
TableName: TABLE_NAME,
Key: AWS.DynamoDB.Converter.marshall({pk, sk})
Key: AWS.DynamoDB.Converter.marshall({ pk, sk })
};
let item = await dynamodb.getItem(params).promise();
if (item?.Item) {
@@ -137,6 +147,30 @@ async function getSubAreas(orcs) {
return await runQuery(subAreaQuery);
}

// returns all records within a subarea.
// pass the full subarea object.
// pass filter = false to look for every possible activity
async function getRecords(subArea, filter = true) {
let records = [];
let filteredActivityList = RECORD_ACTIVITY_LIST;
if (filter && subArea.activites) {
filteredActivityList = AWS.DynamoDB.Converter.unmarshall(subArea.activites);
}
for (let activity of filteredActivityList) {
const recordQuery = {
TableName: TABLE_NAME,
KeyConditionExpression: `pk = :pk`,
ExpressionAttributeValues: {
':pk': { S: `${subArea.sk}::${activity}` },
},
}
// will return at most 1 record.
const record = await runQuery(recordQuery);
records = records.concat(record);
}
return records;
}

module.exports = {
ACTIVE_STATUS,
RESERVED_STATUS,
@@ -154,5 +188,6 @@ module.exports = {
runScan,
getOne,
getParks,
getSubAreas
getSubAreas,
getRecords
};
22 changes: 17 additions & 5 deletions lambda/export/invokable/index.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ const AWS = require("aws-sdk");
const s3 = new AWS.S3();
const fs = require("fs");
const writeXlsxFile = require("write-excel-file/node");
const { runScan, runQuery, TABLE_NAME } = require("../../dynamoUtil");
const { runScan, runQuery, TABLE_NAME, getParks, getSubAreas, getRecords } = require("../../dynamoUtil");
const {
EXPORT_NOTE_KEYS,
EXPORT_MONTHS,
@@ -124,10 +124,22 @@ exports.handler = async (event, context) => {
};

async function getAllRecords(queryObj) {
queryObj.ExpressionAttributeValues = {};
queryObj.ExpressionAttributeValues[":prefixDate"] = { S: "20" };
queryObj.FilterExpression = "begins_with(sk, :prefixDate)";
return await runScan(queryObj);
let records = [];
let subareas = [];
try {
const parks = await getParks();
for (const park of parks) {
const parkSubAreas = await getSubAreas(park.sk);
subareas = subareas.concat(parkSubAreas);
}
for (const subarea of subareas) {
const subAreaRecords = await getRecords(subarea, true);
records = records.concat(subAreaRecords);
}
return records;
} catch (err) {
logger.error(err);
}
}

async function groupBySubAreaAndDate(

0 comments on commit 9c2599d

Please sign in to comment.