Skip to content

Commit

Permalink
BRS-148: add facility booking window fields (#33)
Browse files Browse the repository at this point in the history
Adds `bookingOpeningHour` and `bookingDaysAhead` to the facility
object on write. This data will allow setting of a per facility booking
window.
  • Loading branch information
cole authored Nov 25, 2021
1 parent 58958e4 commit 02a8f16
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions lambda/writeFacility/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,33 @@ exports.handler = async (event, context) => {
console.log(event.body);
let newObject = JSON.parse(event.body);

let { parkName, bookingTimes, name, status, type, visible, mode, stateReason, ...otherProps } = newObject;
let {
parkName,
bookingTimes,
name,
status,
type,
visible,
mode,
stateReason,
bookingOpeningHour,
bookingDaysAhead,
...otherProps
} = newObject;

const bookingOpeningHourAttrValue = {};
const bookingDaysAheadAttrValue = {};

if (bookingOpeningHour) {
bookingOpeningHourAttrValue.N = bookingOpeningHour.toString();
} else {
bookingOpeningHourAttrValue.NULL = true;
}
if (bookingDaysAhead) {
bookingDaysAheadAttrValue.N = bookingDaysAhead.toString();
} else {
bookingDaysAheadAttrValue.NULL = true;
}

if (mode !== 'editFacililty') {
// Add facility
Expand All @@ -30,6 +56,8 @@ exports.handler = async (event, context) => {
facilityObject.Item['visible'] = { BOOL: visible };
// Add reservations property to bookingtimes.
facilityObject.Item['reservations'] = { M: {} };
facilityObject.Item['bookingOpeningHour'] = bookingOpeningHourAttrValue;
facilityObject.Item['bookingDaysAhead'] = bookingDaysAheadAttrValue;

console.log('putting item:', facilityObject);
const res = await dynamodb.putItem(facilityObject).promise();
Expand All @@ -45,13 +73,15 @@ exports.handler = async (event, context) => {
ExpressionAttributeValues: {
':statusValue': { M: AWS.DynamoDB.Converter.marshall(status) },
':visibility': { BOOL: visible },
':bookingTimes': { M: AWS.DynamoDB.Converter.marshall(bookingTimes) }
':bookingTimes': { M: AWS.DynamoDB.Converter.marshall(bookingTimes) },
':bookingOpeningHour': bookingOpeningHourAttrValue,
':bookingDaysAhead': bookingDaysAheadAttrValue,
},
ExpressionAttributeNames: {
'#facilityStatus': 'status',
'#visibility': 'visible'
},
UpdateExpression: 'SET #facilityStatus =:statusValue, bookingTimes =:bookingTimes, #visibility =:visibility',
UpdateExpression: 'SET #facilityStatus =:statusValue, bookingTimes =:bookingTimes, #visibility =:visibility, bookingOpeningHour = :bookingOpeningHour, bookingDaysAhead = :bookingDaysAhead',
ReturnValues: 'ALL_NEW',
TableName: process.env.TABLE_NAME
};
Expand Down

0 comments on commit 02a8f16

Please sign in to comment.