Skip to content

Commit

Permalink
wip - update to missing v3 files
Browse files Browse the repository at this point in the history
  • Loading branch information
davidclaveau committed Jul 29, 2024
1 parent 3251e59 commit 872b061
Show file tree
Hide file tree
Showing 27 changed files with 147 additions and 166 deletions.
18 changes: 11 additions & 7 deletions arSam/handlers/activity/POST/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
const { marshall, unmarshall } = require('@aws-sdk/util-dynamodb');
const { DateTime } = require('luxon');
const {
dynamodb,
dynamoClient,
PutItemCommand,
DeleteItemCommand,
UpdateItemCommand,
runQuery,
TABLE_NAME,
getOne,
FISCAL_YEAR_FINAL_MONTH,
TIMEZONE,
sendResponse,
logger,
calculateVariance
calculateVariance,
marshall,
unmarshall,
} = require('/opt/baseLayer');
const { EXPORT_VARIANCE_CONFIG } = require('/opt/constantsLayer');

Expand Down Expand Up @@ -132,7 +136,7 @@ async function deleteVariance(body) {

logger.info('Deleting variance record:', params);

await dynamodb.deleteItem(params);
await dynamoClient.send(new DeleteItemCommand(params));
}

async function checkVarianceTrigger(body) {
Expand Down Expand Up @@ -228,7 +232,7 @@ async function createVariance(body, fields) {
TableName: TABLE_NAME,
Item: newObject,
};
await dynamodb.putItem(putObj);
await dynamoClient.send(new PutItemCommand(putObj));
} catch (e) {
logger.error(e);
}
Expand Down Expand Up @@ -318,7 +322,7 @@ async function handleLockUnlock(record, lock, context) {
ReturnValues: 'ALL_NEW',
};
try {
const res = await dynamodb.updateItem(updateObj);
const res = await dynamoClient.send(new UpdateItemCommand(updateObj));
logger.info(`Updated record pk: ${record.pk}, sk: ${record.sk} `);
const s = lock ? 'locked' : 'unlocked';
return sendResponse(200, {
Expand Down Expand Up @@ -380,7 +384,7 @@ async function handleActivity(body, lock = false, context) {
Item: newObject,
};

await dynamodb.putItem(putObject);
await dynamoClient.send(new PutItemCommand(putObject));
logger.info('Activity Updated.');
return sendResponse(200, body, context);
} catch (err) {
Expand Down
2 changes: 0 additions & 2 deletions arSam/handlers/activity/__tests__/activity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ describe("Activity Test", () => {
const doc = await dynamoClient.send(command);
expect(doc?.Item).toBe(undefined);



// Change year and create a new record
const secondResponse = await activityPOST.handlePost(
{
Expand Down
24 changes: 13 additions & 11 deletions arSam/handlers/export-variance/GET/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
const { Lambda } = require("@aws-sdk/client-lambda");
const { getSignedUrl } = require("@aws-sdk/s3-request-presigner");
const { S3Client, GetObjectCommand } = require("@aws-sdk/client-s3");
const { marshall } = require('@aws-sdk/util-dynamodb');

const defaultRegion = process.env.AWS_REGION || "ca-central-1";
const s3Client = new S3Client({ region: defaultRegion });
const bucket = process.env.S3_BUCKET_DATA || "parks-ar-assets-tools";

const IS_OFFLINE =
Expand All @@ -17,9 +10,18 @@ if (IS_OFFLINE) {
options.endpoint = "http://localhost:3002";
}

const lambda = new Lambda(options);

const { runQuery, TABLE_NAME, dynamodb, sendResponse, logger } = require("/opt/baseLayer");
const { runQuery,
TABLE_NAME,
dynamoClient,
PutItemCommand,
marshall,
lambda,
s3Client,
GetObjectCommand,
getSignedUrl,
sendResponse,
logger
} = require("/opt/baseLayer");
const { createHash } = require('node:crypto');

const VARIANCE_EXPORT_FUNCTION_NAME =
Expand Down Expand Up @@ -151,7 +153,7 @@ exports.handler = async (event, context) => {
logger.debug('Creating new job:', varianceExportPutObj);
let newJob;
try {
newJob = await dynamodb.putItem(varianceExportPutObj);
newJob = await dynamoClient.send(new PutItemCommand(varianceExportPutObj));
// Check if there's already a report being generated.
// If there are is no instance of a job or the job is 100% complete, generate a report.
logger.debug('New job created:', newJob);
Expand Down
11 changes: 0 additions & 11 deletions arSam/handlers/export-variance/GET/package.json

This file was deleted.

17 changes: 11 additions & 6 deletions arSam/handlers/export-variance/invokable/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3');
const s3Client = new S3Client({});
const { marshall } = require('@aws-sdk/util-dynamodb');
const fs = require('fs');

const { VARIANCE_CSV_SCHEMA, VARIANCE_STATE_DICTIONARY } = require("/opt/constantsLayer");
const { getParks, TABLE_NAME, dynamodb, runQuery, logger } = require("/opt/baseLayer");
const { getParks,
TABLE_NAME,
dynamoClient,
PutItemCommand,
marshall,
s3Client,
PutObjectCommand,
runQuery,
logger
} = require("/opt/baseLayer");

const FILE_PATH = process.env.FILE_PATH || "/tmp/";
const FILE_NAME = process.env.FILE_NAME || "A&R_Variance_Report";
Expand Down Expand Up @@ -139,7 +144,7 @@ async function updateJobEntry(jobObj) {
TableName: TABLE_NAME,
Item: marshall(jobObj)
}
await dynamodb.putItem(putObj);
await dynamoClient.send(new PutItemCommand(putObj));
}

async function getVarianceRecords(fiscalYearEnd, roles) {
Expand Down
9 changes: 0 additions & 9 deletions arSam/handlers/export-variance/invokable/package.json

This file was deleted.

22 changes: 13 additions & 9 deletions arSam/handlers/export/GET/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
const { Lambda } = require("@aws-sdk/client-lambda");
const { getSignedUrl } = require("@aws-sdk/s3-request-presigner");
const { S3Client, GetObjectCommand } = require("@aws-sdk/client-s3");
const { marshall } = require('@aws-sdk/util-dynamodb');

const defaultRegion = process.env.AWS_REGION || "ca-central-1";
const s3Client = new S3Client({ region: defaultRegion });
const bucket = process.env.S3_BUCKET_DATA || "parks-ar-assets-tools";

const IS_OFFLINE =
Expand All @@ -16,9 +10,19 @@ if (IS_OFFLINE) {
// For local we use port 3002 because we're hitting an invokable
options.endpoint = "http://localhost:3002";
}
const lambda = new Lambda(options);

const { runQuery, dynamodb, TABLE_NAME, sendResponse, logger } = require("/opt/baseLayer");
const { runQuery,
dynamoClient,
PutItemCommand,
GetObjectCommand,
getSignedUrl,
s3Client,
marshall,
lambda,
TABLE_NAME,
sendResponse,
logger
} = require("/opt/baseLayer");
const { convertRolesToMD5 } = require("/opt/functionsLayer");

const EXPORT_FUNCTION_NAME =
Expand Down Expand Up @@ -134,7 +138,7 @@ exports.handler = async (event, context) => {
logger.debug(putObject);
let newJob;
try {
newJob = await dynamodb.putItem(putObject);
newJob = await dynamoClient.send(new PutItemCommand(putObject));
// Check if there's already a report being generated.
// If there are is no instance of a job or the job is 100% complete, generate a report.
logger.debug("Creating a new export job.", newJob);
Expand Down
11 changes: 0 additions & 11 deletions arSam/handlers/export/GET/package.json

This file was deleted.

4 changes: 2 additions & 2 deletions arSam/handlers/export/invokable/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3");
const s3Client = new S3Client({});
const fs = require("fs");
const writeXlsxFile = require("write-excel-file/node");
const {
Expand All @@ -8,6 +6,8 @@ const {
getSubAreas,
getRecords,
logger,
s3Client,
PutObjectCommand
} = require("/opt/baseLayer");
const {
EXPORT_NOTE_KEYS,
Expand Down
1 change: 0 additions & 1 deletion arSam/handlers/export/invokable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "1.0.0",
"author": "Digitalspace <contact@digitalspace.ca>",
"dependencies": {
"@aws-sdk/client-s3": "^3.568.0",
"write-excel-file": "^1.3.16"
}
}
9 changes: 5 additions & 4 deletions arSam/handlers/fiscalYearEnd/POST/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const { marshall } = require('@aws-sdk/util-dynamodb');
const {
TABLE_NAME,
dynamodb,
dynamoClient,
PutItemCommand,
TIMEZONE,
FISCAL_YEAR_FINAL_MONTH,
sendResponse,
logger
logger,
marshall
} = require("/opt/baseLayer");
const { DateTime } = require("luxon");

Expand Down Expand Up @@ -93,7 +94,7 @@ async function putFiscalYear(isLocked, params) {
TableName: TABLE_NAME,
Item: marshall(newObject),
};
await dynamodb.putItem(putObj);
await dynamoClient.send(new PutItemCommand(putObj));
logger.debug("Updated fiscalYearEnd Object:", newObject);
return newObject;
} catch (err) {
Expand Down
1 change: 0 additions & 1 deletion arSam/handlers/fiscalYearEnd/POST/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "1.0.0",
"author": "Digitalspace <contact@digitalspace.ca>",
"dependencies": {
"@aws-sdk/util-dynamodb": "^3.614.0",
"luxon": "^3.2.1"
}
}
2 changes: 1 addition & 1 deletion arSam/handlers/nameUpdate/__tests__/name-update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe("Name Update Tests", () => {
// Run the update
await nameUpdateHandler.handler({}, null);

// Fetch the updated cache and check that it has been udpated
// Fetch the updated cache and check that it has been updated
const cachedDocumentRes = await dynamoClient.send(new GetItemCommand(CACHED_DOCUMENT));
const cachedDocument = unmarshall(cachedDocumentRes.Item);
expect(cachedDocument.displayName).toBe('Strathcona Park');
Expand Down
22 changes: 16 additions & 6 deletions arSam/handlers/nameUpdate/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
const axios = require('axios');
const { marshall } = require('@aws-sdk/util-dynamodb');
const { runQuery, runScan, NAME_CACHE_TABLE_NAME, TABLE_NAME, ORCS_INDEX, dynamodb, logger } = require("/opt/baseLayer");
const { runQuery,
runScan,
NAME_CACHE_TABLE_NAME,
TABLE_NAME,
ORCS_INDEX,
dynamoClient,
PutItemCommand,
BatchWriteItemCommand,
UpdateItemCommand,
marshall,
logger
} = require("/opt/baseLayer");
const DATA_REGISTER_NAME_ENDPOINT = process.env.DATA_REGISTER_NAME_ENDPOINT || 'https://zloys5cfvf.execute-api.ca-central-1.amazonaws.com/api/parks/names?status=established';
const DATA_REGISTER_NAME_API_KEY = process.env.DATA_REGISTER_NAME_API_KEY;
const ESTABLISHED_STATE = 'established';
Expand Down Expand Up @@ -82,7 +92,7 @@ async function updateLocalCache(item) {
TableName: NAME_CACHE_TABLE_NAME,
Item: marshall(item, { removeUndefinedValues: true })
};
await dynamodb.putItem(putItem);
await dynamoClient.send(new PutItemCommand(putItem));
logger.info("Update complete")
}

Expand All @@ -104,7 +114,7 @@ async function batchWriteCache(records) {
if (batch.RequestItems[NAME_CACHE_TABLE_NAME].length === 25) {
batchCount++;
// Write the current batch and reset the batch
await dynamodb.batchWriteItem(batch);
await dynamoClient.send(new BatchWriteItemCommand(batch));
process.stdout.write(`.`);
batch.RequestItems[NAME_CACHE_TABLE_NAME] = [];
}
Expand All @@ -114,7 +124,7 @@ async function batchWriteCache(records) {
if (batch.RequestItems[NAME_CACHE_TABLE_NAME].length > 0) {
batchCount++;
logger.info(`writing final batch #${batchCount}`);
await dynamodb.batchWriteItem(batch);
await dynamoClient.send(new BatchWriteItemCommand(batch));
logger.info(`Complete.`);
}
}
Expand Down Expand Up @@ -161,7 +171,7 @@ async function updateRecords(recordsToUpdate, updateObj) {

try {
process.stdout.write(`.`);
await dynamodb.updateItem(params);
await dynamoClient.send(new UpdateItemCommand(params));
} catch (e) {
logger.info(e);
// TODO: Fall through, but record error somehow?
Expand Down
3 changes: 1 addition & 2 deletions arSam/handlers/nameUpdate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"version": "1.0.0",
"author": "Digitalspace <contact@digitalspace.ca>",
"dependencies": {
"axios": "^0.21.1",
"@aws-sdk/util-dynamodb": "^3.614.0"
"axios": "^0.21.1"
}
}

9 changes: 7 additions & 2 deletions arSam/handlers/park/POST/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
const { dynamodb, TABLE_NAME, logger, sendResponse } = require("/opt/baseLayer");
const { dynamoClient,
PutItemCommand,
TABLE_NAME,
logger,
sendResponse
} = require("/opt/baseLayer");

exports.handler = async (event, context) => {
logger.debug("Park POST:", event);
Expand Down Expand Up @@ -38,7 +43,7 @@ exports.handler = async (event, context) => {
};

logger.debug("Creating park:", postObj);
const res = await dynamodb.putItem(postObj);
const res = await dynamoClient.send(new PutItemCommand(postObj));
logger.info("Park Created");
logger.debug("Result:", res);
return sendResponse(200, res);
Expand Down
Loading

0 comments on commit 872b061

Please sign in to comment.