Skip to content

Commit

Permalink
NOBUG: Fixing undefined reference in sendTemplateSQS (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieltruong authored Jun 11, 2024
1 parent 816c6dc commit c499a63
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion __tests__/global/settings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const REGION = process.env.AWS_REGION || 'local-env';
const ENDPOINT = 'http://localhost:8000';
const ENDPOINT = process.env.DB_ENDPOINT_OVERRIDE || 'http://localhost:8000';
const TABLE_NAME = process.env.TABLE_NAME || 'parksreso-tests';
const TIMEZONE = 'America/Vancouver';

Expand Down
6 changes: 3 additions & 3 deletions lambda/passUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ async function sendTemplateSQS(facilityType, personalisation, passObject) {

logger.info(
`Pass successfully created. Registration number: ${JSON.stringify(
passObject?.Item['registrationNumber']
)}, Orcs: ${passObject.Item.pk}`
passObject?.registrationNumber
)}, Orcs: ${passObject?.pk}`
);
return passObject;
};

async function sendExpirationSQS(){
logger.info("SQSQUE: ", process.env.SQSEXPIRY_QUEUE)
logger.info("SQSQUE: ", process.env.SQSEXPIRY_QUEUE);
try {
const params = {
MessageBody: `SQS Message at ${(new Date()).toISOString()}`,
Expand Down
74 changes: 37 additions & 37 deletions lambda/writePass/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async function handleCommitPass(newObject, isAdmin) {
try {
// Check if the user has a valid token, ensuring it has not expired
logger.info('Checking if the user has a valid token, ensuring it has not expired.');
decodedToken = verifyHoldToken(token, SECRET);
decodedToken = verifyHoldToken(token, SECRET);
logger.info('Decoded Token');

facilityName = decodedToken.facilityName;
Expand Down Expand Up @@ -157,23 +157,23 @@ async function handleCommitPass(newObject, isAdmin) {
const currentPSTDateTime = DateTime.now().setZone(TIMEZONE);
logger.info('Checking pass status based on current time');
const passStatus = checkPassStatusBasedOnCurrentTime(currentPSTDateTime,
bookingPSTDateTime,
type);
bookingPSTDateTime,
type);
// Does the pass already exist in the database?
logger.info('Checking if the pass already exists in the database');
await checkPassExists(decodedToken.facilityName,
email,
decodedToken.type,
bookingPSTShortDate);
email,
decodedToken.type,
bookingPSTShortDate);

// Update the pass in the database
logger.info('Updating the pass in the database');
pass = await convertPassToReserved(decodedToken,
passStatus,
firstName,
lastName,
email,
phoneNumber);
passStatus,
firstName,
lastName,
email,
phoneNumber);
logger.debug(JSON.stringify(pass));

// delete the audit property before returning back to FE.
Expand All @@ -190,18 +190,18 @@ async function handleCommitPass(newObject, isAdmin) {

logger.info('generateCancellationLink');
const encodedCancellationLink = generateCancellationLink(pass.registrationNumber,
email,
parkOrcs,
bookingPSTShortDate,
type);
email,
parkOrcs,
bookingPSTShortDate,
type);

const formattedBookingDate = bookingPSTDateTime.toLocaleString(dateOptions);

const parkData = await getPark(decodedToken.parkOrcs);
logger.debug('parkData', parkData)
logger.debug('parkData', parkData);
const facilityData = await getFacility(decodedToken.parkOrcs, facilityName, false);
logger.debug('facilityData', facilityData)
logger.info('personaliazation')
logger.debug('facilityData', facilityData);
logger.info('personaliazation');
let personalisation = {
firstName: firstName,
lastName: lastName,
Expand All @@ -228,8 +228,8 @@ async function handleCommitPass(newObject, isAdmin) {
)}`
);
logger.error(err.response?.data || err);
return sendResponse(200, pass);
}
return sendResponse(200, pass);
// TODO: Remove JWT from hold pass area in database.
}

Expand Down Expand Up @@ -406,8 +406,8 @@ async function handleHoldPass(newObject, isAdmin) {
// Return the jwt'd pass object for the front end with a 7 minute expiry time.
passObject.Item['parkOrcs'] = { S: parkOrcs };
const holdPassJwt = jwt.sign(AWS.DynamoDB.Converter.unmarshall(passObject.Item),
SECRET,
{ algorithm: ALGORITHM, expiresIn: HOLD_PASS_TIMEOUT});
SECRET,
{ algorithm: ALGORITHM, expiresIn: HOLD_PASS_TIMEOUT });

let expirationTime = getExpiryTime(holdPassJwt);
// Store the jwt, as well as the registration number, and the expiry time in DynamoDB
Expand Down Expand Up @@ -564,20 +564,20 @@ function checkFacilityData(facilityData, numberOfGuests) {
* @returns {Object} The pass object.
*/
function createPassObject(parkData,
registrationNumber,
firstName,
lastName,
facilityName,
email,
bookingPSTDateTime,
bookingPSTShortDate,
type,
numberOfGuests,
status,
phoneNumber,
facilityData,
currentPSTDateTime
) {
registrationNumber,
firstName,
lastName,
facilityName,
email,
bookingPSTDateTime,
bookingPSTShortDate,
type,
numberOfGuests,
status,
phoneNumber,
facilityData,
currentPSTDateTime
) {
const passObject = {
TableName: TABLE_NAME,
ConditionExpression: 'attribute_not_exists(sk)'
Expand All @@ -586,7 +586,7 @@ function createPassObject(parkData,
passObject.Item['pk'] = { S: 'pass::' + parkData.sk };
passObject.Item['sk'] = { S: registrationNumber };
passObject.Item['parkName'] = { S: parkData.name };

if (firstName != null) {
passObject.Item['firstName'] = { S: firstName };
passObject.Item['searchFirstName'] = { S: firstName.toLowerCase() };
Expand Down Expand Up @@ -669,7 +669,7 @@ function checkForHardCodeAdjustment(newObject) {
* @returns {Object} - The transaction object.
*/
function generateTrasactionObject(parkData, facilityName, reservationsObjectPK, bookingPSTShortDate, type, numberOfGuests, passObject = undefined) {

let TransactItems = [
{
ConditionCheck: {
Expand Down

0 comments on commit c499a63

Please sign in to comment.